carlpett
carlpett

Reputation: 12613

How to handle exception in external/unknown DynamicMethods assembly

I have a situation where I get an exception in a dynamic assembly, which in turn terminates my application. I assume this assembly is generated by some of the third party libraries we use, because we don't use Reflection.Emit or other codegen tools ourselves. However, as far as I can tell, there is no way for me to determine where it comes from?

This is the exception I get:

An unhandled exception of type 'System.ArgumentException' occurred in Unknown Module.

Additional information: An item with the same key has already been added.

Is there tooling, or some code I can write into my own application, to figure out what is going on?

Upvotes: 0

Views: 354

Answers (1)

Lucas Trzesniewski
Lucas Trzesniewski

Reputation: 51430

Go to Debug -> Exceptions:

Exceptions dialog http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-82-17-metablogapi/5824.image_5F00_thumb.png

then check the Thrown checkbox on the Common Language Runtime Exceptions line (or directly on the ArgumentException line). This will make the debugger kick in as soon as any exception is thrown, before the stack is unwinded. You'll be able to examine the call stack at this point.

Note that you may also have to disable the following option:
Tools -> Options -> Debugging -> General -> Enable Just My Code

And in the call stack window, enable Show External Code from the context menu:

call stack context menu http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-82-17-metablogapi/5672.image_5F00_thumb_5F00_3.png

Upvotes: 1

Related Questions