7

Since updating a working MonoTouch 3.x app to MonoTouch 4.0, I have been getting the following error when attempting to start a Debug or Release build on the Simulator:

Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at MonoTouch.ObjCRuntime.Runtime.RegisterAssembly (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0 

The problem appears to be with System.Xml.Linq, however I have checked all projects and references, and this doesn't even appear to be a transitive reference from what I can tell. I just don't appear to be using this anywhere.

Exception Message is always "Could not load System.Xml.Linq.XNodeNavigator from System.Xml.Linq".

Anyone have any ideas?

poupou
  • 43,413
  • 6
  • 77
  • 174
Ben Phegan
  • 505
  • 3
  • 6
  • Were you able to solve this problem? I am having exactly the same situation although it seem, at least in my case, that it is no related to Linq. – Julio Garcia Apr 18 '11 at 17:58
  • Seems to have been resolved, cant say at this point exactly what caused it. Steps to get rid of it (and guesses) 1) I had a test project that referenced non-MonoTouch assemblies, and built alongside the other assemblies. I think this might have helped confuse MD. 2) Deleted all references from all projects, add back in one at a time (probably unecessary...might just have needed to do this on the non-MonoTouch one) 3) Excluded non-MonoTouch project from building 4) Reset Simulator contents 5) Clean and Rebuild It worked. At a guess, some non-MonoTouch assemblies were being bundled as well. – Ben Phegan Apr 18 '11 at 23:25

1 Answers1

4

The root cause is that the iOS simulator only update files, it never deletes them (even if you delete your app from the simulator).

This cause problems if you have some files (e.g. System.Xml.Linq) at one point and remove them later (directly or use the linker which can remove it). From there you'll have some old, stale files in your simulator app directory.

The next issue is that MonoTouch register all assemblies present in the directory. This means the stale one are registered too in the simulator. At this stage this can work (and you won't see an error) or this could fail (with the error you have above) because the stale assembly does not have everything it needs to be loaded properly.

The easiest workaround is to reset your iOS simulator, that will remove everything (all apps and all files).

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Per [this question](http://stackoverflow.com/questions/300793/iphone-simulator-springboard-failed-to-launch-application-with-error-7), I also had to *restart* the simulator (exit and re-run). – Kirk Woll Nov 02 '12 at 19:38
  • That specific issue was fixed a long time ago (long enough that I don't recall which version ;-). OTOH you can run into weird issues if you have more than one version of Xcode around (i.e. that will require you to exit and restart the simulator). – poupou Nov 02 '12 at 23:44
  • yeah, go figure. I tried just your solution (since I was getting the error in this question) and then immediately got the Springboard error mentioned in the other question. In any case, just commented on your answer in case it might help a future googler like me. :) – Kirk Woll Nov 03 '12 at 01:30