You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been attempting to use moq to mock a class with an internal constructor. Following on from my SO post i appear to be hitting the constructor, but now faced with a new error, i.e.,
System.MethodAccessException
Attempt by method 'Castle.Proxies.MyClassProxy..ctor(Castle.DynamicProxy.IInterceptor[])'
to access method 'MyAssembly.MyClass..ctor()' failed.
at Castle.Proxies.StageProxy..ctor(IInterceptor[] )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] >arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type proxyType, List1 proxyArguments, Type classToProxy, Object[] constructorArguments) at Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments) at Moq.Mock1.b__20_0()
at Moq.PexProtector.Invoke(Action action)
at Moq.Mock1.InitializeInstance() at Moq.Mock1.OnGetObject()
at Moq.Mock`1.get_Object()
at TestAssembly.UnitTest1.TestMethod1() in c:\users\briaris-j\documents\visual studio 2017\Projects\TestMoqInternals\TestAssembly\UnitTest1.cs:line 16
This is my AssemblyInfo.cs for MyAssembly, i.e., the assembly containing my internal types
The quickstart guide contained an inaccuracy here. You only need to include the public key in the assembly name if your own assembly is strong-named. If it isn't, then you should not include the public key.
It seems that you are not strong-naming your project that uses Moq, so I believe you've already discovered the correct solution.
I've been attempting to use moq to mock a class with an internal constructor. Following on from my SO post i appear to be hitting the constructor, but now faced with a new error, i.e.,
This is my
AssemblyInfo.cs
forMyAssembly
, i.e., the assembly containing my internal typesAny ideas how this may be fixed?
The text was updated successfully, but these errors were encountered: