[quoted text, click to view] "Jon Jagger" <jon@jaggersoft.com> wrote in message
news:1115663791.828168.149810@z14g2000cwz.googlegroups.com...
> So I can write a test to check that what I think is happening is
> happening.
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] > Domain neutral assemblies can't be unloaded (from an
> AppDomain) so the answer is important and useful.
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] > Especially if you're
> building an extensible app with add-ins say.
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] > 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?
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] > Jon