NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Exception is thrown if method with an interpolated string handler argument on a mocked interface is called

Open appel1 opened this issue 1 year ago • 2 comments

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

appel1 avatar Mar 21 '23 12:03 appel1

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.

GeraldLx avatar Apr 03 '23 08:04 GeraldLx

Possibly related issue https://github.com/castleproject/Core/issues/651

appel1 avatar Apr 03 '23 19:04 appel1