Monday, August 17, 2015

MVVMCross Core solution throws error - Unhandled managed exception

Problem:

I just completed the Windows Phone UI project for an MVVMCross solution.  The core project is used by iPhone and Windows Phone UI.  Upon completion of testing for WP, I decided to run a few tests against iPhone which I had completed earlier.  I was immediately confronted with an error -

"An Unhandled exception occurred"

The Xamarin log shows the error occurring at load time.  The compiler built out the bits.  The attempt to run in debug did reveal some more interesting leads. 

[3641:134567] Unhandled managed exception: Could not load file or assembly 'Windows' or one of its dependencies.  The system cannot find the file specified.  (System.IO.FileNotFoundException)

I continued to play around with the changes I had made to the Core PCL.  Then I found the issue.

Solution:

In the course of building the Windows Phone project I used the LongListSelector. This Windows Phone control has several dependcies which are specific to Windows Phone.  The Core PCL included some code which depended on the library Microsoft.Phone.dll.  This reference is not compatible with the Monotouch framework.  My code worked fine when I compiled to Windows Phone but as soon as I tried to run the exe to Monotouch I raised the error. 

My solution was to surround the code with conditional compilation commands

#if USE_MVVMCROSS_WP8

....

#endif

Source:
http://typecastexception.com/post/2012/08/18/Visual-Studio-Use-Conditional-Compilation-to-Control-Runtime-Settings-for-Different-Deployment-Scenarios.aspx

No comments:

Post a Comment