exception - 单声道-System.TypeLoadException : Could not load types

标签 exception xamarin mono simple-injector typeloadexception

最近升级到 Xamarin Studio 6 和 Mono 4.4.0.182(在 OSX 10.10.5 上运行)后,我们发现我们的应用程序不再运行(Asp.NET MVC/Razor 网站)。然而,该解决方案确实可以正确编译。
我们尝试恢复到以前有效的版本 - Xamarin Studio 5.10.3 和 Mono 4.3.2,但我们的应用程序仍然无法正常运行。完全相同的应用程序在更新之前运行良好。
没有进行其他环境/代码更改,并且重新启动也不起作用。

更新后生成错误。

第一个错误(应用程序启动时):System.Reflection.ReflectionTypeLoadException
这是由 SimpleInjector Container.RegisterPackages() 触发的。这是在 Xamarin/Mono 更新之前运行的,并且没有应用/进行任何代码更改/包更新。

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'.

堆栈跟踪

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  

第二个错误(页面重新加载和任何后续页面请求之后):System.ArgumentException 已添加具有相同 key 的项目。
这引用了 App_Start/RouteConfig.cs 文件中的 System.Web.Mvc.RouteCollectionExtensions.MapRoute 调用(从 Global.asax.cs、Application_Start 依次调用),表明该文件至少被调用两次。同样,这在最近的 Xamarin/Mono 更新之前是有效的。

任何人都可以提供任何帮助和/或建议吗?

编辑
回滚到 Mono 4.2.4.4,错误消失了。看起来 4.3.2 中的某个更改引入了此错误。

最佳答案

我也遇到过类似的问题:

无法从程序集“System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”加载类型“System.Net.HttpListener”

我解决了将 Mono.Security 添加到可执行项目并重建它的问题。 希望这有帮助

关于exception - 单声道-System.TypeLoadException : Could not load types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37779772/

相关文章:

.net - .NET没有概念性(Fatal-)Error异常类型的设计原因?

c# - 为什么我的抽象基类会出现这个编译错误?

c# - Xamarin.IOS。代码分析——CA2123

c# - 如何在 Mono IDE 中使用 C# 设置命令行参数。

sql - 什么是时间戳/行版本(SQL Server)与 PostgreSQL 的等价物

Python:尝试/排除整个模块

python - 为什么尝试在Python 3.7的Visual Studio代码中使用except block无法工作?

android - WebViewCore 内部线程中 StatFs 中的 IllegalArgumentException

Xamarin 表单 : Programmatically added AbsoluteLayout not rendering on iOS

ios - 从MvvmCross 4迁移到5后,Xamarin iOS在启动时崩溃