My App crash at startup with a MissingMethodException, and I don’t know why

Xamarin is a wonderful platform. You can build native apps for multiple platforms on a shared C# codebase, using the same IDE, language and API.

Like all platforms, there are (sometimes) some problems and you have to loose your time to find a solution. Today I have tried to run on a Motorola WT6000 device a test app (I would like to test Beacons…). So I have connect the device to my Mac and pressed “Run”. The app have been deployed and CRASH! An exception.

Strange, very strange, because my App works (of course, having made it, I can not say otherwise). The “Exception Popup” in Xamarin Studio disappear immediately; I am only able to see something like MissingMethodException. Nothing else.

How can I understand which kind of exception has been thrown? Fortunately Xamarin Studio has an Application Output TAB where you can find all logs the app writes. Taking a look to these logs, I find

cant resolve internal call to "System.Environment::internalGetEnvironmentVariable(string)"
[mono] Your mono runtime and class libraries are out of sync.
[mono] The out of sync library is: mscorlib.dll
[mono] 
[mono] When you update one from svn you need to update, compile and install
[mono] the other too.
[mono] Do not report this as a bug unless you're sure you have updated correctly:
[mono] you probably have a broken mono install.
[mono] If you see other errors or faults after this message they are probably related
[mono] and you need to fix your mono install first.

Wow. And some rows later

[mono] Unhandled Exception:
[mono] System.MissingMethodException: Cannot find the requested method.

Ok. Mono seem to be out fo sync, maybe on the device. So what can I do to “clean” the situation and have a runnable App installed on my device?

  1. In Xamarin Studio: Clean Solution
  2. On the Device: Settings->App->Uninstall the App, Mono Shared Runtime, Xamarin.Android API-XX Support
  3. Restart Xamarin Studio
  4. Redeploy the App

Now it should works. I think these 4 steps can be used also for other Xamarin’s mysterious problems…

Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...