1

Another year, another question about Moles. I've got an assembly with an internal sealed class that I'd like to mole in the test project that I use for unit tests.

According to the Moles documentation I should add an

[assembly: InternalsVisibleTo( "MyAssembly.Moles" )]

attribute so I can access the internal class from my test project. However, this unfortunately doesn't work as "MyAssembly" is strongly signed.

Therefore, following the documentation, I added the Public Key to the line above, resulting in

[assembly: InternalsVisibleTo( "MyAssembly.Moles, PublicKey=0123456..." )]

Unfortunately this now gives me the following error when compiling "MyAssembly":

Assembly reference 'MyMoles.Moles, PublicKey=0123456...' is invalid and cannot be resolved

The documentation says that "...the Moles framework always uses the same key to sign the assembly...", but as the compiler says, this does not work. I also checked the generated file "MyAssembly.Moles.dll" with Reflector to verify that I use the correct public key (which I do), so I am stuck as I don't really know what the problem is.

Any ideas?

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Gorgsenegger
  • 7,356
  • 4
  • 51
  • 89

1 Answers1

3

Be sure you are entering the PUBLIC KEY, and not the PUBLIC KEY TOKEN.

If that doesn't work, use the secutil, to get the public key. The verbose output will include the correct key value. This is the syntax you need to use:

C:\> secutil -hex -s MyAssemblyName.dll
Mike Christian
  • 1,526
  • 1
  • 15
  • 27
  • Sorry for my late reply, somehow the notification must have slipped through. When I run secutil I always get the error message "ERROR: Unable to load assembly "MyAssemblyName.dll"". I made sure that the name is correct by using the command prompt's command completion feature, and I also tried the assembly name with and without the ".dll" extension, unfortunately to no avail. I then tried to extract the public key from the .snk as described on http://msdn.microsoft.com/en-us/library/0tke9fxk(v=vs.80).aspx, but using that key I get "inaccessible due to its protection level..." error messages. – Gorgsenegger Jan 11 '12 at 08:09
  • 1
    Which operating system are you using? – Mike Christian Jan 11 '12 at 20:00
  • Windows 7 Entersprise SP1, 64 bit – Gorgsenegger Jan 12 '12 at 07:50
  • I'll see if I can reproduce this issue. I'm not sure what the problem or solution is, at this time. – Mike Christian Jan 14 '12 at 19:38
  • Thank you. Should I find a solution I will also post an update here. – Gorgsenegger Jan 17 '12 at 14:30