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

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

Open
appel1 opened this issue Mar 21, 2023 · 2 comments
Labels
bug Reported problem with NSubstitute behaviour

Comments

@appel1
Copy link
Contributor

appel1 commented Mar 21, 2023

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
@GeraldLx
Copy link

GeraldLx commented Apr 3, 2023

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.

@appel1
Copy link
Contributor Author

appel1 commented Apr 3, 2023

Possibly related issue castleproject/Core#651

@304NotModified 304NotModified added the bug Reported problem with NSubstitute behaviour label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reported problem with NSubstitute behaviour
Projects
None yet
Development

No branches or pull requests

3 participants