Compiler Error CS1726

友元程序集引用“reference”无效。强名称签名的程序集必须在其 InternalsVisibleTo 声明中指定一个公钥。

强名称签名的程序集只能将使用 InternalsVisibleToAttribute 创建的友元程序集访问权限授予其他强签名的程序集。

若要解决 CS1726,请对要授予其友元访问权限的程序集进行签名(赋予其强名称),或不授予友元访问权限。

有关更多信息,请参见友元程序集(C# 和 Visual Basic)

下面的示例生成 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 { }

请参阅

如何:创建签名的友元程序集(C# 和 Visual Basic)