让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
来源:互联网 发布:数据统计怎么做 编辑:程序博客网 时间:2024/05/22 02:00
这两天一直在为“Unable to load one or more of the types in the assembly”而头疼,我相信凡是有需要大量使用Reflection来Load Assembly,并动态地调用ass.GetTypes()或ass.GetType(string)或CreateInstance()的朋友可能会和我一样遇到这个恼人的问题。而且这个问题是非常隐蔽的,一般如果GetType或CreateInstance执行时遇到这个问题,而选择出错不提示的话,程序只是简单的返回null。而且,至今未找到任何描述为何会这样原因的文档。
还是来看看出错的典型场景:
Assembly ass = Assembly.LoadFile(assPath);
t = ass.GetType(typeName, false);
就是这么明显的代码,却时常会发生这个“Unable to load one or more of the types in the assembly”错误,明明指定的Type在这个Assembly中,却报错并返回null。而且,有的程序集运行正常,有的则不行,甚至,有的有时正常有时报错,简直是对Bill没话说。
几经周折,发现解决办法:用LoadFrom代替LoadFile:
Assembly ass = Assembly.LoadFrom(assPath);
t = ass.GetType(typeName, false);
的确很简单,简单到我想笑,但是,在网上找了无数圈,无数的朋友却都没尝试这样做而烦恼不已。
比较MSDN中Assembly.LoadFile和Assembly.LoadFrom的描述:
Assembly.LoadFile:
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.
Loads the contents of an assembly file.
Assembly.LoadFrom:
Loads an assembly.
除此之外没有任何不同的说明!
无话说,只能感叹又一次被Bill叔叔耍了~~
还是来看看出错的典型场景:
Assembly ass = Assembly.LoadFile(assPath);
t = ass.GetType(typeName, false);
就是这么明显的代码,却时常会发生这个“Unable to load one or more of the types in the assembly”错误,明明指定的Type在这个Assembly中,却报错并返回null。而且,有的程序集运行正常,有的则不行,甚至,有的有时正常有时报错,简直是对Bill没话说。
几经周折,发现解决办法:用LoadFrom代替LoadFile:
Assembly ass = Assembly.LoadFrom(assPath);
t = ass.GetType(typeName, false);
的确很简单,简单到我想笑,但是,在网上找了无数圈,无数的朋友却都没尝试这样做而烦恼不已。
比较MSDN中Assembly.LoadFile和Assembly.LoadFrom的描述:
Assembly.LoadFile:
Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.
Loads the contents of an assembly file.
Assembly.LoadFrom:
Loads an assembly.
除此之外没有任何不同的说明!
无话说,只能感叹又一次被Bill叔叔耍了~~
- 让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
- Fix: 'Unable to load one or more of the requested types' Errors
- System.Data - System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the r
- magento:One or more of the Cache Types are invalidated
- Could not load file or assembly '***' or one of its does not match the assembly reference
- Maven之Unable to load the mojo 'resources' (or one of its required components)
- We are unable to complete the review of your app since one or more of your In App Purchases have not
- Could not load file or assembly 'App_Web_xxxx' or one of its dependencies. The system cannot find the file specified.
- Could not load file or assembly "xxx" or one of its dependencies. The system cannot find the file sp
- 让人哭笑不得的 The value of attribute "value" associated with an element type "prope
- 当用到反射的程序部署时出现System.Data - System.Reflection.ReflectionTypeLoadException: Unable to load one or more
- Plaase select at least one of the signature versions to use 问题的解决
- How to solve "one or more projects in the solution were not loaded correctly" problem?
- Unable to read the project file 'client.csproj'. Could not load file or assembly 'Microsoft.Build.En
- Parser Error Message: Could not load file or assembly 'NameSpace' or one of its dependencies. The system cannot find the file sp
- arcgis的One or more layers failed to draw: 问题
- the diary of how to backup one more files in linux
- 使用studio引用资源的问题One or more layouts are missing the layout_width or layout_height attributes. These a
- 重新诠释SOA
- 上海科技馆C++大会第一天见闻
- 关于本Blog内容的声明、今后的发展方向及Teddy的其他相关站点
- AJAX设计模式实践 之 可刷新Ajax应用范例+Framework
- AJAX设计模式 之 怎样构建一个可刷新的无刷新应用
- 让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
- 国庆庆祝一下
- AOP Practice with AspectWeaver0.6 - DebugPropertyValueModifying
- 从Design Pattern浅谈AOP
- 滑雪
- AOP编程实践之AspectWeaverSample1.0
- 高精度计时器---QueryPerformanceFrequency()与QueryPerformanceCounter()的使用
- Teddy's Aspect Weaver Version 0.6
- Teddy's Aspect Weaver Version 0.5