Search code examples
c#xamarin.iosvisual-studio-2022

An attempt was made to load an assembly with an incorrect format:


I've just finished up my Xamarin.iOS app and I'm preparing it for release. I'm using VS 2022 v 17.10.2, I've spent the last few weeks debugging and testing it to make sure all is functioning as it needs to. I switched the mode from "Debug" to "Release" and hit build. It fails with the error:

Error An attempt was made to load an assembly with an incorrect format: C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Xamarin.iOS.dll. OML_iOS C:\Users\Presc\source\repos\OML_iOS\OML_iOS\SGEN

I've found very little online that addesses this particular issue and nothing suggested has worked. If I change the app back to "Debug" it builds and deploys to my test device just fine. I have no idea how to fix this. Anyone have any ideas?


Solution

  • Well, fortunately this turned out to be a "minor" issue, just took me 3 days to figure it out. In the build section of my project's properties I had set "Generate serialization assembly" to "Auto". Turning it off, cleaning the project, and deleting the obj and bin folders cleared the error and allowed me to compile, archive, and distribute the app to the Apple Store. It's currently "Under Review". For those of you who are or have experienced the same issue, it's important to clean and delete the bin and obj folders, otherwise other strange errors may (and for me did) occur.