本文介绍了ProjectVI.Api.dll中出现“System.Reflection.ReflectionTypeLoadException”类型的异常,但未在用户代码中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在web.API部分收到此错误:
I am getting this error in my web.API part:
An exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in ProjectVI.Api.dll but was not handled in user code
Additional information: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
public SafeDirectoryCatalog(string directory)
{
var files = Directory.EnumerateFiles(directory, "*.dll", SearchOption.AllDirectories);
this.catalog = new AggregateCatalog();
foreach (var file in files)
{
try
{
var asmCat = new AssemblyCatalog(file);
////Force MEF to load the plugin and figure out if there are any exports
// good assemblies will not throw the RTLE exception and can be added to the catalog
if (asmCat.Parts.ToList().Count > 0)
{
this.catalog.Catalogs.Add(asmCat);
}
}
catch (Exception ex)
{
Log.Instance.Error(ex, "@file " + file.ToString());
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
if (loaderExceptions.Count() > 0)
{
foreach (Exception exc in loaderExceptions)
{
Log.Instance.Error(exc, "exception");
}
}
}
throw ex;
}
}
}
我得到了这个例外:
I am getting this exception:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
ProjectVI.Api.Install.SafeDirectoryCatalog..ctor(String directory) in C:\ProjectVI\Code\BA\ProjectVI.Api\Install\SafeDirectoryCatalog.cs:67
ProjectVI.Api.Install.MefConfig.Register() in C:\ProjectVI\Code\BA\ProjectVI.Api\Install\MefConfig.cs:28
ProjectVI.Api.WebApiApplication.Application_Start() in C:\ProjectVI\Code\BA\ProjectVI.Api\Global.asax.cs:30
[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9916673
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
推荐答案
catch (Exception ex)
{
Log.Instance.Error(ex, "@file " + file.ToString());
if (ex is System.Reflection.ReflectionTypeLoadException) // here exception!
{
// ... and so long
这意味着上面的代码已经错了:
That means that the code above is already wrong:
var asmCat = new AssemblyCatalog(file);
////Force MEF to load the plugin and figure out if there are any exports
// good assemblies will not throw the RTLE exception and can be added to the catalog
if (asmCat.Parts.ToList().Count > 0)
{
this.catalog.Catalogs.Add(asmCat);
}
你需要找到原始错误而不是试图解决以下错误!
尝试逐步调试上面的代码并找出错误...
You need to find the origin error and not try to cure the following errors!
Try to debug the code above step by step and find out what is wrong there ...
这篇关于ProjectVI.Api.dll中出现“System.Reflection.ReflectionTypeLoadException”类型的异常,但未在用户代码中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!