Karl, I was the one who created that JIRA issue. Since reporting it,
I've improved the DP API quite a bit.
In fact, in the current DP trunk revisions, PersistentProxyBuilder
doesn't automatically save any longer (it did that previously, which
resulted in the assemblies holding only the last generated type);
instead, you need to manually call
PersistentProxyBuilder.SaveAssembly, which will save all the types
generated with that builder so far.
I haven't taken the time to implement support for loading the
assemblies until now simply because it's a lot of work. However, with
these performance issues popping up, I'll look into it again.
I'm not sure how often Ayende updates Rhino.Mocks to the latest Castle
trunk, though.
> http://support.castleproject.org/browse/DYNPROXY-72
Hm, it would be expected that CreateMock runs slower with a debugger
attached than without, but I wouldn't expect it to be that slow.
However, I don't think there's anything we (= Castle) can do there -
it seems to be a Reflection.Emit/debugger issue, right? (Maybe you
could do some profiling with a debugger attached to check where
exactly all the time is spent? I'd suspect one or several of the
Reflection.Emit methods.)
However, once you have save/load support, you can work-around that issue, right?
Fabian
[...]
I have now implemented support for loading proxies from disk in Castle
DynamicProxy 2 (trunk revision 4800). As soon as Rhino.Mocks is
upgraded to the latest version of the Castle trunk, you should be able
to use that API (ModuleScope.LoadAssemblyIntoCache, access via
IProxyBuilder.ModuleScope).
Fabian
You could check whether there is an assembly in the application base
directory that is newer than the generated file (if one exists) and
use this as a heuristic for proxy regeneration, for example.
Fabian
> You could check whether there is an assembly in the application base
directory
> that is newer than the generated file (if one exists) and use this as
a
> heuristic for proxy regeneration, for example.
I think I'd probably try and work out some way to embed metadata e.g.
the assembly timestamp when the proxy was generated in the proxy
assembly. It's always possible, for example, that a referenced assembly
may be reverted to an earlier version in which case the timestamp test
would succeed when the desired result would be a failure (so the proxy
gets regenerated).
Just my humble opinion.
Regards,
Richard
* C O N F I D E N T I A L I T Y N O T I C E *
-----------------------------------------------------------
The content of this e-mail is intended solely for the use of the individual or entity to whom it is addressed. If you have received this communication in error, be aware that forwarding it, copying it, or in any way disclosing its content to any other person, is strictly prohibited. Quixote Traffic Corporation is neither liable for the contents, nor for the proper, complete and timely transmission of (the information contained in) this communication. If you have received this communication in error, please notify the author by replying to this e-mail immediately and delete the material from any computer.
You can also embed information in the generated assembly file, e.g. by
defining a custom attribute on the proxy builder's AssemblyBuilder.
You can access the AssemblyBuilder via
IProxyBuilder.ModuleScope.StrongNamedModule/WeakNamedModule.Assembly,
I think. (Take a look at how DP stores the cache metadata in
ModuleScope.SaveAssembly(bool):
http://svn.castleproject.org:8080/svn/castle/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy/ModuleScope.cs)
Regards,
Fabian
You're right, inspecting metadata via Reflection requires the assembly
to be loaded. If you want to avoid loading stale assemblies you'd need
to inspect it in a separate AppDomain (that's not so problematic, look
at the test cases in
http://svn.castleproject.org:8080/svn/castle/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/ModuleScopeTestCase.cs
(bottom) and at the CrossAppDomainCaller class in
http://svn.castleproject.org:8080/svn/castle/trunk/Tools/Castle.DynamicProxy2/Castle.DynamicProxy.Tests/CrossAppDomainCaller.cs).
However, if you prefer the .cache file approach, just go ahead, it's
probably simpler :)
Fabian