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
Hi,

Since moving to VS2010 I seem to have gotten the "Unable to obtain public key for StrongNameKeyPair" error trying to mock and interface.

I am running VS2010, .Net 4.0, Typemock 6.0.3.0 MBUbit/Gallio. All are x64 flavour. I am running as Admin.

Code and call stack below. This happend to me last year too.

Yell if you need any other info.

Cheers
Bart

Code to repro.

using MbUnit.Framework;
using TypeMock.ArrangeActAssert;

namespace ClassLibrary1
{
[Isolated]
[TestFixture]
public class Class1
{
[Test] public void TestInterface() { var x = Isolate.Fake.Instance<IMyInterface>(); } // FAIL
[Test] public void TestClass() { var x = Isolate.Fake.Instance<MyClass>(); } // PASS
}

public interface IMyInterface { }
public class MyClass { }
}


This is the stack running the test.

TestInterface : Failed*** Failures ***
Execute
System.ArgumentException: Unable to obtain public key for StrongNameKeyPair.
at System.Reflection.StrongNameKeyPair.ComputePublicKey()
at System.Reflection.StrongNameKeyPair.get_PublicKey()
at System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource)
at System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource)
at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 assemblyAttributes, SecurityContextSource securityContextSource)
at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
at d9.b()
at d9.a(Type A_0, String A_1)
at d9.a(Type A_0, Object[] A_1)
at if.Instance[T](Members behavior)
at ClassLibrary1.Class1.TestInterface() in c:usersfibrichdocumentsisual studio 2010ProjectsClassLibrary1ClassLibrary1Class1.cs:line 17
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at ClassLibrary1.Class1.TestInterface() in c:usersfibrichdocumentsisual studio 2010ProjectsClassLibrary1ClassLibrary1Class1.cs:line 16

System.ArgumentException: Unable to obtain public key for StrongNameKeyPair.
at System.Reflection.StrongNameKeyPair.ComputePublicKey()
at System.Reflection.StrongNameKeyPair.get_PublicKey()
at System.Reflection.Emit.AssemblyBuilder..ctor(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource)
at System.Reflection.Emit.AssemblyBuilder.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable`1 unsafeAssemblyAttributes, SecurityContextSource securityContextSource)
at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable`1 assemblyAttributes, SecurityContextSource securityContextSource)
at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
at d9.b()
at d9.a(Type A_0, String A_1)
at d9.a(Type A_0, Object[] A_1)
at if.Instance(Members behavior)
at ClassLibrary1.Class1.TestInterface() in Class1.cs: line 17
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at ClassLibrary1.Class1.TestInterface() in Class1.cs: line 16
asked by bfibrich (1.2k points)

3 Answers

0 votes
Hello,

The case you are describing is interesting. Let's take this offline. We'll try to reproduce this locally and investigate this further. I will send you an email shortly from our support mailbox.

Igal
Typemock Support
answered by igal (5.7k points)
0 votes
Hi,

we receive the same identical error with our VS2010 + SP1 + Win7 on x64.
We are using latest Isolator 6 just downloaded from your site. We are running our VS2010 as administrators also.

Do you have any suggestion about how to solve this issue? If you need any information you can ask.
Thanks in advance

Livio
answered by Livio (140 points)
0 votes
Hi Livio,

Can you send us a solution reproducing this problem to support@typemock.com ?

--
Regards,
Yoel Schejter
Typemock Support
answered by yoel (1.9k points)
...