.netunit-testingexceptiondynamic-assemblies

Assembly.GetManifestResourceNames() exception because of dynamic assembly


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.


Solution

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