27

I have a website that uses AjaxControlToolkit.dll and Log4Net.dll.

When I try to run the performance profiling tool in VS 2010 on it it gives me the following warning:

AjaxControlToolkit.dll is signed and instrumenting it will invalidate its signature. If you proceed without a post-instrument event to re-sign the binary it may not load correctly.

Now, if I choose the option to continue without re-signing, the profiling starts but the assembly doesn't load and gives an ASP.NET exception.

Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
Storm
  • 4,307
  • 11
  • 40
  • 57
  • Note that the [PathofDLL] (per Vince & ghusse answers) will be located in the obj project folder, not the bin folder. – Mark Oct 07 '10 at 08:54

6 Answers6

21

If you're doing this on a development machine, you can disable strong name verification altogether with sn -Vr *. If you do this, you don't have to resign anything. This approach can be a security risk, but if you are comfortable with it, it's easier than resigning.

Specifically, from MSDN, it says:

Registers assembly for verification skipping. Optionally, you can specify a comma-separated list of user names. If you specify infile, verification remains enabled, but the public key in infile is used in verification operations. Assembly can be specified in the form *, strongname to register all assemblies with the specified strong name. Strongname should be specified as the string of hexadecimal digits representing the tokenized form of the public key. See the -t and -T options to display the public key token.

And the security risk:

Caution: Use this option only during development. Adding an assembly to the skip verification list creates a security vulnerability. A malicious assembly could use the fully specified assembly name (assembly name, version, culture, and public key token) of the assembly added to the skip verification list to fake its identity. This would allow the malicious assembly to also skip verification.

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
  • 7
    .. and one must not forget the opposite: `sn -Vu *` (This is to re-enable verification with this method) – Sean Aitken Nov 17 '11 at 21:10
  • 2
    `sn -Vx` also re-enables verification of all assemblies. To quote the docs: "Removes all verification-skipping entries.". –  Mar 09 '12 at 21:39
  • 1
    For profiling into 3rd party assemblies, where I do not have the signing key, this proved to be the only solution I could get working – Blake Mitchell May 08 '14 at 23:46
  • 1
    So ... sn -Vu * or sn -Vx?? :) – Ignacio Soler Garcia Nov 24 '14 at 16:00
  • I did that, but the "is signed and instrumenting it will invalidate its signature" dialog still pops up and I cannot profile. What else am I missing? A Visual Studio restart did not help. – Evgeniy Berezovsky Jun 12 '15 at 06:59
  • Click "Yes" and you'll be able to proceed with the analysis. – vrxacs Jul 14 '15 at 17:53
  • 1
    Much faster than adding post-instrumentation events, you don't have to remember to add/remove entries, and it can be easily undone using the Vx command. – jbeanky Aug 31 '15 at 16:19
  • On VS 2019, I had to make sure to use the 32-bit version of `sn.exe` in order for it to work. Not sure if the x64 version would work for x64 iisexpress. – Vinicius Apr 29 '20 at 19:33
17

ghusse linked to a blog post giving the answer. The answer is described there. As he points out, you have to use a post-instrument event on each signed assembly.

It's easiest to call sn.exe directly:

"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\sn.exe" -R [pathOfDll] [pathOfSNK]

Note that [pathOfDll] is located in the directory obj\Debug associated to the project.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Vince
  • 1,036
  • 1
  • 10
  • 17
  • what is this answer? where should it be called? – serhio Jun 09 '11 at 15:19
  • The answer is the link given by ghusse: http://blogs.msdn.com/b/ianhu/archive/2005/07/25/443021.aspx. – Vince Jun 21 '11 at 08:43
  • 1
    This seems to have gotten me past the initial problems, unfortunately I'm running into issues getting the web server to launch after that. I will note too though that implementing this event for each assembly is a pain when you have 30+ assemblies like we do in our project. – jpierson Sep 21 '12 at 14:40
  • sn.exe may be located on different location. For example in my case, it was located at `"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\sn.exe"`. So search for sn.exe in Windows drive if you don't find it – Abdul Rauf Dec 08 '15 at 10:47
7

The answer is described here. You have to use a post-instrument event on each signed assembly.

I could not manage to make it work "as is" with my installation of VS 2010. I had to call this command line as a post-build event on each dll :

"C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"   & sn -Ra [pathOfDll] [pathOfSNK]

Note that [pathOfDll] is located in the directory obj\Debug associated to the project.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
ghusse
  • 3,200
  • 2
  • 22
  • 30
5

The easiest way to get instrumentation work on signed binaries, which have not been re-signed, is to disable signature checks altogether. This is a machine wide setting that you can activate by registering an exception for the * pattern:

sn.exe -Vr *

This command must be executed from an elevated command prompt. You will find sn.exe in the SDK (in my case, I found it in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin).

When you are finished with testing, you should unregister the exception:

sn.exe -Vu *

or else your machine could be vulnerable to malicious code, since assemblies will be trusted even if they have been tampered with.

See also Access denied running sn.exe on Windows 7.

Community
  • 1
  • 1
Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
1

The profiler probably changes the assembly and because it was previously signed. Apparently you need to add a post-instrument action that re-signs the assembly.

This could be a problem because you do not have the sn file that was used to sign the 3rd party assemblies.

Dror Helper
  • 30,292
  • 15
  • 80
  • 129
0

Might have taken the lazy learning-new-things-free way out here, but I ended up solving this by writing a powershell script to unsign all the projects in my solution -- worked just fine. As part of the script, I save the original csproj files so I can revert them after. (you could also just undo changes in source control).

http://pastebin.com/UbABvz7d

should be able to revert by calling it passing the -revert switch.

Joshua Evensen
  • 1,544
  • 1
  • 15
  • 33
  • Due note that this might not be an option for all with a similar problem. CodeAnalysis rule [Code Analysis rule CA2240](https://msdn.microsoft.com/en-us/library/ms182127.aspx) can give compile errors, and using the [InternalsVisibleTo attribute](https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute%28v=vs.110%29.aspx) will also fail with this approach. – Johny Skovdal Jun 02 '15 at 05:17