4

If I run a unit test (mstest) I get an exception if 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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
habakuk
  • 2,712
  • 2
  • 28
  • 47

2 Answers2

2

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

habakuk
  • 2,712
  • 2
  • 28
  • 47
  • 1
    This helped me too, but it would be nice if someone could explain why the method needs to be static. – Vale May 16 '12 at 06:59
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.

Hugo Delsing
  • 13,803
  • 5
  • 45
  • 72