tags:

views:

303

answers:

3

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(...)?

A: 

This is for DynamicMethods and thus goes for expressions too.

You cannot load it manually.

leppie
Well, why not? :-)
dbaw
+2  A: 

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.

Hans Passant
Thanks for your answer. Is there a way to determine when this dynamically created assembly object is created?
dbaw
The debugger notification is a good hint.
Hans Passant
Sorry, I meant 'determine' as in 'influence', not 'identify' :-) So could one advance or delay the loading of dynamic assembly objects?
dbaw
Erm, yes, don't execute the code that uses Reflection.Emit. You'll have to find it first.
Hans Passant
OK. The point is: in the project I'm currently working on, this loading takes quite some time when a certain piece of code is reached. What I tried to do was to move the loading of this dynamic assembly to the startup phase of the application. But if I understand you correctly, this could be quite some challenge.
dbaw
Erm, so you don't actually want to delay it, you want to run it sooner. That still requires you finding out where that code is located and what method call is required to run it. Surely there's a programmer out there somewhere that wrote that code and knows the answer? She might be in the next cubicle?
Hans Passant
Well, who knows! ;-)
dbaw
A: 

Hi

I guess that this is an assembly emitted at run time. Since it's not required to save the assembly to disk, it may not be possible to load it manually (in this case when the code finishes emitting the assembly - into memory - it will use the types defined in the assembly directly - no need to load anything)

For more information see the documentation in msdn.

Best

Vagaus