Strong name validation failed for application

6

I made a c# application that uses C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll

I also copied the dll to my bin folder. It works fine, but if I copy the bin folder to another machine and run the executable I get this error:

************** Exception Text **************
System.IO.FileLoadException: Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)

Note: I'm not signing the assemblies at all. Also I do not want to disable security by modifying the registry keys. I just want to fix it properly. Any ideas how to fix this problem without globally registering the dll?

Updates: I tried copying the whole visual studio project over to the other machine. It's not working on windows 7 while it is working on windows 8.

c#
dll
asked on Stack Overflow Dec 1, 2014 by max • edited Dec 1, 2014 by max

3 Answers

4

You can remove the strong reference to the assembly in your app.confg by changing

System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

to

System.Management.Automation

But I would suggest getting more information about exactly what is wrong, using Fuslogvw (which can be copied onto your destination server, along with a support dll).

This will show you exactly where the application is probing for dll's and what is causing the issue. Maybe you have another dll you need to add to your bin folder, or maybe the GAC is winning out on another dll.

answered on Stack Overflow Dec 1, 2014 by bigtlb
1

I think the problem is that the way I did it works only on windows 8 since it has a newer version of this dll. To make it run on windows 7:

  • modified csproj file to have the reference like so:

< Reference Include="System.Management.Automation" />

  • changed the authentication code to this

    SecureString securePwd = new SecureString(); pass.ToCharArray().ToList().ForEach(p => securePwd.AppendChar(p)); PSCredential credentials = new PSCredential(username, securePwd); string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell"; WSManConnectionInfo connectionInfo = new WSManConnectionInfo(false, host, 5985, "/wsman", shellUri, credentials, 100000);// timeout is in miliseconds

answered on Stack Overflow Dec 1, 2014 by max
1

[Use this solution if you have problems during Testing binaries] I have the same problem as the author. I removed the strong name on the system.management.automation.dll using snremove.exe

snremove -r .\system.management.automation.dll (And remove strong name for all your binaries being used for testing.) http://www.nirsoft.net/dot_net_tools/strong_name_remove.html

It works well now. I do this only because I didnt want to check in my binaries before testing. Once checked in, my binaries are signed by the build and I dont have to worry about strong naming.

answered on Stack Overflow Feb 17, 2017 by AdmiralThrawn • edited Feb 17, 2017 by AdmiralThrawn

User contributions licensed under CC BY-SA 3.0