Previews do not load in Xcode 13

While trying to generate previews in Xcode 13, I am presented with the error MessageSendFailure: Message send failure for send previewInstances message to agent. I've tried a few projects and it seems to affect all of them.

Body of the diagnostics window:

==================================

|  RemoteHumanReadableError
|  
|  LoadingError: failed to load library at path "/Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/ContentView.2.preview-thunk.dylib": Optional(dlopen(/Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/ContentView.2.preview-thunk.dylib, 2): no suitable image found.  Did find:
|  	/Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/ContentView.2.preview-thunk.dylib: code signature in (/Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/ContentView.2.preview-thunk.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?))

I've tried cleaning the build folder to remove any old files it might be trying to use but I've had no luck. The program itself compiles and runs just fine. Any ideas?

Answered by NinjaCheetah in 690138022

Ended up solving this myself but thought it would be a good idea to share my solution in case anyone stumbles upon this thread with the same question some day.

My solution was to first make sure all my accounts were signed in (in my case my Apple ID and my GitHub account, not sure if the GitHub account made any difference tho) since it seemed to be a signing issue. Then I cleaned the build folder (Product -> Clean Build Folder or Command + Shift + K), and deleted the Data folder at /Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/.

Next I went into the "Signing & Capabilities" settings screen in my project settings, disabled "Automatically manage signing", turned it back on, and allowed Xcode to reset all of the signing settings. After that I just reselected my team and previews started working again.

Accepted Answer

Ended up solving this myself but thought it would be a good idea to share my solution in case anyone stumbles upon this thread with the same question some day.

My solution was to first make sure all my accounts were signed in (in my case my Apple ID and my GitHub account, not sure if the GitHub account made any difference tho) since it seemed to be a signing issue. Then I cleaned the build folder (Product -> Clean Build Folder or Command + Shift + K), and deleted the Data folder at /Users/campbell/Library/Containers/com.NCX-Programming.SwiftUI-Test/Data/.

Next I went into the "Signing & Capabilities" settings screen in my project settings, disabled "Automatically manage signing", turned it back on, and allowed Xcode to reset all of the signing settings. After that I just reselected my team and previews started working again.

Previews do not load in Xcode 13
 
 
Q