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

Improperly throws System.TypeLoadException on mock when a record has a base record on dotnet 6 #1273

Closed
tgrieger-sf opened this issue Aug 1, 2022 · 5 comments · Fixed by #1275
Assignees
Milestone

Comments

@tgrieger-sf
Copy link

A System.TypeLoadException is incorrectly thrown on dotnet 6 when mocking a record with a base record. See simple repro below.

using System;
using Moq;

namespace Testing
{
	public record First : Base
	{
		public virtual string Something { get; init; }
	}

	public record Base {}

	class Program
	{
		static void Main(string[] args)
		{
			Mock<First> mockFirst = new();
			mockFirst.SetupGet(f => f.Something).Returns("string");
			Console.WriteLine(mockFirst.Object.Something);
		}
	}
}
@stakx
Copy link
Contributor

stakx commented Aug 1, 2022

The Entity Framework team noticed the same thing and reported it directly to the DynamicProxy project (upon which Moq 4 is built): castleproject/Core#601.

This has recently been fixed there, and it will be fixed in Moq once we can upgrade to the upcoming version of DynamicProxy.

@tgrieger-sf
Copy link
Author

Awesome, thanks for the update!

@tgrieger-sf
Copy link
Author

Thanks @stakx! 🚀

@stakx
Copy link
Contributor

stakx commented Aug 2, 2022

You're welcome @tgrieger-sf. FYI, I'm going to push a new release to NuGet shortly.

@stakx
Copy link
Contributor

stakx commented Aug 2, 2022

This is now fixed in Moq version 4.18.2, which has just been pushed to NuGet.

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

Successfully merging a pull request may close this issue.

2 participants