Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Created November 1, 2012 15:04
Show Gist options
  • Save gabrieljoelc/3994175 to your computer and use it in GitHub Desktop.
Save gabrieljoelc/3994175 to your computer and use it in GitHub Desktop.
Use this to code to determine the type that can't be loaded on a "ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." exception
// ripped this off from this stackoverflow.com answer:
// http://stackoverflow.com/a/8824250/34315
using System.IO;
using System.Reflection;
try
{
//The code that causes the error goes here.
}
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.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment