NSubstitute
NSubstitute copied to clipboard
Exception is thrown if method with an interpolated string handler argument on a mocked interface is called
Describe the bug If a mocked interface has a method with an interpolated string handler an exception is thrown if the method is called.
To Reproduce
using System.Runtime.CompilerServices;
var foo = NSubstitute.Substitute.For<IFoo>();
foo.Foo($"{foo.GetType()}");
public interface IFoo
{
void Foo(DefaultInterpolatedStringHandler handler);
}
System.InvalidProgramException
HResult=0x8013153A
Message=Common Language Runtime detected an invalid program.
Source=DynamicProxyGenAssembly2
StackTrace:
at Castle.Proxies.ObjectProxy.Foo(DefaultInterpolatedStringHandler handler)
at Program.<Main>$(String[] args) in Program.cs:line 6
Expected behaviour No exception
Environment:
- NSubstitute version: 5.0
- Platform: .NET 7.0
NSubstitute relies on Castle.Core for proxy generation.
It seems Castle.Core does not work with ref struct types. So there is not much NSubstitute can do about this.
Possibly related issue https://github.com/castleproject/Core/issues/651