Test "GenericMethodShouldBeProxied" failing for x86 but not x64?

106 views
Skip to first unread message

cremor

unread,
May 11, 2011, 2:26:54 AM5/11/11
to nhibernate-development
This message is about that issue:
http://216.121.112.228/browse/NH-2698

I think I just found out why the test didn't fail for Fabio. It
succeeds if I start it with nunit.exe, but it fails if I start it with
nunit-x86.exe (using the latest trunk right now). The exception is
"System.Security.VerificationException : Method
NHibernate.Test.DynamicProxyTests.GenericMethodsTests.GenericMethodShouldBeProxied
+MyClass.As: type argument 'T0' violates the constraint of type
parameter 'TRequestedType'."

Can someone reproduce this? If yes, please reopen the issue :-)

And if someone has an explanation for this different behaviour of
the .NET runtimes it would be great if he could explain it for me.

cremor

unread,
May 16, 2011, 11:02:09 AM5/16/11
to nhibernate-development
Seems like this was fixed with r5816, thanks!
I think the issue should be changed to "fixed in 3.2.0.Beta1" so it
appears in the changelog.

Richard Brown (gmail)

unread,
May 16, 2011, 11:07:16 AM5/16/11
to nhibernate-development
Done.

Sorry I hadn't realised the correlation between the JIRA ticket and the fix.
I should really pay more attention.

Thanks for letting us know.

Cheers.

cremor

unread,
May 23, 2011, 9:23:57 AM5/23/11
to nhibernate-development
After some hours of debugging I just found out why generic methods
still don't work in my project but work perfectly in the NHibernate
unit tests: It's the .NET runtime version.

NUnit is using the 2.0 runtime, everything works fine there. But my
project is using the 4.0 runtime and there the call to the generic
method fails.
Luckily this can be reproduced without changing any code. If you
change the app.config files of NUnit (in my case nunit-x86.exe.config
and nunit-agent-x86.exe.config) the way it's shown here
http://mint.litemedia.se/2010/11/04/nunit-for-net-framework-4/ both
tests of GenericMethodsTests.GenericMethodShouldBeProxied fail.
The exception is "InvalidOperationException : Late bound operations
cannot be performed on types or methods for which
ContainsGenericParameters is true."

The problem here is that with the assembly generated in the 4.0
runtime the MethodInfo parameter of the InvocationInfo constructor is
an open generic method (As<T>) instead of a closed one (As<MyClass>)
and therefore the info.TargetMethod.Invoke() call of the Interceptor
fails with the exception I mentioned above.

While debugging this I compared the generated dynamic assemblies and
there I found a little difference between the assembly generated in
2.0 and 4.0:
2.0 code line:
L_0014: ldtoken instance !!0
[NHibernate.Test]NHibernate.Test.DynamicProxyTests.GenericMethodsTests.GenericMethodShouldBeProxied/
MyClass::As<!!T0>()
4.0 code line:
L_0014: ldtoken instance !!0
[NHibernate.Test]NHibernate.Test.DynamicProxyTests.GenericMethodsTests.GenericMethodShouldBeProxied/
MyClass::As()
(note the missing generic type parameter at the end)

So it seems like a fix should be made in
DefaultMethodEmitter.EmitMethodBody(), but sadly all that IL is way to
complex for me, so I stopped the debugging there.

Should I submit a Jira issue about this although I can't provide a
unit test that fails with the 2.0 runtime?
And any chance someone will look into this? :-)


On May 16, 5:07 pm, "Richard Brown \(gmail\)"

Richard Brown (gmail)

unread,
May 23, 2011, 10:02:23 AM5/23/11
to nhibernate-development
I would expect NH to run in .Net 4.0, so I think there should be a JIRA for
this.

If you could reference this thread in the JIRA that would be great.

Thanks,
Richard

cremor

unread,
May 23, 2011, 10:12:05 AM5/23/11
to nhibernate-development
Done: http://216.121.112.228/browse/NH-2726

On May 23, 4:02 pm, "Richard Brown \(gmail\)"
Reply all
Reply to author
Forward
0 new messages