title: Mono - System.TypeLoadException: Could not load types
body: <p>After recently upgrading to Xamarin Studio 6 and Mono 4.4.0.182 (running on OSX 10.10.5) we found that our application no longer runs (Asp.NET MVC/Razor website). The solution does compile correctly however.<br>
  We've tried reverting back to the previous versions which did work - Xamarin Studio 5.10.3 and Mono 4.3.2, and our application still does not run correctly. The exact same application was working fine prior to the update.<br>
  No other environment/code changes have been made, and restarts have also not worked.</p>
  
  <p>Errors being generated after the update.</p>
  
  <p><strong>1st Error</strong> (on application start): <strong>System.Reflection.ReflectionTypeLoadException</strong><br>
  This is being triggered by SimpleInjector Container.RegisterPackages(). This was working prior to the Xamarin/Mono update, and no code changes/package updates have been applied/made.</p>
  
  <pre><code>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'.
  </code></pre>
  
  <p>Stacktrace</p>
  
  <pre><code>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 &lt;filename unknown&gt;:0
  at SimpleInjector.PackageExtensions+&lt;&gt;c.&lt;RegisterPackages&gt;b__1_0 (System.Reflection.Assembly assembly) [0x00000] in &lt;filename unknown&gt;:0
  at System.Linq.Enumerable+&lt;SelectManyIterator&gt;c__Iterator5`3[TSource,TCollection,TResult].MoveNext () [0x00059] in &lt;filename unknown&gt;:0
  at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00078] in &lt;filename unknown&gt;:0
  at System.Linq.Buffer`1[TElement]..ctor (IEnumerable`1 source) [0x00087] in &lt;filename unknown&gt;:0
  at System.Linq.Enumerable.ToArray[TSource] (IEnumerable`1 source) [0x00011] in &lt;filename unknown&gt;:0
  at SimpleInjector.PackageExtensions.RegisterPackages (SimpleInjector.Container container, IEnumerable`1 assemblies) [0x000f0] in &lt;filename unknown&gt;:0
  at SimpleInjector.PackageExtensions.RegisterPackages (SimpleInjector.Container container) [0x0002f] in &lt;filename unknown&gt;:0
  at MyApplication.Web.UI.MvcApplication.InitializeContainer (SimpleInjector.Container container) [0x00003] in /Users/*sanitized*/MyApplication.Web.UI/Global.asax.cs:57  
  </code></pre>
  
  <p><strong>2nd Error</strong> (After page reload and any subsequent page requests):  <strong>System.ArgumentException</strong> An item with the same key has already been added.<br>
  This is referencing a System.Web.Mvc.RouteCollectionExtensions.MapRoute call in our App_Start/RouteConfig.cs file (called in turn from Global.asax.cs, Application_Start), indicating that this file is being called at least twice. Again, this was working prior to the recent Xamarin/Mono update.</p>
  
  <p>Can anyone provide any assistance and/or suggestions?</p>
  
  <p>EDIT<br>
  Rolled back to Mono 4.2.4.4, and the error has gone away. Looks like there has been a change introduced into 4.3.2 at some point that has introduced this bug.</p>