After upgrading to xcode 16.2 I see the following crash when resolving dependencies via command line:
** INTERNAL ERROR: Unable to load workspace '....' **
Uncaught Exception: *** -[NSMutableArray insertObjects:atIndexes:]: count of array (15) differs from count of index set (14)
Stack:
0 __exceptionPreprocess (in CoreFoundation)
1 objc_exception_throw (in libobjc.A.dylib)
2 -[__NSCFString characterAtIndex:].cold.1 (in CoreFoundation)
3 -[NSMutableArray insertObjects:atIndexes:] (in CoreFoundation)
4 __50-[IDEGroup insertGroupSubitems:atIndexes:context:]_block_invoke (in IDEFoundation)
5 -[DVTModelObjectGraph performBlockCoalescingModelChanges:] (in DVTFoundation)
6 -[IDEGroup insertGroupSubitems:atIndexes:context:] (in IDEFoundation)
7 -[NSMutableArray(DVTFoundationClassAdditions) dvt_sortedInsertOfObjects:withComparator:] (in DVTFoundation)
8 specialized IDESPMWorkspaceDelegate.registerDependencyFileReferences(_:modelGraphSynchronizerToken:) (in IDESwiftPackageCore)
9 specialized IDESPMWorkspaceDelegate.dependencyPackagesDidUpdate(packages:graphHasErrors:revalidatedFilePathCaches:modelGraphSynchronizerToken:) (in IDESwiftPackageCore)
10 closure #1 in IDESPMWorkspaceDelegate.packageGraphDidFinishAction(_:duration:result:) (in IDESwiftPackageCore)
11 partial apply for closure #1 in IDESPMWorkspaceDelegate.disableWorkspaceContentSynchronization(during:) (in IDESwiftPackageCore)
12 closure #1 in DVTModelObjectGraph.performBlockCoalescingModelChanges<A>(_:) (in DVTFoundation)
13 thunk for @callee_guaranteed () -> (@owned [String : NSObject]) (in DVTFoundation)
14 thunk for @escaping @callee_guaranteed () -> () (in DVTFoundation)
15 __58-[DVTModelObjectGraph performBlockCoalescingModelChanges:]_block_invoke (in DVTFoundation)
16 -[DVTModelGraphTransactionScope performTransaction:] (in DVTFoundation)
17 -[DVTModelObjectGraph performBlockCoalescingModelChanges:] (in DVTFoundation)
18 DVTModelObjectGraph.performBlockCoalescingModelChanges<A>(_:) (in DVTFoundation)
19 IDESPMWorkspaceDelegate.disableWorkspaceContentSynchronization(during:) (in IDESwiftPackageCore)
20 IDESPMWorkspaceDelegate.packageGraphDidFinishAction(_:duration:result:) (in IDESwiftPackageCore)
21 partial apply for thunk for @escaping @isolated(any) @callee_guaranteed @async () -> () (in IDESwiftPackageCore)
22 SPMWorkspace.packageGraphActionFinished(_:) (in SwiftPM)
23 closure #2 in closure #3 in SPMWorkspace.processPackageGraphActionsInBackgroundIfNeeded(canProcessPackageGraphActions:) (in SwiftPM)
24 dispatch thunk of SPMWorkspaceOrchestrationDelegate.packageGraphDidFinishAction(_:duration:result:) (in SwiftPM)
25 specialized thunk for @escaping @isolated(any) @callee_guaranteed @async () -> (@out A) (in SwiftPM)
26 partial apply for specialized thunk for @escaping @isolated(any) @callee_guaranteed @async () -> (@out A) (in SwiftPM)
27 completeTaskWithClosure(swift::AsyncContext*, swift::SwiftError*) (in libswift_Concurrency.dylib)
sh: line 1: 24112 Abort trap: 6 env NSUnbufferedIO=YES xcodebuild -scheme ***-Package -destination 'platform=iOS Simulator,id=950768B8-85B4-4250-A7EC-5AE8758369EE' -derivedDataPath .DerivedData -resultBundlePath '/.../***-Package.xcresult' -enableCodeCoverage YES -skipPackagePluginValidation -skipMacroValidation -disablePackageRepositoryCache build test```
Are there any workaround for this?
Found out the cause of the crashes. We sync the Package.resolved file of the Xcode project with some local swift packages contained in the project by copying it to the root of the packages, next to Package.swift. This means that the Package.resolved would have more entries than it should for the smaller packages. This worked fine in Xcode 15, but it looks like Xcode 16 expects the dependency count to be exact.