all groups > dotnet clr > may 2005 >
You're in the

dotnet clr

group:

is there an API to determine if an assembly is loaded domain neutral?


is there an API to determine if an assembly is loaded domain neutral? Jon Jagger
5/9/2005 10:04:44 AM
dotnet clr:
and if so what is it?
Thanks
Jon Jagger
Re: is there an API to determine if an assembly is loaded domain neutral? Jon Jagger
5/9/2005 11:36:31 AM
So I can write a test to check that what I think is happening is
happening. Domain neutral assemblies can't be unloaded (from an
AppDomain) so the answer is important and useful. Especially if you're
building an extensible app with add-ins say. It's amazing how many APIs
are built without testing in mind. Given all the options of whether an
assembly is or isn't loaded domain neutral don't you wonder how this
stuff was tested?
Jon
Re: is there an API to determine if an assembly is loaded domain neutral? Yves Tourchot
5/9/2005 2:59:39 PM

[quoted text, click to view]

Take a look at

AssemblyIsDomainNeutral

On framework 2.0

Re: is there an API to determine if an assembly is loaded domain neutral? Sean Hederman
5/9/2005 7:45:05 PM
[quoted text, click to view]

Short of rolling your own runtime host, I don't know of any way to do this.
Is there any particular reason you need this information? Since
domain-neutral assemblies have no impact on your code, merely on the size of
the working set, it shouldn't make any difference to your application.

[quoted text, click to view]

Re: is there an API to determine if an assembly is loaded domain neutral? Sean Hederman
5/10/2005 12:00:00 AM
[quoted text, click to view]

Good reason. How about hooking the AppDomain.AssemblyLoad event? I'm not
sure if this fires in other domains when the assembly is "loaded" from the
domain-neutral domain or not. If it doesn't then if you have access to an
assembly that wasn't loaded, then by definition it would be domain neutral.

[quoted text, click to view]

Not quite, domain-neutral assemblies are loaded into the SharedDomain.
They're never unloaded because the SharedDomain only unloads on process
exit. However, if you have 20 "child" AppDomains each with a "copy" of a
domain-neutral assembly, the assembly has only been loaded once, into the
SharedDomain. Each of the child AppDomains maintains a data section for the
assembly (containing statics and suchlike), but does not contain the actual
assembly. Needless to say this is of no help if you're loading 20 different
domain-neutral assemblies, but does help if they're common.

[quoted text, click to view]

Using CorBindToRuntimeEx you can specify whether to load no assemblies
domain-neutral (only mscorlib will be neutral), all assemblies as domain
neutral, or only strong-named assemblies as domain neutral. You can specify
the same options by setting the LoaderOptimization property on the
AppDomainSetup object when creating your AppDomain. You should be able to
query it in the DefaultDomain as well (or use the
LoaderOptimizationAttribute on your entry point). This won't tell you which
ones are domain neutral, but it will give you the policy used. You could use
this setting along with AppDomain.AssemblyResolve to try and determine how
each assembly is being loaded.

In .NET 2.0 the GetDomainNeutralAssemblies is implemented by IHostControl,
and can be used by a runtime host to provide granular control over
domain-neutral assemblies. It also provides the AssemblyIsDomainNeutral
method on System.Diagnostics.Loader, which will provide the capabilities you
require.

[quoted text, click to view]

Not really, since the domain-neutrality should have no impact on most code.
In the situation of a highly-customisable highly-available stateful server
domain-neutrality information could be of use, which is why it's probably in
2.0, since SQL Server will likely make use of this information.

[quoted text, click to view]

Re: is there an API to determine if an assembly is loaded domain neutral? David Levine
5/10/2005 5:05:56 AM
There's a book called "Customizing the Microsoft .NET Framework Common" by
Steven Pratschner that goes into great detail about assembly loading
issues - highly recommended. It talks about domain neutral assemblies, which
ones are automatically loaded that way, and how to load your own that way.
By default your own assemblies will never be loaded that way. You have to
write a .NET host to customize it.


[quoted text, click to view]

Re: is there an API to determine if an assembly is loaded domain neutral? Sean Hederman
5/11/2005 7:30:43 AM
[quoted text, click to view]

Whoops. This only appears to apply in console applications.

Re: is there an API to determine if an assembly is loaded domain neutral? Jon Jagger
5/12/2005 11:41:11 PM

On page 251 of the Pratschner book he says that your own assemblies are
loaded domain neutral if they're strongly named and the setup for the
AppDomain is multi-domain-host....
Jon


[quoted text, click to view]
AddThis Social Bookmark Button