locked
Problem with signing assembly during testing process RRS feed

  • Question

  • Hi!

    I have an assembly, that need to be signed with strong name. Ok, no problem, i have done it.

    Then, during testing process I need access to internal part of my assembly. I have added attribute [assembly: InternalsVisibleTo())] into my AssemblyInfo.cs with the name of the test project. So, the test project should be signed with strong name too, an I need to pass public key of the test project into InternalsVisibleTo attribute. No, problem, done. But, there is a problem: my test project uses the third party library, that don't signed with SN and i can't get signed version of it from the contributor.

    Could you, please, explain me, is there a right way to resolve this issue? I tried to use delay sign, but I still need to sign third party library (or not? maybe, I do something wrong). Thanks in advance.


    • Edited by serzubov Monday, October 13, 2014 8:24 AM
    Monday, October 13, 2014 7:36 AM

Answers

  • Hi Serzubov,

    If you have one strong-signed project in your solution, all the references must be strong-signed.

    The best way to resolve this issue is to contact the supplier of the third-party assembly and ask them to provide a version with a strong name. Generally 3rd party authors are quite good and will happily supply you with a signed assembly on request.

    If they can’t, I find some threads about how to sign third-party DLL with strong name. Hoping those explanations and detailed steps provided in them can help you:

    Nimit Patel provided a detailed solution in this thread: Assign strong name to third part DLL

    Step 1: Dis-assemble the assembly
            ildasm myTest.dll /out:myTest.il


    Step 2: Re-Assemble using your strong-name key
            ilasm myTest.il /res:myTest.res /dll /key:myTest.snk /out:myTestSN.dll

    This blog also provided detailed steps: How to Assign a Strong Name to an Unsigned 3rd-Party Assembly

    Some members in the following threads gave some ideas:

    Third party DLL does not have 'strong name'?

    signing assemblies with a strong name, ok, but what if some 3rd party DLL isn't signed?

    Signing an Unsigned Assembly

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by serzubov Thursday, October 23, 2014 5:30 AM
    Thursday, October 23, 2014 2:11 AM

All replies

  • Hi Serzubov,

    If the third-party library is referenced by your test project which is signed with strong name, you need sign strong name for the third-party library. Your can sign it using SN.exe. If the library can't be signed using SN.exe, because the library is third-party, I suggest consulting the third-party to check how to sign the library to make it work with Visual Studio.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 14, 2014 8:59 AM
  • Hi Crystal Zhu!

    Thanks for your answer! So if there is no way to sign 3rd party lib without contacting the contributor of library, could you please explain, how can i test my assembly without signing the test project?

    As i see, the right way is to use delay sign, built project,  then disable signing verification with sn -Vr MyProject.winmd. But compiler still says:

    "Friend assembly reference 'MyProjectTests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations".

    MyProjectTests references MyProject project (not output winmd-file). Maybe the problem is here?!

    Thank you!

    Wednesday, October 15, 2014 5:51 AM
  • Hi Serzubov,

    Since you delay sign the third-party library, and the third-party library is referenced and used by your test project, then you also need to use InternalsVisibleTo attribute with the name of the test project and the public key of the test project instead of public key token in the AssemblyInfo.cs of the third-party library in order to make the test project can access the third-party library.

    Reference Bassetassen’s answer in this thread with the same issue: http://stackoverflow.com/questions/11740229/c-sharp-unit-test-with-signed-assemblies

    Also this thread explained the same issue can help you:

    InternalsVisibleTo and PublicKey or PublicKeyToken

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Amanda Zhu Wednesday, October 15, 2014 9:45 AM edit
    Wednesday, October 15, 2014 9:43 AM
  • Hi Crystal Zhu,

    I can't modify third-party library, because I have only dll-files without source code. These libraries are referenced by my Test project.  

    When I sign my test assembly, the compiler said, that referenced assembly, let us say "ThirdPartyAssemblyName" does not have a strong name.

    Maybe, there is another way to test my assembly without signing Test Assembly? Actually, I do not want to test unsigned project (but now i see just this way to resolve my issue).

    Thanks, serzubov


    • Edited by serzubov Wednesday, October 15, 2014 11:27 AM
    Wednesday, October 15, 2014 11:26 AM
  • Hi Serzubov,

    If you don’t sign the test project, you may not make a test for the internal part of the project under test because the project under test is signed with strong name.

    I don’t find other ways to test your assembly without signing test project. In the current situation, please contact the contributor of the third-party library to check how to sign the library.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 16, 2014 2:48 AM
  • You could try to use the Humble Object parent to isolate your code from 3rd party dependencies. Here you can see an example: http://blogs.unity3d.com/2014/06/03/unit-testing-part-2-unit-testing-monobehaviours/

    Basically it consist in create a set of class to isolate your code from a hard to test dependency, like your scenario.

     Hope this diagram could help you:

    So in this way, you can mock the Humble object, and sign the test assembly without sign the 3rd party dll.

    Hope this helps!


    Try-Fail-Learn-Improve http://speakingin.net


    • Edited by JuanLao Friday, October 17, 2014 6:30 AM
    Friday, October 17, 2014 6:28 AM
  • Hi JuanLao,

    Thanks for your answer! 

    Such model doesn't resolve necessity to sign 3rd party libs, because these libs would be referenced by the Humble Object anyway. All referenced assembly should have strong names. 

    It is like a chain reaction: sign one, then you have to sign all referenced in the chain.

    Important update: 3rd party library is the mocking framework, so I need to use it during testing process

    Regards, serzubov


    • Edited by serzubov Monday, October 20, 2014 11:36 AM
    Monday, October 20, 2014 5:03 AM
  • Hi Serzubov,

    Whether the third-party library’s author/support can provide you some information?

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 21, 2014 1:45 AM
  • Umm.

    And what would happen if you put the Humble Object on a new dll that references the 3rd party dlls, and that is referenced from the test project?

    So the test project references the "HumbleLibrary", that is strong named. I don't know if it is the same scenario.

    If is the same scenario, and it is no critical to expose the internals elements as public ...

    Hope this helps!


    Try-Fail-Learn-Improve http://speakingin.net

    Tuesday, October 21, 2014 3:47 PM
  • Hi JuanLao!

    Are there any differences between using 3rd party mocking framework in testing project or in "HumbleLibrary"?

    I don't see any differences. This framework is still be referenced by the strongly named assembly ("HumbleLibrary" in your example), so it needs to be signed.

    I can not find any other way other than contacting the author.

    Actually, there is one known way to sign it explained here:

    http://ianpicknell.blogspot.com/2009/12/adding-strong-name-to-third-party.html

    but I don't think it is good enough. Maybe someone find it useful.

    Best regards. serzubov.

    Wednesday, October 22, 2014 5:12 AM
  • Hi Serzubov,

    If you have one strong-signed project in your solution, all the references must be strong-signed.

    The best way to resolve this issue is to contact the supplier of the third-party assembly and ask them to provide a version with a strong name. Generally 3rd party authors are quite good and will happily supply you with a signed assembly on request.

    If they can’t, I find some threads about how to sign third-party DLL with strong name. Hoping those explanations and detailed steps provided in them can help you:

    Nimit Patel provided a detailed solution in this thread: Assign strong name to third part DLL

    Step 1: Dis-assemble the assembly
            ildasm myTest.dll /out:myTest.il


    Step 2: Re-Assemble using your strong-name key
            ilasm myTest.il /res:myTest.res /dll /key:myTest.snk /out:myTestSN.dll

    This blog also provided detailed steps: How to Assign a Strong Name to an Unsigned 3rd-Party Assembly

    Some members in the following threads gave some ideas:

    Third party DLL does not have 'strong name'?

    signing assemblies with a strong name, ok, but what if some 3rd party DLL isn't signed?

    Signing an Unsigned Assembly

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by serzubov Thursday, October 23, 2014 5:30 AM
    Thursday, October 23, 2014 2:11 AM
  • Hi Crystal Zhu!

    Thanks for your effort in my issue! I really appreciate it! 

    I have already mentioned this way in my last comment. I can't use it due to strong license and IP policy. 

    Best wishes and nice job!

    serzubov

    Thursday, October 23, 2014 5:30 AM