首页 > 解决方案 > 在这种情况下不可访问,因为它是朋友

问题描述

我从另一个 C# 项目中提取了一些代码并将其转换为 vb,但现在我得到了错误:

Is not accessible in this context because it is friend

Imports System.Security.Cryptography  

Public Shared Sub Sign()
  CryptoConfig.AddAlgorithm(GetType(RSAPKCS1SHA256SignatureDescription), "http://www.w3.org/2000/09/xmldsig-more#rsa-sha256")
End Sub

在此处输入图像描述

所需的命名空间System.Deployment.Internal.CodeSigning,但这个命名空间似乎没有RSAPKCS1SHA256SignatureDescription.

正在导入的命名空间是,System.Security.Cryptography但我开始认为这是从错误的库派生的。

Imports System.Security.Cryptography

Namespace System.Security.Cryptography
  Friend Class RSAPKCS1SHA256SignatureDescription
    Inherits RSAPKCS1SignatureDescription
    Public Sub New()
  End Class
End Namespace

任何人都可以提供对此错误消息的见解吗?

这个错误似乎并不代表微软所说的:

错误 ID:BC30389

https://docs.microsoft.com/en-us/dotnet/visual-basic/misc/bc30389


标签: asp.netvb.netwebformscryptographysaml

解决方案


请注意错误消息是如何指代的System.Security.Cryptography.RSAPKCS1SHA256SignatureDescription?那就是您的代码所引用的类,并且该类已声明Friend,因此您不能使用它。如果你想要这个System.Deployment.Internal.CodeSigning.RSAPKCS1SHA256SignatureDescription类,那么这就是你需要导入的命名空间。


命名空间首先需要添加到您的System.Deployment项目中才能引用Internal.CodeSigning库。

在此处输入图像描述


推荐阅读