Compiler Error CS1726

Switch View :
ScriptFree
Visual Studio 2010 - Visual C#
Compiler Error CS1726

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

A strong name signed assembly can only grant friend assembly access, made with the InternalsVisibleToAttribute, to other strongly signed assemblies.

To resolve CS1726, either sign (give a strong name to) the assembly to which you want to grant friend access, or don't grant friend access.

For more information, see Friend Assemblies (C# and Visual Basic).

Example

The following sample generates CS1726.


// Save this code as CS1726.cs

// Run the following command to create CS1726.key:
//      sn -k CS1726.key

// Then compile by using the following command: 
//      csc /keyfile:CS1726.key /target:library CS1726.cs


using System.Runtime.CompilerServices;

// The following line causes compiler error CS1726.
[assembly: InternalsVisibleTo("UnsignedAssembly")]   

// To get rid of the error, try the following line instead.
//[assembly: InternalsVisibleTo("SignedAssembly, PublicKey=0024000004800000940000000602000000240000525341310004000001000100031d7b6f3abc16c7de526fd67ec2926fe68ed2f9901afbc5f1b6b428bf6cd9086021a0b38b76bc340dc6ab27b65e4a593fa0e60689ac98dd71a12248ca025751d135df7b98c5f9d09172f7b62dabdd302b2a1ae688731ff3fc7a6ab9e8cf39fb73c60667e1b071ef7da5838dc009ae0119a9cbff2c581fc0f2d966b77114b2c4")]

class A { }
See Also

Tasks

Community Content

HeavyStorm
String, not parameter.
$0Notice that the PublicKey parameter is part of the string -- the first parameter -- of the InternalsVisibleTo. $0 $0$0 $0 Probably no one else did this mistake, but it took me five minutes to understand why there wasn't any "PublicKey" in the above attribute.

RE31686
CS1726 with unsigned assemblies
If AssemblyKeyFile or AssemblyKeyName are defined on an assembly, even if these are blank, the compiler will force you to specify a public key in the InternalsVisibleTo declaration.

To fix this simply remove the AssemblyKeyFile and AssemblyKeyName from your AssemblyInfo file.

Yop83
Getting the public key of an assembly
In order to get the public key of a strong name signed assembly, you can use sn in the following manner:
sn –Tp myAssembly.dll

sn is easily available in the Visual Studio 2010 Command prompt.