locked
Compiler Error CS1726 - InternalsVisibleTo Attribute - Strong Name Not Accepted - Why? RRS feed

  • Question

  • This is what I've done:

    1. Signed my class DLL project by generating a .snk file from within Visual Studio
    2. Signed my unit test DLL project using the same .snk file
    3. Retrieved the public key from the sn tool with: "sn -T FullTexterTest.dll"
    4. Added the following InternalsVisibleToAttribute to the class DLL project file:
    [assembly: InternalsVisibleTo("FullTexterTest, PublicKeyToken=1234567890123456")]

    (* been using the correct public key, of course)

    .

    Now I can't compile, because I get the following error:

    Friend assembly reference 'FullTexterTest, PublicKeyToken=1234567890123456' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

    What's wrong?


    Still people out there alive using the keyboard?

    Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...


    • Edited by BetterToday Saturday, January 24, 2015 1:37 PM
    Saturday, January 24, 2015 1:36 PM

Answers

  • Hi BetterToday,

    Glad to see you again!:)

    Maybe you could use the "PublicKey" instead of "PublicKeyToken" like the following sample, test the result.

    [assembly:InternalsVisibleTo("FullTexterTest,PublicKey=...")]
     

    Reference:

    http://stackoverflow.com/questions/1123683/how-to-declare-a-friend-assembly

    http://blog.tylerholmes.com/2008/04/unit-tests-and-internalsvisibleto.html

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Jack


    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 BetterToday Monday, January 26, 2015 10:52 AM
    Monday, January 26, 2015 5:59 AM

All replies

  • Hi BetterToday,

    Glad to see you again!:)

    Maybe you could use the "PublicKey" instead of "PublicKeyToken" like the following sample, test the result.

    [assembly:InternalsVisibleTo("FullTexterTest,PublicKey=...")]
     

    Reference:

    http://stackoverflow.com/questions/1123683/how-to-declare-a-friend-assembly

    http://blog.tylerholmes.com/2008/04/unit-tests-and-internalsvisibleto.html

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

    Microsoft does not control these sites and has not tested any software or information found on these sites;

    Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Jack


    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 BetterToday Monday, January 26, 2015 10:52 AM
    Monday, January 26, 2015 5:59 AM
  • Gee, thanks, Jack, you saved my day again.

    Like one of the commenters in the stackoverflow blog said, I got distracted by a sample in MSDN showing a public key that very much resembled the public key token.

    And strange enough: As of today I can only find complete samples with the full public key therein. Tss..

    Thanks for enlightening me again!

    Cheers,
    Axel


    Still people out there alive using the keyboard?

    Working with SQL Server/Visual Studio/Office/Windows and their poor keyboard support they seem extinct...

    Monday, January 26, 2015 10:52 AM
  • You are welcome! Axel!

    Have a nice day,

    Jack


    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, January 27, 2015 1:25 AM