Why does this line cause a VerificationException when running under .NET 4?

Viewed 3775

Help me out folks - why does this code cause a VerificationException when run under .NET 4.0?

public  T parseEnum<T>(string value, T defaultValue) {
  //Removing the following lines fixes the problem
  if (!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type");
  return defaultValue;
}

I ran peverify on the .net 2.0 assembly and got the following message:

ImageResizer.Util.Utils::parseEnum[T]][offset 0x0000000A] The 'this' parameter to the call must be the calling method's 'this' parameter.

This causes a VerificationException: Operation could destabilize the runtime message when running the code under medium trust.

I've already read all the similar-looking posts on stack overflow, and none of them apply to this code.

Is there something new with generics that would cause this code to be somehow invalid?

1 Answers
Related