tags:

views:

39

answers:

1

...and can those steps also be applied to a 3rd party assembly (that might already be strong-named)?

The context for my question should not be important, but I'll share anyway: I'm thinking of making a logger (or log-wrapper) that always knows what "log source" to target, regardless of whether the assemblies using it are in one appdomain, or spread across several appdomains. I think one way to achieve that, is to have a domain-neutral assembly with a static "LogSource" property. If that static property is set in a domain-neutral assembly, I think all appdomains will see it.

A: 

Domain-neutral assemblies share only code across appdomains. However, data is still per-appdomain. Thus, there will be one copy of your static LogSource property for each domain.

Franci Penov
But how do you create a domain-neutral assemblies? And can a 3rd party (possibly strong-named) assembly be converted too?
Brent Arias
You don't do anything specific at assembly build time. The CLR decides at load time if the assembly can be loaded as domain-neutral based on the host and the appdomain policies.
Franci Penov
@Franci: I'm seeing a different story (http://www.drdobbs.com/184405853;jsessionid=VQ1FBYMTHDGU5QE1GHRSKH4ATMY32JVN). It appears I can only make a main program domain-neutral, and it must be decorated with the LoaderOptimizationAttribute. Have I answered my own question, or does .net 3.5 or 4.0 change the story?
Brent Arias
I am not sure how that is a different story. The attribute is just a hint to the loader what policies to set on the appdomain when it is created. However, you can set the same policy when you are explicitly creating new domain through the CLR host interfaces. Meanwhile, once the policy on the appdomain is set, it affects loading other assemblies in the appdomain, not only the assembly containing the Main method.
Franci Penov
I think the link I gave in my comment above is 75% the answer I was looking for. But if you will be more specific about the "CLR host interface", I will mark it as the answer. For example, what are the signatures you have in mind?
Brent Arias
There is an unmanaged interface that can be used by C++ applications to load the CLR and host it in their process and create managed appdomains. In fact, it's the same process that is used by the unmanaged loader stub that the OS executes when it loads a managed executable. More info: http://msdn.microsoft.com/en-us/magazine/cc301479.aspx
Franci Penov