4

如果我运行单元测试(mstest),如果我调用assembly.GetManifestResourceNames()

动态程序集中不支持调用的成员。

这是有问题的代码:

Dim assembly As Assembly = Assembly.GetAssembly(Me.GetType())
Dim names = assembly.GetManifestResourceNames()

但是,如果我正确理解了文档,它应该可以工作,并且只有当我使用时,AssemblyBuilder.GetManifestResourceNames()我才会得到这个异常。

如果我尝试逐步浏览 .NET 源,我会收到以下消息:

mscorlib.dll!System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames() 没有可用的源

为什么会抛出这个异常?我错过了什么吗?

我忘了提到我mock.CallBase = True在测试中使用 Moq(带有选项)。

4

2 回答 2

2

我找到了一种解决方法:如果我将过程共享(在 c# 中是静态的),其中调用了“assembly.GetManifestResourceNames()”,它就可以工作。

于 2011-09-12T14:44:15.187 回答
0

I couldn't get it to work with just using static, but I did find another solution.

My Setup:

  1. MVC Project (website) (References 2)
  2. Logic Project (References 3)
  3. Content Library (only files)

My website called a method in the logic project, which tried to access the GetManifestResourceNames() from the content library. This resulted in the error.

I then removed the content reference from the logic project and added it directly to my website. No other changes and now it worked.

于 2016-06-23T18:45:53.997 回答