InvalidOperationException:动态操作只能在同源AppDomain中执行 [英] InvalidOperationException: Dynamic operations can only be performed in homogenous AppDomain
问题描述
我在使用moles和DLR同时引发此异常时遇到问题:InvalidOperationException:动态操作只能在同类AppDomain中执行
I have an issue when using moles and the DLR at the same time that causes this exception to be thrown: InvalidOperationException: Dynamic operations can only be performed in homogenous AppDomain 我猜它正在抛出,因为Moles测试主机不会创建一个同质的AppDomain。导致异常的代码可以在下面找到。 I guess it's throwing because the Moles test host doesn't create a homogenous AppDomain. The code that will cause the exception can be found below. 我似乎无法找到更多相关信息。我在这里更深入地发表了博客文章: 这篇关于InvalidOperationException:动态操作只能在同源AppDomain中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
using System.IO;
using System.IO.Moles;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public classFileWrapperTest
{
[TestMethod, HostType("Moles")]
publicvoid TestMethod1()
{
// arrange
var fileWrapper = new FileWrapper();
MFile.ExistsString = path => false;
// act
dynamic exists = fileWrapper.DoesExist(@"C:\temp\test.txt");
// assert
Assert.IsFalse(exists);
}
public classFileWrapper
{
public bool DoesExist(string path)
{
return File.Exists(path);
}
}
}
推荐答案
http://cameronfletcher.com/post/InvalidOperationException-Dynamic-operations-can-only-be-performed-in-homogenous-AppDomain.aspx