应用程序的强名称验证失败

max*_*max 5 c# dll

我创建了使用C:\ Program Files(x86)\ Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll的ac#应用程序

我还将dll复制到我的bin文件夹中.它工作正常,但如果我将bin文件夹复制到另一台机器并运行可执行文件我得到此错误:

************** 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)
Run Code Online (Sandbox Code Playgroud)

注意:我根本没有签署组件.此外,我不想通过修改注册表项来禁用安全性.我只是想妥善解决它.任何想法如何解决这个问题,而无需全局注册DLL?

更新:我尝试将整个visual studio项目复制到另一台机器上.当它在Windows 8上工作时,它不能在Windows 7上运行.

max*_*max 1

我认为问题是我的方法只适用于 Windows 8,因为它有这个 dll 的较新版本。要使其在 Windows 7 上运行:

修改 csproj 文件以具有如下引用:

< Reference Include="System.Management.Automation" />
Run Code Online (Sandbox Code Playgroud)

将验证码更改为:

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
Run Code Online (Sandbox Code Playgroud)