chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

Apologies if I have missed something obvious, but I have just jumped back into using TypeMocks after a break so not sure if it’s me or otherwise
I am trying to mock and interface and am getting a “Unable to obtain public key for StrongNameKeyPair.” Exception.

Test : Failed
*** Failures ***
System.ArgumentException: Unable to obtain public key for StrongNameKeyPair.
at System.Reflection.StrongNameKeyPair.nGetPublicKey(Boolean exported, Byte[] array, String container)
at System.Reflection.StrongNameKeyPair.get_PublicKey()
at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes)
at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
at dl.b()
at dl.a(Type A_0, String A_1)
at dl.a(Type A_0, Object[] A_1)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject[TMockedType](Constructor mockConstructors)
at dx.CreateFakeInstance[T](Members behavior, Constructor constructorFlag, Object[] ctorParams)
at dx.Instance[T](Members behavior)
at dx.Instance[T]()
at TestProject1.TestFixture1.Test() in X:DevelopmentTestsClassLibrary1TestProject1

I am using Windows 7 which I think is the issue because getting TypeMocks running has also been an issue with both file and registery permissions. Basically VS needs to run as administrator, which from memory it did not have to do before.

The code to repro is …

namespace TestProject1
public interface ICar { }

public class Car : ICar { }

public class TestFixture1
public void Test()
// :(
//var car = Isolate.Fake.Instance<ICar>();
//var car = (ICar)RecorderManager.CreateMockedObject(typeof(ICar));

// :)
//var car = Isolate.Fake.Instance<Car>();
//var car = (ICar)RecorderManager.CreateMockedObject(typeof(Car));

My Environment is : -
Windows 7 RC1 x64
VS 2008
TypeMock 5.3.0 x64
Also using, Gallio, Resharper

asked by bfibrich (1.2k points)

5 Answers

0 votes
Yes. Currently on Win 7 Visual Studio needs to run as an Administrator when using Typemock.
This is a known issue we are working to resolve in upcoming versions.
answered by royo (2k points)
0 votes
Hi Royo,

Thanks for that.

What about the Interface mocking not working? It that a Win7 issue also?
That does not work as Administrator or not.

answered by bfibrich (1.2k points)
0 votes
Hi Brat

Sorry, I couldn't reproduce the problem with the code you posted.
What version of Isolator are you using?
Are you signing the test Assembly?
answered by ohad (35.4k points)
0 votes
do you get the interface error with vs in admin mode?
answered by royo (2k points)
0 votes
Yes I get the error running as administrator, which is big issue. I can live with running as admin for a while.

I am not signing the assembly.

Also I do have VS2010 B1 installed.
Windows 7 is a plain out of the box install.
Addins installed Resharper, CodeRush, Postsharp (currently uninstalled), Gallio, GhostDoc, CodeSpell

I have sent the full Solution to the support email.

answered by bfibrich (1.2k points)