[Mono-dev] Reflection Emit issues
Ayende Rahien
ayende at ayende.com
Fri Mar 16 16:48:59 EDT 2007
Thanks, it is good to have at least an answer.
On 3/16/07, Jb Evain <jb at db4o.com> wrote:
>
> Hey,
>
> Sorry for delay, my freshly trained spam filter decided that this was a
> spam.
>
> I'm sad to admit that I don't see any workaround for that. I guess
> you'll have to wait for someone to implement that.
>
> Jb
>
> Ayende Rahien wrote:
> > (As an aside, I want to apologize responding directly and not to the
> > list, I blame Gmail for that).
> >
> > I just checked, and you are correct, the issue is that Mono only has
> > GetMethodFromHandle(RuntimeMethodHandle handle)
> >
> > Now I am getting this error, which is why I needed to use the overload
> > with the two parameters in the first rate.
> > I just checked the svn head, and the method that I am looking for is:
> >
> > #if NET_2_0
> > public static MethodBase GetMethodFromHandle(RuntimeMeth
> > odHandle handle, RuntimeTypeHandle declaringType) {
> > throw new NotImplementedException ();
> > }
> > #endif
> >
> > so it looks like it is not supported on Mono, right?
> >
> > Castle.DynamicProxy.Tests.RhinoMocksTestCase.GenericClassWithGenericMeth
> > odWitoutTarget : System.ArgumentException : Cannot resolve method
> > System.Object Call[String](Int32,
> > System.String) because the declaring type of the method handle
> > Castle.DynamicProxy.Tests.IDoubleGene
> > ric`1[One] is generic. Explicitly provide the declaring type to
> > GetMethodFromHandle.
> >
> >
> > On 3/15/07, *Miguel de Icaza* <miguel at novell.com
> > <mailto:miguel at novell.com>> wrote:
> >
> > Hello,
> >
> > > After a lot of trail and error, here is a small sample that
> duplicate
> > > this issue, it works flawlessly on CLR, but fails on Mono.
> > > Note that I put an assert before the call to Emit(OpCode, method),
> > but
> > > it still thing that it is null.
> >
> > It is probably not finding the method because the arguments are:
> >
> > public static MethodBase GetMethodFromHandle(RuntimeMethodHandle
> handle,
> > RuntimeTypeHandle declaringType)
> >
> >
> > Try adjusting that.
> >
> >
> > > Unhandled Exception: System.ArgumentNullException: Argument cannot
> be
> > > null.
> > > Parameter name: method
> > > at System.Reflection.Emit.ILGenerator.Emit (OpCode opcode,
> > > System.Reflection.MethodInfo method) [0
> > > x00099] in C:\cygwin\tmp\scratch\mono- 1.2.3.1\mcs\class\corlib
> > > \System.Reflection.Emit\ILGenerator.cs
> > > :720
> > > at Mono.Emit.Program.Main (System.String [] args) [0x00000]
> > >
> > > class Program
> > > {
> > > static void Main(string[] args)
> > > {
> > > AssemblyName assemblyName = new AssemblyName("Blag");
> > > AssemblyBuilder assemblyBuilder =
> > > AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName,
> > > AssemblyBuilderAccess.RunAndSave);
> > > ModuleBuilder moduleBuilder =
> > > assemblyBuilder.DefineDynamicModule("Module"," test.dll");
> > > TypeBuilder typeBuilder =
> > > moduleBuilder.DefineType("Child",TypeAttributes.Class,
> > > typeof(Parent));
> > > MethodBuilder methodBuilder =
> > > typeBuilder.DefineMethod ("Method", MethodAttributes.Virtual|
> > > MethodAttributes.Public);
> > > ILGenerator ilGenerator = methodBuilder. GetILGenerator();
> > > LocalBuilder localBuilder = ilGenerator.DeclareLocal(typeof
> > > (MethodInfo));
> > > ilGenerator.Emit (OpCodes.Ldtoken,
> > > typeof(Parent).GetMethod("Method"));
> > > ilGenerator.Emit(OpCodes.Ldtoken, typeof(Parent));
> > > MethodInfo methodInfo = typeof(MethodBase).GetMethod(
> > > "GetMethodFromHandle", BindingFlags.Static |
> > > BindingFlags.Public, null,
> > > new Type[] { typeof(RuntimeMethodHandle),
> > > typeof(RuntimeTypeHandle) }, null);
> > > Debug.Assert(methodInfo != null, "GetMethodFromHandle must
> > > exists");
> > > ilGenerator.Emit(OpCodes.Call, methodInfo);
> > > ilGenerator.Emit(OpCodes.Castclass, typeof(MethodInfo));
> > > ilGenerator.Emit(OpCodes.Stloc,localBuilder);
> > > ilGenerator.EmitWriteLine(localBuilder);
> > > ilGenerator.Emit(OpCodes.Ret);
> > > Type type = typeBuilder.CreateType();
> > > Parent parent = (Parent) Activator.CreateInstance(type);
> > > assemblyBuilder.Save("test.dll");
> > > parent.Method();
> > > }
> > > }
> > >
> > > public class Parent
> > > {
> > > public virtual void Method()
> > > {
> > >
> > > }
> > >
> > > public virtual void Print(object obj)
> > > {
> > > Console.WriteLine(obj);
> > >
> > > }
> > > }
> > >
> > >
> > >
> > > On 3/12/07, Gert Driesen < gert.driesen at telenet.be
> > <mailto:gert.driesen at telenet.be>> wrote:
> > > Hi Ayende,
> > >
> > >
> > >
> > > I tried the tests myself (with SVN head), and did not even
> > > succeed in running the complete test suite:
> > >
> > >
> > >
> > > "no implementation for interface method
> > > Rhino.Mocks.Interfaces.IMockedObject::g
> > >
> > > _ProxyHash() in
> > > class .genericClass`1Proxy79e618bfe6044bb9bb680503b32a2e36
> > >
> > >
> > >
> > > This application has requested the Runtime to terminate it
> in
> > > an unusual way.
> > >
> > > Please contact the application's support team for more
> > > information."
> > >
> > >
> > >
> > > It would be great if you could create smaller test cases,
> and
> > > submit a bug reports for these issues.
> > >
> > >
> > >
> > > A good place to start would be running the unit tests of
> > > Castle on Mono, and once these pass move on to the Rhino
> > > tests.
> > >
> > >
> > >
> > > Gert
> > >
> > >
> > >
> > > From:mono-devel-list-bounces at lists.ximian.com
> > <mailto:From:mono-devel-list-bounces at lists.ximian.com>
> > > [mailto:mono-devel-list-bounces at lists.ximian.com
> > <mailto:mono-devel-list-bounces at lists.ximian.com>] On Behalf Of
> > > Ayende Rahien
> > > Sent: maandag 12 maart 2007 7:13
> > > To: mono-devel-list at lists.ximian.com
> > <mailto:mono-devel-list at lists.ximian.com>
> > > Subject: [Mono-dev] Reflection Emit issues
> > >
> > >
> > >
> > >
> > > Hi guys,
> > > I have just attempted to run the Rhino Mocks test suite on
> > > Mono (Win32).
> > > The result is about 300 failing tests. The root cause
> > seems to
> > > be differences in Reflection.Emit behavior.
> > > Rhino Mocks is using Castle Dynamic Proxy 2 to generate
> > > proxies, and all those tests are running on the Microsoft
> .NET
> > > implementation successfully.
> > >
> > > How to reproduce:
> > > 1/ Get the source from
> > >
> > https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools
> > <https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools>
> > > 2/ Build rhino-mocks (xbuild default.build )
> > > 3/ rhino-tools\rhino-mocks\Rhino.Mocks.Tests\bin\debug>"c:
> > > \Program Files\Mono-1.2.3.1\bin\mono" MbUnit.GUI.exe
> > >
> > > The result of one of the failing tests:
> > >
> > > 1)
> > >
> >
> Rhino.Mocks.Tests.FieldsProblem.PresenterBaseTestFixture.SetUp.TestEventInitialization.TearDown
> > :
> > > Argument cannot be null.
> > > Parameter name: method
> > > at System.Reflection.Emit.ILGenerator.Emit (OpCode
> opcode,
> > > System.Reflection.MethodInfo method) [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.Emitters.SimpleAST.MethodTokenExpression.Emit
> > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.Emitters.SimpleAST.AssignStatement.Emit
> > (IMemberEmitter member, System.Reflection.Emit.ILGenerator gen)
> > [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.Emitters.CodeBuilders.AbstractCodeBuilder.Generate
> > (IMemberEmitter member, System.Reflection.Emit.ILGenerator il)
> [0x00000]
> > > at
> > >
> > Castle.DynamicProxy.Generators.Emitters.ConstructorEmitter.Generate
> > () [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersAreInAValidState
> > () [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType
> > () [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode
> > (System.Type proxyTargetType, System.Type[] interfaces,
> > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget
> > (System.Type theInterface, System.Type[] interfaces,
> > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > at
> > >
> >
> Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget
> > (System.Type theInterface, System.Type[] interfaces,
> > Castle.DynamicProxy.ProxyGenerationOptions options) [0x00000]
> > > at
> > >
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > (System.Type theInterface, System.Type[] interfaces,
> > Castle.DynamicProxy.ProxyGenerationOptions options,
> > Castle.Core.Interceptor.IInterceptor[] interceptors) [0x00000]
> > > at
> > >
> > Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget
> > (System.Type theInterface, System.Type[] interfaces,
> > Castle.Core.Interceptor.IInterceptor [] interceptors) [0x00000]
> > > at Rhino.Mocks.MockRepository.MockInterface
> > > (Rhino.Mocks.CreateMockState mockStateFactory, System.Type
> > > type, System.Type[] extras) [0x00000]
> > > at Rhino.Mocks.MockRepository.CreateMockObject (
> System.Type
> > > type, Rhino.Mocks.CreateMockState factory, System.Type[]
> > > extras, System.Object[] argumentsForConstructor) [0x00000]
> > > at Rhino.Mocks.MockRepository.DynamicMultiMock (
> System.Type
> > > mainType, System.Type[] extraTypes, System.Object []
> > > argumentsForConstructor) [0x00000]
> > > at Rhino.Mocks.MockRepository.DynamicMock (System.Typetype,
> > > System.Object[] argumentsForConstructor) [0x00000]
> > > at
> > >
> Rhino.Mocks.Tests.FieldsProblem.PresenterBaseTestFixture.SetUp
> > > () [0x00000]
> > > at <0x00000> <unknown method>
> > > at (wrapper managed-to-native)
> > > System.Reflection.MonoMethod:InternalInvoke(object,object[])
> > > at System.Reflection.MonoMethod.Invoke ( System.Objectobj,
> > > BindingFlags invokeAttr, System.Reflection.Binder binder,
> > > System.Object[] parameters,
> System.Globalization.CultureInfo
> > > culture) [0x00000]
> > >
> > >
> > >
> > > _______________________________________________
> > > Mono-devel-list mailing list
> > > Mono-devel-list at lists.ximian.com
> > <mailto:Mono-devel-list at lists.ximian.com>
> > > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> > <http://lists.ximian.com/mailman/listinfo/mono-devel-list>
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070316/6172efa8/attachment.html
More information about the Mono-devel-list
mailing list