Problem with Dynamic Assembly

215 views
Skip to first unread message

Chuck

unread,
Nov 13, 2009, 8:38:23 PM11/13/09
to Rhino.Mocks
First of all, I'm a Java guy, so I'm not familiar with this Dynamic
Assembly DLL thing. As such, I apologize in advance.

I've got a fairly good understanding of Rhino Mocks, but now I have a
a config issue I'm not sure how to deal with.

I'm using NUnit 2.5 and Visual Studio 2008. I've tried using
Rhino.Mocks 3.5 and Rhino.Mocks 3.5 for 2.0 as well.

Whenever I want to do anything interesting with the mocking framework,
I seem to be getting these weird error messages in a totally different
test.

Error Message:

1) Test Error :
Unit_Testing.Components.Utilities.TestXmlResourceAccessor.TestGetResourceAsString
System.NotSupportedException : The invoked member is not supported
in a dynamic assembly.
at System.Reflection.Emit.AssemblyBuilder.GetManifestResourceNames
()
at xxx.XmlResourceAccessor.GetResourceAsString(String resourceName)
in xxx\XmlResourceAccessor.cs:line xx
at
Unit_Testing.Components.Utilities.TestXmlResourceAccessor.TestGetResourceAsString
()



All are somewhat abbreviated (and obfuscated to protect the innocent)
below for things I believe to be irrelevant, but let me know if there
is something else you want to see.

...The test that causes the failure
[TestFixture]
public class TestChangePasswordCon
{

[Test]
public void TestNewPasswordsMatch()
{
MockRepository mocks = new MockRepository();

// Using this code causes error in the other test
ChangePasswordCon classUnderTest2 =
(ChangePasswordCon)mocks.CreateMock(typeof
(ChangePasswordCon));

ChangePasswordCon classUnderTest = new ChangePasswordCon
();
Assert.IsFalse(classUnderTest.NewPasswordsMatch("new",
"new"));

}
...
}


...The test that shows as the failure(TestXmlResourceAccessor) calls
this code: (blows up at the ***)

public static String GetResourceAsString(String resourceName)
{
Assembly assembly = Assembly.GetCallingAssembly()
foreach (String str in
***assembly.GetManifestResourceNames())***
{
.......

Tim Barcz

unread,
Nov 14, 2009, 7:29:11 AM11/14/09
to rhino...@googlegroups.com
Can you please post a complete sample code (test class and code under test) so that we can take a look at the whole.

I'm fairly certain I can help you, I just need a bit more to go on.
--
Tim Barcz
Microsoft C# MVP
Microsoft ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

Chuck

unread,
Nov 15, 2009, 10:45:38 PM11/15/09
to Rhino.Mocks
Unfortunately, due to security and NDA reasons, I cannot give the full
code. What I could do is create a contrived example to illustrate the
issue, but I really don't have time for that right now. I was kind of
hoping this was a known problem. It seems the assembly is getting
modifed by RhinoMocks in such a way as to break the call to:

Assembly assembly = Assembly.GetCallingAssembly()
foreach (String str in
***assembly.GetManifestResourceNames())***

What also bothers me about this is that this code is clearly not a
unit test, it's an integration test, but they're in the same VS
project so they currently run using the same assembly.

cb

Kenneth Xu

unread,
Nov 20, 2009, 11:37:38 AM11/20/09
to rhino...@googlegroups.com
Hi Chuck,

> Assembly assembly = Assembly.GetCallingAssembly()
>            foreach (String str in
> ***assembly.GetManifestResourceNames())***

Your code is trying to find all the resources from the calling
assembly. When a mock object calls this method, it will fail because
dynamic assembly, which all mocks reside in, doesn't support
resources.

Without knowing your intend I cannot say much but you can check if the
calling assembly is dynamic assembly, if yes then don't bother to call
GetManifestResourceNames as it won't have any resource anyway. Use:

If (assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)

HTH,
Kenneth

Chuck

unread,
Nov 24, 2009, 12:33:17 PM11/24/09
to Rhino.Mocks
Kenneth,

That does help quite a bit.

The intent of this line:
> ***assembly.GetManifestResourceNames())***

is to test the ability to read resources from the assembly. We have
another class that simply loads a text file from an assembly. In Java
the equivalent would be reading a resource/property file from a jar.

One possible solution would be to re-locate the test with that line of
code in it (not a true unit test anyway) to another assembly where
this kind of conflict would not happen, but still where the test could
be run anyway.

I was hoping there might be some other way to modify the assembly or
some setting (in RhinoMocks or elsewhere) so that the two tests could
co-habitate. Sounds like that might not be possible.

Thanks so much for your help.

cb
Reply all
Reply to author
Forward
0 new messages