Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeLoadException while mocking mixed code interface that contains a method with 'const char' parameter. #244

Closed
mvdtom opened this issue Jan 28, 2016 · 3 comments

Comments

@mvdtom
Copy link

mvdtom commented Jan 28, 2016

There is an interface written in c++/cli:

public interface class IFoo
{
    virtual bool DoWork(const char type);
};

When I mock it:

var mocked = Mock.Of<IFoo>();

It throws the following exception:

System.TypeLoadException was unhandled by user code
  HResult=-2146233054
  Message=Signature of the body and declaration in a method implementation do not match.  Type: 'Castle.Proxies.IFooProxy'.  Assembly: 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
  Source=mscorlib
  TypeName=Castle.Proxies.IFooProxy
  StackTrace:
       at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
       at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
       at System.Reflection.Emit.TypeBuilder.CreateType()
       at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type)
       at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
       at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
       at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass1.<GenerateCode>b__0(String n, INamingScope s)
       at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
       at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
       at Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
       at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
       at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
       at Moq.Mock`1.<InitializeInstance>b__2()
       at Moq.PexProtector.Invoke(Action action)
       at Moq.Mock`1.InitializeInstance()
       at Moq.Mock`1.OnGetObject()
       at Moq.Mock`1.get_Object()
       at Moq.Mocks.<CreateMocks>d__0`1.MoveNext()
       at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at lambda_method(Closure )
       at System.Linq.EnumerableExecutor`1.Execute()
       at System.Linq.EnumerableQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
       at System.Linq.Queryable.First[TSource](IQueryable`1 source)
       at lambda_method(Closure )
       at Moq.Linq.MockQueryable`1.Execute[TResult](Expression expression)
       at System.Linq.Queryable.First[TSource](IQueryable`1 source)
       at Moq.Mock.Of[T]()
       at MoqTest.Class1.Test() in c:\users\mvdto_000\documents\visual studio 2015\Projects\MoqTest\MoqTest\Class1.cs:line 20
  InnerException: 

It occurs only with const modifier and only with char. It works fine without const as well as with another type (e.g. int).

@stakx
Copy link
Contributor

stakx commented Jun 23, 2017

@mvdtom, thanks for the report. This is an issue with Castle DynamicProxy, so I have forwarded your report to the Castle Core project (see castleproject/Core#277) with some added details.

@stakx
Copy link
Contributor

stakx commented Jun 28, 2017

A fix for this has just been merged into Castle.Core (see castleproject/Core#278), so this issue will be resolved as soon as we update Moq to DynamicProxy >4.1.0.

@stakx
Copy link
Contributor

stakx commented Jul 5, 2017

This has been taken care of in Castle.Core, so there's nothing left to do here other than wait for the next release of that dependency. This is being tracked by #402.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants