Created
November 1, 2012 15:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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