Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.



C#
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:

C#
[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
Posted
Updated 17-Dec-15 3:53am
v5
Comments
ZurdoDev 17-Dec-15 8:31am    
This is a key part of the error: "Retrieve the LoaderExceptions property for more information."
[no name] 17-Dec-15 8:39am    
what i can do? how i can fix this?

1 solution

Don't you see that the exception you are talking about has been thrown from "catch" - block:
C#
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:
C#
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 ...
 
Share this answer
 
v2
Comments
[no name] 17-Dec-15 9:42am    
so what i can do? i am new to thispls help me to find a solution

Leo Chapiro 17-Dec-15 9:55am    
As I already said, you need to DEBUG your code line-by-line, do you think you will get it been a software developer?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900