Wednesday, December 10, 2014

Invalid IL code in system.xml.linq.xdocument:Parse (string): method body is empty

Working on getting a iPhone application off the ground.  We are using Xamarin/Monotouch and MVVMcross to build a cross platform solution.  The PCL does not support File.IO namespace so using some excellent posts about IoC.

Problem:

An issue cropped up in my attempts to get my example working.  I have the xml file being rendered in the iOS project of the solution.  The Interface is stored in the PCL and it compiles and runs.  But when I hit the line in the iOS project

doc = XDocument.Parse(DefaultData);

I got the runtime error:
Invalid IL code in system.xml.linq.xdocument:Parse (string): method body is empty

Solution:

The iOS project is using the Monotouch namespace which includes its own copies of the common
.Net dlls.  It appears that the namespaces for the non mono projects were included as references for the iOS project.  This meant that the source code would compile without errors.  The dll in question was System.XML.dll.  I dropped the reference to this dll and added in the correct mono dll and that removed the IL error.


Wrong System.XML.dll file

Program Files(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.XML.dll

vs.


Correct System.XML.dll

Program Files(x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v1.0\System.XML.dll

No comments:

Post a Comment