It appeared that DP calls AssemblyBuilder.DefineDynamicModule() with the
flag that also builds debug symbols. This is still not allowed under
medium trust as this still requires
ReflectionPermissionFlag.ReflectionEmit permissions where the rest works
fine since .NET 2.0 SP1
(http://msdn.microsoft.com/en-us/library/76xbchca.aspx).
In ModuleScope.cs, I changed the calls to not generate debug symbols
(see attached patch) and it finally works under medium trust! Also, all
DP tests still pass.
This is huge, because it will also allow NHibernate to run under medium
trust without having to turn off lazy load or use a proxy generator.
Now I wonder if not generating debug symbols has major drawbacks? I am
still able to step into a proxied method of a service (decorated with
ATM attribute) but I have no idea of other side-effects since I know
nothing about the inner workings of DynamicProxy.
Patch is attached.
But this also raised another issue in web environments: you can't safely
use either CallContext or TLS because a request is not guaranteed to run
in a single thread. IMO, there should also be a
HttpContextActivityManager that stores the ActivityManager in
HttpContext.Current.Items, just like the WebSessionStore in the
NHibernateIntegration facility. And now we're at the
NHibernateIntegration facility: wouldn't it be nice that when you set
isWeb="true", the facility automagically also uses the
HttpContextActivityManager?
Opinions?