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

Mocking a method with "in" parameter of generic type #1136

Closed
kaminova opened this issue Jan 28, 2021 · 3 comments
Closed

Mocking a method with "in" parameter of generic type #1136

kaminova opened this issue Jan 28, 2021 · 3 comments

Comments

@kaminova
Copy link

Hello

I'm trying to mock a method with "in" parameter of generic type.
Repro:

    public readonly struct MyStruct
    {
        public int F1 { get; }
    }
    public interface ITester
    {
        void Method<T>(in T value) where T : struct;
    } 
	
    var mock = new Mock<ITester>();
    mock.Setup(m => m.Method(It.Ref<MyStruct>.IsAny));
	
    var t = new MyStruct();
    mock.Object.Method(in t);  //exception here

I got an exception:

`System.MissingMethodException : Method not found: 'Void Project1.Tests.ITester.Method(Project1.Tests.MyStruct ByRef)'.`

Am i missing something? (i use moq4.14.7)

@stakx
Copy link
Contributor

stakx commented Jan 28, 2021

Duplicate of #1104 and #988. I'm going to leave this one open because it recently occurred to me in castleproject/Core#430 (comment) that a partial workaround may be possible. If so, we need to wait for a fix in DynamicProxy & then update.

@stakx
Copy link
Contributor

stakx commented Mar 7, 2021

Small update: It appears that updating to .NET 6 (once released) will take care of this problem. The issue described above is no longer reproducible on .NET 6 Preview.

@stakx
Copy link
Contributor

stakx commented Mar 15, 2021

I am closing this issue as explained in #1148.

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