11 February, 2013

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

Problem:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Solution:
To know in details what exactly happen add one more catch block like below.

catch (ReflectionTypeLoadException ex)
{
    StringBuilder sb = new StringBuilder();
    foreach (Exception exSub in ex.LoaderExceptions)
    {
        sb.AppendLine(exSub.Message);
        if (exSub is FileNotFoundException)
        {
            FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
            if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
            {
                sb.AppendLine("Fusion Log:");
                sb.AppendLine(exFileNotFound.FusionLog);
            }
        }
        sb.AppendLine();
    }
    string errorMessage = sb.ToString();
    //Display or log the error based on your application.
}

No comments:

Post a Comment