Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the 'Anonymously Hosted DynamicMethods Assembly' and how can I make it load manually?

Tags:

c#

.net

As a .NET developer, the line

'<process name>' (Managed): Loaded 'Anonymously Hosted DynamicMethods Assembly' 

probably is familiar to you. My question is simple and straightforward: what exactly is this 'Anonymously Hosted DynamicMethods Assembly' and can I make it (pre)load manually? If so, how? Can this be done via Assembly.Load(...)?

like image 953
hwschuur Avatar asked Apr 14 '10 09:04

hwschuur


2 Answers

System.Reflection.Emit contains classes that allows you to create dynamically generated code by emitting IL instructions. The DynamicMethod and AssemblyBuilder classes are the work-horses for doing so. IL normally is loaded from an assembly, but there is no assembly when you generate the IL dynamically. An assembly object is however needed to act as the container of the IL code and a "fake" one is created by AppDomain.DefineDynamicAssembly(). That's what you see in the debugger notification.

You can't use Assembly.Load(), the assembly is created dynamically.

like image 54
Hans Passant Avatar answered Sep 20 '22 17:09

Hans Passant


This is for DynamicMethods and thus goes for expressions too.

You cannot load it manually.

like image 22
leppie Avatar answered Sep 18 '22 17:09

leppie