I am trying to Stub IUnityContainer using Rhino Mocks, and with this
change the problem persists.
The exception is the following:
System.BadImageFormatException: An attempt was made to load a program
with an incorrect format. (Exception from HRESULT: 0x8007000B)
at
IUnityContainerProxy878915366750464caf2756ec11621ba0.RegisterType<TFrom,TTo>
(InjectionMember[] injectionMembers)
at SecurityModule.SecurityModule.RegisterViewsAndServices() in
SecurityModule.cs: line 39
at SecurityModule.SecurityModule.Initialize() in SecurityModule.cs:
line 31
at
SecurityModule.Tests.SecurityModuleTests.InitializeShouldRegisterLoginView
() in SecurityModuleTests.cs: line 41
Other symptoms:
I need to run in debug mode, otherwise I get the following exception
when I try to create the stub.
System.BadImageFormatException: An attempt was made to load a program
with an incorrect format. (Exception from HRESULT: 0x8007000B)
at System.Reflection.Emit.TypeBuilder._TermCreateClass(Int32 handle,
Module module)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
() in AbstractTypeEmitter.cs: line 271
at
Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
() in AbstractTypeEmitter.cs: line 275
at
Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode
(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions
options) in InterfaceProxyWithTargetGenerator.cs: line 326
at
Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)
in DefaultProxyBuilder.cs: line 70
at
Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)
in ProxyGenerator.cs: line 392
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(Type theInterface, Type[] interfaces, ProxyGenerationOptions options,
IInterceptor[] interceptors) in ProxyGenerator.cs: line 262
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
(Type theInterface, Type[] interfaces, IInterceptor[] interceptors) in
ProxyGenerator.cs: line 239
at Rhino.Mocks.MockRepository.MockInterface(CreateMockState
mockStateFactory, Type type, Type[] extras) in MockRepository.cs: line
816
at Rhino.Mocks.MockRepository.CreateMockObject(Type type,
CreateMockState factory, Type[] extras, Object[]
argumentsForConstructor) in MockRepository.cs: line 874
at Rhino.Mocks.MockRepository.Stub(Type type, Object[]
argumentsForConstructor) in MockRepository.cs: line 1321
at Rhino.Mocks.MockRepository.GenerateStub(Type type, Object[]
argumentsForConstructor) in MockRepository.cs: line 1343
at Rhino.Mocks.MockRepository.GenerateStub<T>(Object[]
argumentsForConstructor) in MockRepository.cs: line 1332
at
SecurityModule.Tests.SecurityModuleTests.InitializeShouldRegisterLoginView
() in SecurityModuleTests.cs: line 37
On Jan 12, 7:28 am, "Fabian Schmied" <
fabian.schm...@gmail.com> wrote:
> Fixed on the trunk. Thanks, Krzystof, for investigating the problem. I
> fixed it by making AddFieldToCacheMethodTokenAndStatementsToInitialize
> perform the check forgenericmethods.
>
> Fabian
>
> On Mon, Jan 12, 2009 at 12:54 PM, Fabian Schmied
>
> <
fabian.schm...@gmail.com> wrote:
> > This is definitely a bug in ImplementBlankInterface, which for some
> > reason doesn't use the "CacheMethodTokens" method. The current
> > workaround forgenericmethodsin "CacheMethodTokens" is to not cache
> > them (your solution number 2), so ImplementBlankInterface shouldn't
> > cache them either.
>
> > I'll fix this.
>
> > Fabian
>
> > PS: Yes, it's inefficient, and maybe we should talk about fixing this,
> > but I'll make it consistent first, we can optimize later.
>
> > On Mon, Jan 12, 2009 at 12:03 PM, Krzysztof Kozmic <
KKoz...@atsisa.com> wrote:
>
> >> Craig,
>
> >> The problem is in .cctor, when trying to get MethodInfo of thegeneric
> >> method with ldtoken.
> >> Unfortunately the API for opengenericmethodsseems to be broken, and
> >> I couldn't find a clean way of getting Methodinfo for such a method.
> >> There are two solutions for that.
>
> >> 1. Try to cache the method in some other way, than by ldtoken
> >> The best I came up with so far is this:
> >> MemberInfo[]methods= type.GetMember( "MethodName",
> >> MemberTypes.Method,
> >> BindingFlags.Instance
> >> |
> >> BindingFlags.Public
> >> |
>
> >> BindingFlags.NonPublic );
> >> //and now filter out the method we need, and assign it to
> >> the cache field
>
> >> We get the MethodInfos for not only thegenericmethod, but for all
> >>methodswith the same name, and we need to filter it out.
>
> >> 2. Alternatively, easler thing to do, is to not cache thegeneric
> >> method.
>
> >> This requires changing ImplementBlankInterface method of
> >> BaseProxyGenerator, so that in foreach loop when current method is open
> >>genericmethod
> >> it won't get cached.
>
> >> I don't have access to the repository to create the patch, but it's
> >> straightforward.
> >> With that little change your test, as well as all other pass.
>
> >> This however means worse performance. Probably someone should create a
> >> solution that does a lot operations with thesegenericmethods, and
> >> profile it to see how well it behaves.
> >> If the performance hit is significant, we might try the 1st approach
> >> and see if it improves things.
>
> >> Krzysztof
>
> >>>>>
cneuw...@gmail.com 2009-01-10 19:04:18 >>>
> >> Krzysztof, Fabian
>
> >> It looks like the problem is when creating interfaces proxies while
> >> specifying additional interfaces that includegenericmethods. I
> >> created a
> >> unit test to demonstrate the problem. It is checked in on DP2 trunk
> >> with
> >> the Ignore attribute.
>
> >>
http://svn.castleproject.org:8080/svn/castle/trunk/Tools/Castle.Dynam...
>
> >> I am currently trying to resolve this defect in the WCF integration
> >> facility
> >>
http://support.castleproject.org/projects/DYNPROXY/issues/view/DYNPRO...
>
> >> Thanks for your help,
> >> Craig
>
> >> I also have defects when creating class proxies that call selfgeneric
> >>methods. This is happening when using MS MVC Controllers that have
> >>generic
> >>methods, but that is something totally different and I'll create more
> >> broken
> >> tests for that too.
>
> >> On Sat, Jan 10, 2009 at 2:33 AM, Fabian Schmied
> >> <
fabian.schm...@gmail.com>wrote:
>
> >>> > Does anyone have any idea the extent of change to DP2 to support
> >>proxying
> >>> >genericmethods? Got a few defects from that.
>
> >>> This is actually implemented. There are, however, a few bugs in the
> >>> .NET 2.0 CLR (before SP2, at least), which make this really hard to
> >>> get right. There are a few workarounds in there (eg. tokens of
> >>generic
> >>>methodsaren't cached, there is this ominous