Open andrewimcclement opened 2 months ago
Have you set the <UseWindowsForms>true</UseWindowsForms>
when using .NET6/8 as documented?
Yes - see https://github.com/andrewimcclement/MoqInternalsVisibleToIssue/blob/cd273f348e2edf7ab301dfa452fece060c85bff8/Production/Production.csproj#L8 and https://github.com/andrewimcclement/MoqInternalsVisibleToIssue/blob/cd273f348e2edf7ab301dfa452fece060c85bff8/Production.Tests/Production.Tests.csproj#L8.
Describe the Bug
Given an internal class
DerivedControl
inheriting fromSystem.Windows.Forms.Control
, constructingnew Mock<DerivedControl>().Object
throwsArgumentException
, wrappingTypeLoadException
. I cannot reproduce this issue without usingSystem.WIndows.Forms.Control
.I am not certain if this is a bug in Castle.Core, but thought I would ask here first.
Steps to Reproduce
Full code with additional examples can be found at https://github.com/andrewimcclement/MoqInternalsVisibleToIssue.
This test (in
Production.Tests.csproj
) passes on .NET Framework 4.8 but fails on .NET 6.0 & .NET 8.0.Expected Behavior
Given this passes on .NET Framework 4.8, I would expect this to pass (or understand why System.Windows.Forms.Control is special
Exception with Stack Trace
.NET 8.0 stack trace: (.NET 6.0 stack trace is similar)
Note that InternalDerivedControl is a non-sealed, non-static class, so even if this behaviour is correct, the error message seems inaccurate. Also, looking at the source code of
System.Windows.Forms.Control
, I cannot see any relevant change tointernal virtual void NotifyValidationResult
Version Info
Moq 4.20.70 used (implicitly using Castle.Core 5.1.1).
Additional information
I hit this issue while trying to upgrade some test projects from .NET Framework to .NET 8.