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

Are internal methods supported? #695

Open
baynezy opened this issue Feb 27, 2025 · 1 comment
Open

Are internal methods supported? #695

baynezy opened this issue Feb 27, 2025 · 1 comment

Comments

@baynezy
Copy link

baynezy commented Feb 27, 2025

I have a bug raised on NSubstitute nsubstitute/NSubstitute#866 which after some debugging looks like it makes more sense to be here.

I have a reporoduction case which you can check out here https://github.com/baynezy/NSubstituteIssue

Essentially, this interface can be mocked:

public interface IExample
{
    bool Check();
}

and this one

public interface IExampleWithInternal
{
    internal bool Check();
}

throws a System.TypeLoadException.

Let me know if you need more detail.

Thanks.

@304NotModified
Copy link

304NotModified commented Feb 27, 2025

In addition, this will also give the same exception in Moq. So it's unclear is this a bug, a limitation or NSubstitute and Moq doing incorrect calls.

The full exception stacktrace, with the message from Castle Core "method .. does not have an implementation":

System.TypeLoadException
Method 'Check' in type 'Castle.Proxies.IExampleWithInternalProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
   at System.Reflection.Emit.RuntimeTypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.RuntimeTypeBuilder.CreateTypeInfoImpl()
   at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
   at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.CreateType(TypeBuilder type)
   at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
   at Castle.DynamicProxy.Generators.BaseInterfaceProxyGenerator.GenerateType(String typeName, INamingScope namingScope)
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.<>c__DisplayClass13_0.<GetProxyType>b__0(CacheKey cacheKey)
   at Castle.Core.Internal.SynchronizedDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Castle.DynamicProxy.Generators.BaseProxyGenerator.GetProxyType()
   at Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
   at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
   at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
   at Moq.CastleProxyFactory.CreateProxy(Type mockType, IInterceptor interceptor, Type[] interfaces, Object[] arguments) in /_/src/Moq/Interception/CastleProxyFactory.cs:line 50
   at Moq.Mock`1.InitializeInstance() in /_/src/Moq/Mock`1.cs:line 309
   at Moq.Mock`1.OnGetObject() in /_/src/Moq/Mock`1.cs:line 323
   at Moq.Mock.get_Object() in /_/src/Moq/Mock.cs:line 181
   at Moq.Mock`1.get_Object() in /_/src/Moq/Mock`1.cs:line 281
   at Target.UnitTests.ReproductionCase.Moq_IExampleWithInternal() 

Tested with version 5.1.1

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

No branches or pull requests

2 participants