How do I find the PublicKeyToken for a particular

2019-01-21 00:28发布

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?

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

10条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-21 00:31

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

查看更多
beautiful°
3楼-- · 2019-01-21 00:32

Using sn.exe utility:

sn -T YourAssembly.dll

or loading the assembly in Reflector.

查看更多
Juvenile、少年°
4楼-- · 2019-01-21 00:36

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

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

查看更多
不美不萌又怎样
5楼-- · 2019-01-21 00:40

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

Example:

<Reference Include="System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
查看更多
戒情不戒烟
6楼-- · 2019-01-21 00:43

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

查看更多
Deceive 欺骗
7楼-- · 2019-01-21 00:45

Using PowerShell, you can execute this statement:

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

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

MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
查看更多
登录 后发表回答