让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
2005-10-25 14:02
966 查看
这两天一直在为“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”问题的解决!
- WebPart部署时,“Unable to load one or more of the requested types.”错误的解决
- GetTypes Unable to load one or more of the requested types
- Fix: 'Unable to load one or more of the requested types' Errors
- Unable to load one or more of the requested types.
- 反射引发的错误“reflection Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.”
- We are unable to complete the review of your app since one or more of your In App Purchases have not
- System.Data - System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the r
- 【随】Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack 问题解决。
- Maven之Unable to load the mojo 'resources' (or one of its required components)
- fatal error: malformed or corrupted AST file: 'Unable to load module Darwin.pcm 问题解决
- Plaase select at least one of the signature versions to use 问题的解决
- It is not possible to run two different versions of ASP.NET in the same IIS process.问题的解决
- Could not load file or assembly "xxx" or one of its dependencies. The system cannot find the file sp
- 安装Fedora时遇到unable to find any devices of the type needed for this installation type问题的解决
- 解决Could not load file or assembly 'App_Web_xxxx' or one of its dependencies.
- Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. The parameter is incorrect.
- 解决svn:"One or more files are in a conflicted state."问题
- fatal error: malformed or corrupted AST file: 'Unable to load module Darwin.pcm 问题解决
- One or more Filters failed to start. Full details will be found in the appropriate container log fil