如何找到特定dll的PublicKeyToken ?

时间:2021-01-30 07:09:22

I need to recreate a provider in my web.config file that looks something like this:

我需要在我的网络中重新创建一个提供程序。配置文件看起来像这样:

<membership defaultProvider="AspNetSqlMemProvider">
  <providers>
    <clear/>
    <add connectionStringName="TRAQDBConnectionString" applicationName="TRAQ" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0"
         name="AspNetSqlMemProvider"
         type="System.Web.Security.SqlMembershipProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"
    />
  </providers>
</membership>

However, I get a runtime error saying this assembly cannot be loaded, and I think it is because I have the wrong PublicKeyToken. How do I look up the PublicKeyToken for my assembly?

但是,我得到一个运行时错误,说这个程序集不能被加载,我认为这是因为我有错误的PublicKeyToken。我如何查找我的程序集的PublicKeyToken ?

Alternatively, am I going entirely the wrong way with this?

或者,我在这方面走错路了吗?

9 个解决方案

#1


146  

Using PowerShell, you can execute this statement:

使用PowerShell,您可以执行以下语句:

([system.reflection.assembly]::loadfile("c:\MyDLL.dll")).FullName

([system.reflection.assembly]::loadfile(c:\ MyDLL.dll)).FullName

The output will provide the Version, Culture and PublicKeyToken as shown below:

输出将提供版本、文化和PublicKeyToken,如下所示:

MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a

MyDLL、Version = 1.0.0.0、文化=中立,都必须= 669 e0ddf0bb1aa2a

#2


121  

Using sn.exe utility:

使用sn。exe实用程序:

sn -T YourAssembly.dll

or loading the assembly in Reflector.

或在反射器上装载组件。

#3


18  

sn -T <assembly> in Visual Studio command line. If an assembly is installed in the global assembly cache, it's easier to go to C:\Windows\assembly and find it in the list of GAC assemblies.

在Visual Studio命令行中,sn -T 。如果一个装配安装在全局程序集缓存,它更容易去C:\Windows\assembly广汽部件的列表中找到它。

On your specific case, you might be mixing type full name with assembly reference, you might want to take a look at MSDN.

在您的特定情况下,您可能会将类型全名与程序集引用混合,您可能想看一下MSDN。

#4


7  

If you have the DLL added to your project, you can open the csproj file and see the Reference tag.

如果将DLL添加到项目中,可以打开csproj文件并查看参考标签。

Example:

例子:

<Reference Include="System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

#5


4  

Answer is very simple use the .NET Framework tools sn.exe. So open the Visual Studio 2008 Command Prompt and then point to the dll’s folder you want to get the public key,

答案很简单,使用。net框架工具。打开Visual Studio 2008命令提示符然后指向dll文件夹你想要得到公钥,

Use the following command,

使用下面的命令,

sn –T myDLL.dll

This will give you the public key token. Remember one thing this only works if the assembly has to be strongly signed.

这将提供公钥标记。记住,只有当程序集必须被强签名时,这才会起作用。

Example

例子

C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T EdmGen.exe

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key token is b77a5c561934e089

#6


3  

I use Windows Explorer, navigate to C:\Windows\assembly , find the one I need. From the Properties you can copy the PublicKeyToken.

我使用Windows资源管理器,导航到C:\Windows\assembly,找到我所需要的。从属性中可以复制PublicKeyToken。

This doesn't rely on Visual Studio or any other utilities being installed.

这并不依赖于Visual Studio或正在安装的任何其他实用程序。

#7


1  

Just adding more info, I wasn't able to find sn.exe utility in the mentioned locations, in my case it was in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin

只是添加更多的信息,我找不到sn。exe实用程序中提到的地方,我的情况是在C:\Program Files (x86)\Microsoft sdk \ Windows \ v7.0A \ bin

#8


0  

You can also check by following method.

你也可以用下面的方法来检查。

Go to Run : type the path of DLL for which you need public key. You will find 2 files : 1. __AssemblyInfo_.ini 2. DLL file

运行:键入需要公钥的DLL的路径。您将找到两个文件:1。__AssemblyInfo_。ini 2。DLL文件

Open this __AssemblyInfo_.ini file in notepad , here you can see Public Key Token.

打开这个__AssemblyInfo_。ini文件在记事本中,这里您可以看到公钥标记。

#9


0  

Assembly.LoadFile(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\system.data.dll").FullName

Assembly.LoadFile(@“C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ system.data.dll”).FullName

Will result in

将导致

System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

系统。数据、Version = 4.0.0.0文化=中立,都必须要

#1


146  

Using PowerShell, you can execute this statement:

使用PowerShell,您可以执行以下语句:

([system.reflection.assembly]::loadfile("c:\MyDLL.dll")).FullName

([system.reflection.assembly]::loadfile(c:\ MyDLL.dll)).FullName

The output will provide the Version, Culture and PublicKeyToken as shown below:

输出将提供版本、文化和PublicKeyToken,如下所示:

MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a

MyDLL、Version = 1.0.0.0、文化=中立,都必须= 669 e0ddf0bb1aa2a

#2


121  

Using sn.exe utility:

使用sn。exe实用程序:

sn -T YourAssembly.dll

or loading the assembly in Reflector.

或在反射器上装载组件。

#3


18  

sn -T <assembly> in Visual Studio command line. If an assembly is installed in the global assembly cache, it's easier to go to C:\Windows\assembly and find it in the list of GAC assemblies.

在Visual Studio命令行中,sn -T 。如果一个装配安装在全局程序集缓存,它更容易去C:\Windows\assembly广汽部件的列表中找到它。

On your specific case, you might be mixing type full name with assembly reference, you might want to take a look at MSDN.

在您的特定情况下,您可能会将类型全名与程序集引用混合,您可能想看一下MSDN。

#4


7  

If you have the DLL added to your project, you can open the csproj file and see the Reference tag.

如果将DLL添加到项目中,可以打开csproj文件并查看参考标签。

Example:

例子:

<Reference Include="System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

#5


4  

Answer is very simple use the .NET Framework tools sn.exe. So open the Visual Studio 2008 Command Prompt and then point to the dll’s folder you want to get the public key,

答案很简单,使用。net框架工具。打开Visual Studio 2008命令提示符然后指向dll文件夹你想要得到公钥,

Use the following command,

使用下面的命令,

sn –T myDLL.dll

This will give you the public key token. Remember one thing this only works if the assembly has to be strongly signed.

这将提供公钥标记。记住,只有当程序集必须被强签名时,这才会起作用。

Example

例子

C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T EdmGen.exe

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key token is b77a5c561934e089

#6


3  

I use Windows Explorer, navigate to C:\Windows\assembly , find the one I need. From the Properties you can copy the PublicKeyToken.

我使用Windows资源管理器,导航到C:\Windows\assembly,找到我所需要的。从属性中可以复制PublicKeyToken。

This doesn't rely on Visual Studio or any other utilities being installed.

这并不依赖于Visual Studio或正在安装的任何其他实用程序。

#7


1  

Just adding more info, I wasn't able to find sn.exe utility in the mentioned locations, in my case it was in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin

只是添加更多的信息,我找不到sn。exe实用程序中提到的地方,我的情况是在C:\Program Files (x86)\Microsoft sdk \ Windows \ v7.0A \ bin

#8


0  

You can also check by following method.

你也可以用下面的方法来检查。

Go to Run : type the path of DLL for which you need public key. You will find 2 files : 1. __AssemblyInfo_.ini 2. DLL file

运行:键入需要公钥的DLL的路径。您将找到两个文件:1。__AssemblyInfo_。ini 2。DLL文件

Open this __AssemblyInfo_.ini file in notepad , here you can see Public Key Token.

打开这个__AssemblyInfo_。ini文件在记事本中,这里您可以看到公钥标记。

#9


0  

Assembly.LoadFile(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\system.data.dll").FullName

Assembly.LoadFile(@“C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ system.data.dll”).FullName

Will result in

将导致

System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

系统。数据、Version = 4.0.0.0文化=中立,都必须要