How to retrieve the LoaderException property?

C#.NetWcf

C# Problem Overview


I get a error message while updating my service reference:

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

How can I retrieve the LoaderException property?

Update: My errors went away when I reimported the domain object projects. I have no idea why this fixed the issue, but I'm happy it's working.

C# Solutions


Solution 1 - C#

try
{
// load the assembly or type
}
catch (Exception ex)
{
if (ex is System.Reflection.ReflectionTypeLoadException)
{
var typeLoadException = ex as ReflectionTypeLoadException;
var loaderExceptions  = typeLoadException.LoaderExceptions;
}
}

Solution 2 - C#

catch (ReflectionTypeLoadException ex)
{        
    foreach (var item in ex.LoaderExceptions)
    {
          MessageBox.Show(item.Message);                    
    }
}

I'm sorry for resurrecting an old thread, but wanted to post a different solution to pull the loader exception (Using the actual ReflectionTypeLoadException) for anybody else to come across this.

Solution 3 - C#

Using Quick Watch in Visual Studio you can access the LoaderExceptions from ViewDetails of the thrown exception like this:

($exception).LoaderExceptions

Solution 4 - C#

Another Alternative for those who are probing around and/or in interactive mode:

> $Error[0].Exception.LoaderExceptions

Note: [0] grabs the most recent Error from the stack

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrozonView Question on Stackoverflow
Solution 1 - C#KBoekView Answer on Stackoverflow
Solution 2 - C#Jacob SaylorView Answer on Stackoverflow
Solution 3 - C#hugo4711View Answer on Stackoverflow
Solution 4 - C#techsaintView Answer on Stackoverflow