访问模拟对象时未找到 moq 文件异常 system.xml
我收到此代码的文件未找到异常: (System.IO.FileNotFoundException:Die Datei oder Assembly“System.Xml,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e”或der eine Abhängigkeit davon wurde nicht gefunden。Das System kann die angegebene Datei nicht finden。)
public interface ISocket
{
int Receive(byte[] buffer);
}
[Test]
public void ShouldMock()
{
var Mock = new Mock<ISocket>();
ToBeTested Example = new ToBeTested ((ISocket)Mock.Object);
}
我可以没有找到我的错误,并且在任何情况下我都没有引用了system.xml。可能出了什么问题?
编辑:
我从未解决过这个问题,而且我仍然坚持手动模拟。我再次尝试建立一个使用起订量的项目,但再次失败。这是具有相同运行时错误消息的其他一些代码:
[Test]
public void shouldLoadContextBasedOn_Type_AfterGettingContextDictionary()
{
Type loadableType = typeof(Context_Empty);
var mocklib= new Mock<IDictionary<Type, Type>>();
mocklib.SetupGet(lib => lib[loadableType]).Returns(loadableType);
ContextLoader tested = new ContextLoader();
tested.setContextKnowledge(mocklib.Object);
tested.loadContext(loadableType);
IContextBase expected = new mockContext();
IContextBase actual = tested.getCurrentContext();
mocklib.VerifyGet( lib => lib[typeof(Context_Empty)]);
Assert.AreEqual(expected.ToString(), actual.ToString());
}
堆栈托盘显示 moq 在杀死自己之前正在寻找其源 - 是这样吗?它实际上只有在我将源安装在 d:\Code\moq\src\Source 下才有效吗?这似乎不对。 (编辑:amd 不是 - nunit 只是告诉我我找不到文件,所以与错误无关)
我有正确的包吗?我选择了 silverligth4,并且使用了我在其中找到的两个 dll - 其他的由于缺少某些内容而无法工作。
编辑:
为了更尖锐地说明问题。这是另一段失败的代码:
[Test]
public void mockDemo()
{
var crappy = new Mock<IDisposable>();
IDisposable instance = crappy.Object; //Runtime Error
}
这里是堆栈跟踪 - 手动重写,可能会发生打字错误
ContextLoader_Spec mockDemo()
Mock1 get_Object()
Mock1 OnGetObject()
Mock1 InitialiseInstance()
PexProtector Invoke()
Mock1 <InitializeInstance>b_32()
ProxyGenerator CreateInterfaceProxyWithoutTarget()
DefaultProxyBuilder CreateInterfaceProxyTypeWithoutTarget()
InterfaceProxyWithTargetGenerator GenerateCode()
InterfaceProxyWithoutTargetGenerator GenerateType()
InterfaceProxyWithTargetGenerator Init()
InterfaceProxyWithTargetGenerator CreateFields()
我不知道为什么会发生此异常。
编辑:这似乎是Silverlight4 的已知问题 编辑:用其他版本 NET35/NET40/NET40Castle/Silverlight4 重试 - 都显示相同的错误。
I am getting a file not found exception for this code:
(System.IO.FileNotFoundException : Die Datei oder Assembly "System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.)
public interface ISocket
{
int Receive(byte[] buffer);
}
[Test]
public void ShouldMock()
{
var Mock = new Mock<ISocket>();
ToBeTested Example = new ToBeTested ((ISocket)Mock.Object);
}
I can not find my error and in no case i ever referenced a system.xml. What could have gone wrong?
EDIT:
I did never solve this problem and i am still stuck with manual mocking. I tried once again to set up a project that uses moq but failed again. Here is some other code with the same runtime error message:
[Test]
public void shouldLoadContextBasedOn_Type_AfterGettingContextDictionary()
{
Type loadableType = typeof(Context_Empty);
var mocklib= new Mock<IDictionary<Type, Type>>();
mocklib.SetupGet(lib => lib[loadableType]).Returns(loadableType);
ContextLoader tested = new ContextLoader();
tested.setContextKnowledge(mocklib.Object);
tested.loadContext(loadableType);
IContextBase expected = new mockContext();
IContextBase actual = tested.getCurrentContext();
mocklib.VerifyGet( lib => lib[typeof(Context_Empty)]);
Assert.AreEqual(expected.ToString(), actual.ToString());
}
The stacktray shows that moq is looking for its source before killing itself - is that it? Does it actually only work if i have the source installed under d:\Code\moq\src\Source ? This does not seem rigth. (EDIT: amd it wasnt - nunit just informed me that i can not find the files, so nothing to do with the error)
Do i have the right package? I chose silverligth4 and i am using both dlls i found in there - the others did not work because something was missing.
EDIT:
To illustrate the problem even sharper. hiere is another failing piece of code:
[Test]
public void mockDemo()
{
var crappy = new Mock<IDisposable>();
IDisposable instance = crappy.Object; //Runtime Error
}
And here isthe stacktrace - manual rewritten, typingerror may occur
ContextLoader_Spec mockDemo()
Mock1 get_Object()
Mock1 OnGetObject()
Mock1 InitialiseInstance()
PexProtector Invoke()
Mock1 <InitializeInstance>b_32()
ProxyGenerator CreateInterfaceProxyWithoutTarget()
DefaultProxyBuilder CreateInterfaceProxyTypeWithoutTarget()
InterfaceProxyWithTargetGenerator GenerateCode()
InterfaceProxyWithoutTargetGenerator GenerateType()
InterfaceProxyWithTargetGenerator Init()
InterfaceProxyWithTargetGenerator CreateFields()
I dont know why this exception happens.
EDIT: This seems to be a known issue withSilverlight4
EDIT: Retried with the other versions NET35/NET40/NET40Castle/Silverlight4 - all show the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
切换到 Rhino 非常有魅力。
Rhino 可以单独下载或者位于 nunit 测试框架。
您所要做的就是将项目属性从 .Net 客户端配置文件切换到纯 .Net 配置文件,然后就可以开始了。
这是一个测试片段,可以帮助您控制是否已完成。
Switching to Rhino works like a charm.
Rhino can be downloadad seperately or is in the lib folder of your nunit testframework.
All you have to do is switch your project properties from the .Net Client profile to the pure .Net Profile and you are good to go.
Here is a Testsnippet that helps you control if you have done it.