-
Notifications
You must be signed in to change notification settings - Fork 471
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
ArgumentException
: "Cannot create an instance of TEnum
because Type.ContainsGenericParameters
is true" caused by Enum
constraint on method out
parameter
#656
Comments
I should also have pointed out that this throws the same exception: var proxy = new Castle.DynamicProxy.ProxyGenerator().CreateInterfaceProxyWithoutTarget(typeof(ITestInterface1)); So I'm guessing this is a DynamicProxy issue -- either that or both Moq and I are calling the wrong method. |
This also affects classes: using System;
using Moq;
public class Program
{
public static void Main()
{
var mock1 = new Mock<TestClass1>();
var mock2 = new Mock<TestClass2>();
// Throws
var instance1 = mock1.Object;
// Does not throw
var instance2 = mock2.Object;
}
public class TestClass1
{
public virtual bool TestMethod<TEnum>(out TEnum? someValue)
where TEnum : Enum
{
someValue = default(TEnum?);
return false;
}
}
public class TestClass2
{
public virtual bool TestMethod<TEnum>(out TEnum? someValue)
{
someValue = default(TEnum?);
return false;
}
}
} Stack trace:
|
@abagonhishead, thanks for reporting, I'm going to take a look at it. |
Enum
constraint on method out
parameter causes ArgumentException
This is apparently caused by type checks inside |
Enum
constraint on method out
parameter causes ArgumentException
ArgumentException
: "Cannot create an instance of TEnum
because Type.ContainsGenericParameters
is true" caused by Enum
constraint on method out
parameter
ArgumentException
: "Cannot create an instance of TEnum
because Type.ContainsGenericParameters
is true" caused by Enum
constraint on method out
parameterArgumentException
: "Cannot create an instance of TEnum
because Type.ContainsGenericParameters
is true" caused by Enum
constraint on method out
parameter
Hi there,
I encountered this using Moq but, from what I could see in the stack trace, it appears to be an issue with Castle.DynamicProxy. Hopefully raising this here is the correct thing to do.
Let me know if I'm wrong and I can raise it with them instead!
I'm not familiar with DynamicProxy so hopefully it's easy enough to suss out.
This is on .NET 6, Moq version 4.20.69 which is using Castle.Core 5.1.1
Example reproduction using Moq on dotnetfiddle
Exception:
Stack trace:
The text was updated successfully, but these errors were encountered: