I am having this problem too.
I just installed version 6.0.7.0 about an hour again and I'm still getting this error.
So here's the rundown, we're using RIA System.ServiceModel.DomainServices dll.
The test I have isolating the issue works fine with the TypeMock dlls not included in the solution, but once I include them I get this error:
Error 1 Test 'GameFly.Enterprise.Retail.UnitTest.Validation.NastyGrossReflectionStuffTestFixture.TryValidate_ShouldNotThrowVerificationException' failed:
Test method GameFly.Enterprise.Retail.UnitTest.Validation.NastyGrossReflectionStuffTestFixture.TryValidate_ShouldNotThrowVerificationException threw exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.VerificationException: Operation could destabilize the runtime.
at System.ServiceModel.DomainServices.Server.MetaType.<>c__DisplayClass1..ctor()
at System.ServiceModel.DomainServices.Server.MetaType.GetMetaType(Type type)
at System.ServiceModel.DomainServices.Server.ValidationUtilities.TryValidateObjectRecursive(Object instance, String memberPath, ValidationContext validationContext, List`1 validationResults)
at System.ServiceModel.DomainServices.Server.ValidationUtilities.TryValidateObject(Object instance, ValidationContext validationContext, List`1 validationResults)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at GameFly.Enterprise.Retail.UnitTest.Validation.NastyGrossReflectionStuffTestFixture.TryValidate_ShouldNotThrowVerificationException()
Here's my code, I know I have some nasty reflection stuff going on, I'm sorry but I need this code and i don't want to have to write code that does the same thing as this. Besides BOO to microsoft for hiding these gems from me. So yes, this is nasty not very maintainable code but I'm doing it and TypeMock is not playing nice with it.
[TestClass]
public class NastyGrossReflectionStuffTestFixture {
/// <summary>
/// Please don't throw this error
/// </summary>
[TestMethod]
public void TryValidate_ShouldNotThrowVerificationException() {
var fBar = new FooBar
{
Name = "Captain FooBar!!!"
};
var context = new ValidationContext(fBar, null, null);
var assembly = typeof (DomainService).Assembly;
var type = assembly.GetType("System.ServiceModel.DomainServices.Server.ValidationUtilities");
var method = type.GetMethod("TryValidateObject", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
var result = (bool) method.Invoke(method.DeclaringType.Module, new object[] {fBar, context, new List<ValidationResult>()});
Assert.IsTrue(result);
}
public class FooBar {
[Required(ErrorMessage = "The parent name is required")]
public string Name {
get;
set;
}
}
}