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

MissingMethodException on virtual method with in parameter #988

Closed
grokys opened this issue Apr 1, 2020 · 3 comments
Closed

MissingMethodException on virtual method with in parameter #988

grokys opened this issue Apr 1, 2020 · 3 comments

Comments

@grokys
Copy link

grokys commented Apr 1, 2020

Repro (moq 4.13.1):

    public class Foo
    {
        public void Run()
        {
            Virtual(new Bar<int>());
        }

        public virtual void Virtual<T>(in Bar<T> bar)
        {
        }
    }

    public readonly struct Bar<T>
    {
        T Value { get; }
    }
var mock = new Mock<Foo>();
mock.Object.Run();

Throws exception:

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void ConsoleApp1.Foo.Virtual(ConsoleApp1.Bar`1<Int32> ByRef)'.
  Source=DynamicProxyGenAssembly2
  StackTrace:
   at Castle.Proxies.FooProxy.Virtual[T](Bar`1& bar)
   at ConsoleApp1.Foo.Run() in D:\temp\ConsoleApp1\ConsoleApp1\Program.cs:line 21
   at ConsoleApp1.Program.Main(String[] args) in D:\temp\ConsoleApp1\ConsoleApp1\Program.cs:line 13

Seems that the combination of a generic struct and an in parameter confuses moq somewhere.

@stakx
Copy link
Contributor

stakx commented Apr 3, 2020

I'm almost certain that this not caused by Moq, but by a long-standing bug in the runtime; see dotnet/runtime#25958.

@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

If there's any further news on this, I'll post them in #1148.

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

No branches or pull requests

2 participants