What steps will reproduce the problem?
1. Create a non-generic type
2. Add a generic method
3. Add an out or ref parameter of the generic argument type
What is the expected output? What do you see instead?
Expect to get a proxy, instead get an InvalidOperationException("Invalid
context") MethodDefinitionExtensions.AddParameters, line 102.
An out parameter of generic type shows up with the following notable
characteristics:
type.ContainsGenericParameters == true
type.IsGenericParameter == false
type.IsGenericType == false
type.IsGenericTypeDefinition == false
type.HasElementType == true
type.IsByRef == true
type.GetElementType() == typeof(T) (assuming T is the generic parameter type)
My suggestion:
Change line 99 from:
if ((type.ContainsGenericParameters && type.IsGenericType) ||
type.IsGenericParameter)
to:
if ((type.ContainsGenericParameters && type.IsGenericType) ||
type.IsGenericParameter || (type.HasElementType &&
type.GetElementType().IsGenericParameter))
That works for me, and I think should also deal with arrays of the generic
type and possibly other situations.
Original issue reported on code.google.com by fastcat@gmail.com on 21 Jul 2009 at 6:42
Original issue reported on code.google.com by
fastcat@gmail.com
on 21 Jul 2009 at 6:42