Mono - System.TypeLoadException: Failed to load types

After a recent upgrade to Xamarin Studio 6 and Mono 4.4.0.182 (running on OSX 10.10.5), we found that our application no longer works (Asp.NET MVC / Razor website). The solution really compiles correctly. We tried to revert to previous versions that worked - Xamarin Studio 5.10.3 and Mono 4.3.2, and our application is still not working correctly. Exactly the same application worked fine before the update.
No other environment / code changes were made, and reboots did not work either.

Errors that occur after the upgrade.

1st error (when starting the application): System.Reflection.ReflectionTypeLoadException
This is triggered by SimpleInjector Container.RegisterPackages (). This worked before the Xamarin / Mono update, and no package changes / updates were applied / done.

Could not load type 'System.Net.HttpListener' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Could not load type 'System.Net.HttpListenerPrefixCollection' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Could not load type 'System.Net.HttpWebRequest' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Could not load type 'System.Net.Security.SslStream' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Could not load type 'System.Net.WebSockets.ClientWebSocket' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 

Stacktrace

 at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool) at System.Reflection.Assembly.GetExportedTypes () [0x00000] in /private/tmp/source-mono-4.3.2/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/Assembly.cs:407 at SimpleInjector.PackageExtensions.GetExportedTypesFrom (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0 at SimpleInjector.PackageExtensions+<>c.<RegisterPackages>b__1_0 (System.Reflection.Assembly assembly) [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<SelectManyIterator>c__Iterator5`3[TSource,TCollection,TResult].MoveNext () [0x00059] in <filename unknown>:0 at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00078] in <filename unknown>:0 at System.Linq.Buffer`1[TElement]..ctor (IEnumerable`1 source) [0x00087] in <filename unknown>:0 at System.Linq.Enumerable.ToArray[TSource] (IEnumerable`1 source) [0x00011] in <filename unknown>:0 at SimpleInjector.PackageExtensions.RegisterPackages (SimpleInjector.Container container, IEnumerable`1 assemblies) [0x000f0] in <filename unknown>:0 at SimpleInjector.PackageExtensions.RegisterPackages (SimpleInjector.Container container) [0x0002f] in <filename unknown>:0 at MyApplication.Web.UI.MvcApplication.InitializeContainer (SimpleInjector.Container container) [0x00003] in /Users/*sanitized*/MyApplication.Web.UI/Global.asax.cs:57 

The second error (after reloading the page and any subsequent page requests): System.ArgumentException An element with the same key has already been added. This refers to a call to System.Web.Mvc.RouteCollectionExtensions.MapRoute in our file App_Start / RouteConfig.cs (called in turn from Global.asax.cs, Application_Start), indicating that this file is called at least twice. Again, this worked until the recent Xamarin / Mono update.

Can anyone provide any help and / or suggestions?

EDIT
Returned to Mono 4.2.4.4, and the error disappeared. It seems that at some point there was a change introduced in 4.3.2, which introduced this error.

+7
exception mono simple-injector typeloadexception xamarin
source share
1 answer

I had a similar problem:

Could not load type 'System.Net.HttpListener' from assembly 'System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089'

I decided to add Mono.Security to the executable project and rebuild it. Hope this helps

+3
source share

All Articles