none
Error: "Friend assembly reference 'CTEco.UnitTests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations. RRS feed

  • Question

  • I'm setting up some unit tests to test the internals of an assembly. I have applied the [assembly:InternalsVisibleTo] attribute to the assembly under test to allow access from the unit test assembly. However when I compile I get the following message:

    error CS1726: Friend assembly reference 'CTEco.UnitTests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

    But neither of the assemblies are signed. Does anyone have any ideas?

    many thanks

    Richard Nagle




    rnagle
    Wednesday, September 24, 2008 9:16 AM

Answers

  • Sorry, my bad, should have posted the eventual solution.

    I discovered that there was some additional signing information in the .csproj file as well as the AssemblyInfo.cs. Once I removed this all was fine.

    Are you using NetTiers possibly? I found it was NetTiers putting the extra signing information into the csproj file.

    Hope this helps.

    Richard Nagle
    http://coding-for-a-living.blogspot.com/

    rnagle
    • Marked as answer by Richard Nagle Wednesday, May 20, 2009 12:51 PM
    Wednesday, May 20, 2009 12:51 PM

All replies

  • It's obvious, you'll need to sign them.  Use snk.exe
    Hans Passant.
    Wednesday, September 24, 2008 9:44 AM
    Moderator
  • OK. But I don't get why I need to sign them. I understand that if one is signed I need to sign the other. But in this case neither is signed.
    rnagle
    Wednesday, September 24, 2008 9:49 AM
  • Would you make your internals visible to anybody that hangs up a sign that says "I'm a doctor"?  The public key verifies identity of the assembly, the name is too easily spoofed.
    Hans Passant.
    Wednesday, September 24, 2008 10:06 AM
    Moderator
  • Sorry Hans, I think you missing the point here. The signing is optional - in usual circumstances the framework will allow an unsigned assembly to reference another unsigned assembly's internals using [InternalsVisibleTo] without specifying the public key. Try it, it works.

    However, in this instance it seems that the framework is mistakingly identifying one of the assemblies as signed.  I know neither is signed as I've run "sn -TP" against each assembly and it tells me as much.

    So, I guess, my question is "why is the framework reporting my assemblies as strongly named when they are not?"

    rnagle
    Wednesday, September 24, 2008 10:22 AM
  • I think you're misinterpreting the problem.  Relevant snippets from the MSDN library articles:

    InternalsVisibleToAttribute class:
    This attribute can only be applied to strong-named assemblies.

    Friend assemblies (C# Programming Guide):
    When compiling an assembly (assembly B) that will access internal types or internal members of another assembly (assembly A), you must explicitly specify the name of the output file (.exe or .dll) with the /out compiler option (see /out for more information). This is required because the compiler has not yet generated the name for the assembly it is building at the time it is binding to external references.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, September 29, 2008 7:39 AM
    • Unmarked as answer by Richard Nagle Wednesday, May 20, 2009 12:51 PM
    Wednesday, September 24, 2008 11:52 AM
    Moderator
  • I too have the same issue...both assemblies are "not signed", it builds perfectly fine in VS.2005 environment. But in the build machine, it fails with same error! Hey Richard, did u get the solution? any clues, anybody? I do not think above reply can be marked as an answer.
    Wednesday, May 20, 2009 10:50 AM
  • Sorry, my bad, should have posted the eventual solution.

    I discovered that there was some additional signing information in the .csproj file as well as the AssemblyInfo.cs. Once I removed this all was fine.

    Are you using NetTiers possibly? I found it was NetTiers putting the extra signing information into the csproj file.

    Hope this helps.

    Richard Nagle
    http://coding-for-a-living.blogspot.com/

    rnagle
    • Marked as answer by Richard Nagle Wednesday, May 20, 2009 12:51 PM
    Wednesday, May 20, 2009 12:51 PM