Ich versuche, eine Klasse aus dem Microsoft Sync Framework zu verspotten. Es hat nur einen internen Konstruktor. Wenn ich versuche, die folgenden:Verspottung eines Typs mit einem internen Konstruktor mit Moq
var fullEnumerationContextMock = new Mock<FullEnumerationContext>();
ich diesen Fehler:
System.NotSupportedException: Parent does not have a default constructor. The default constructor must be explicitly defined.
Dies ist der Stack-Trace:
System.Reflection.Emit.TypeBuilder.DefineDefaultConstructorNoLock(MethodAttributes attributes) System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor(MethodAttributes attributes) System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() System.Reflection.Emit.TypeBuilder.CreateType() Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType() Castle.DynamicProxy.Generators.ClassProxyGenerator.GenerateCode(Type[] interfaces, ProxyGenerationOptions options) Castle.DynamicProxy.DefaultProxyBuilder.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) Castle.DynamicProxy.ProxyGenerator.CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options) Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, Object[] constructorArguments, IInterceptor[] interceptors) Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors) Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, IInterceptor[] interceptors) Moq.Mock
1.<InitializeInstance>b__0() Moq.PexProtector.Invoke(Action action) Moq.Mock
1.InitializeInstance()
Wie kann ich mich um diese Arbeit?
Vielen Dank für diese Frage! Es ist nur die Existenz, die mir geholfen hat. Ich war auf meinem eigenen Code in der Lage, den Konstruktor öffentlich zu machen. Leider kann mir das nicht helfen, aber du hast mir trotzdem geholfen +1 – Marcel