开发者

Assembly.GetManifestResourceNames() exception because of dynamic assembly

If I run a unit test (mstest) I get an exception i开发者_开发百科f I call assembly.GetManifestResourceNames():

The invoked member is not supported in a dynamic assembly.

This is the problematic code:

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

But if I understand the documentation right, it should work and only if I use AssemblyBuilder.GetManifestResourceNames() I should get this exception.

If I try to step through the .NET sources I get the message:

There is no source available for mscorlib.dll!System.Reflection.Emit.InternalAssemblyBuilder.GetManifestResourceNames()

Why does it throw this exception? Did I miss anything?

I forget to mention that I use Moq (with the option mock.CallBase = True) in the test.


I found a workaround: If I make the procedure shared (static in c#), where 'assembly.GetManifestResourceNames()' is called, it works.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜