How to retrieve the LoaderException property?

Multi tool use
Multi tool use


How to retrieve the LoaderException property?



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.





How did you manage to fix this? What do you mean by "reimporting domain object project"? (remove reference to the project and re-add it again?)
– Entrodus
Jun 1 '12 at 8:13





Yes............
– rozon
Jun 13 '12 at 17:14




4 Answers
4


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





I marked you as answer because I think it will be most helpful for others experiencing this warning/error.
– rozon
Jan 14 '11 at 6:37





I'm trying to use this solution, but I have no entry point in my WCF service around which to actually wrap a try block.
– Jordan
Nov 21 '12 at 19:47





This answer would work for me if it had anything to do with my code. I've placed a try...catch around my entire Installer.cs class, and nothing! My code does not throw this when it runs, only when I try to execute the Installer. Does anyone know How to Retrieve the LoaderExceptions property for more information? Like, browse to a folder and view a log file?
– jp2code
Mar 18 '13 at 13:46


try...catch


Installer.cs





The catch clause will catch all exceptions but only handle ReflectionTypeLoadExceptions. Something like this would be better. catch (ReflectionTypeLoadException ex) { var typeLoadException = ex as ReflectionTypeLoadException; var loaderExceptions = typeLoadException.LoaderExceptions; }
– Scott Munro
Oct 17 '13 at 12:19



catch (ReflectionTypeLoadException ex) { var typeLoadException = ex as ReflectionTypeLoadException; var loaderExceptions = typeLoadException.LoaderExceptions; }





@ScottMunro: If you're catching it as one type, why create another variable with the same type and do a cast? This should suffice: catch (ReflectionTypeLoadException ex) { var loaderExceptions = ex.LoaderExceptions; }. Also, unless you expect the cast to fail and will check for null, it's better to do a direct cast so it will fail immediately and not later with a null reference exception: var typeLoadException = (ReflectionTypeLoadException)ex;
– Nelson Rothermel
Aug 8 '14 at 16:07


catch (ReflectionTypeLoadException ex) { var loaderExceptions = ex.LoaderExceptions; }


var typeLoadException = (ReflectionTypeLoadException)ex;


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.





+1 solved my problems
– Rippo
Jun 27 '13 at 13:08





Just an FYI, if you're running a Win Service (like I am), MessageBox will not appear as UI elements are automatically blocked. Rest of implementation was helpful. Just saved to a log file instead. Thanks.
– Vippy
Sep 16 '14 at 21:42





"The catch statement is missing its statement block". God, I hate powershell.
– Owl
Jul 14 '17 at 12:24



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



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


($exception).LoaderExceptions






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

iByBxrUkG xRI,6 K geSw6cMB 3p7a6L3zeOTywaCSJOukI8VK6JCHmHLhOFMmI8Yvm5
j,L,uIC,li bhHytW95yhYOSHFZm5zHUW nUoFhhAORjtsA3

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications