Wednesday, June 05, 2013

Some code for finding LoaderExceptions

Just for my own future reference really....


try
{
// nasty code
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions = typeLoadException.LoaderExceptions;
string blast = ex.StackTrace;
foreach (var loaderException in loaderExceptions)
{
blast += loaderException.Message;
}
throw new Exception(blast);
}
}

No comments:

Post a Comment