[英]Embedding Powershell v2.0 in .NET app on Windows 8 RTM
Im getting the following error when trying to run hosted powershell scripts before upgrading from Windows 7 I never got this error. 我在尝试从Windows 7升级之前运行托管的PowerShell脚本时遇到以下错误我从未遇到此错误。
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\types.ps1xml(2977) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
加载扩展类型数据文件时出现以下错误:Microsoft.PowerShell.Core,C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ types.ps1xml(2977):类型“System.Security.AccessControl.ObjectSecurity”出错:异常:getter方法应该是public,non void,static,并且有一个PSObject类型的参数。 Microsoft.PowerShell.Core, C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\types.ps1xml(2984) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
Microsoft.PowerShell.Core,C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ types.ps1xml(2984):类型“System.Security.AccessControl.ObjectSecurity”出错:异常:getter方法应该是public,non void ,static,并且有一个PSObject类型的参数。 Microsoft.PowerShell.Core, C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\types.ps1xml(2991) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
Microsoft.PowerShell.Core,C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ types.ps1xml(2991):类型“System.Security.AccessControl.ObjectSecurity”出错:异常:getter方法应该是公共的,非void ,static,并且有一个PSObject类型的参数。 Microsoft.PowerShell.Core, C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\types.ps1xml(2998) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
Microsoft.PowerShell.Core,C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ types.ps1xml(2998):类型“System.Security.AccessControl.ObjectSecurity”出错:异常:getter方法应该是public,non void ,static,并且有一个PSObject类型的参数。 Microsoft.PowerShell.Core, C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\types.ps1xml(3005) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: The getter method should be public, non void, static, and have one parameter of type PSObject.
Microsoft.PowerShell.Core,C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ types.ps1xml(3005):类型“System.Security.AccessControl.ObjectSecurity”出错:异常:getter方法应该是public,非void ,static,并且有一个PSObject类型的参数。
I have applied the following in App.config: 我在App.config中应用了以下内容:
<dependentAssembly>
<assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
What could the issue be? 问题可能是什么?
The solution is to do the following, rather than only adding a block for only System.Management.Automation as suggested by the posts I read, you need to add one for all referenced PS assemblies. 解决方案是执行以下操作,而不是仅按照我读过的帖子的建议为System.Management.Automation添加块,您需要为所有引用的PS程序集添加一个块。
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I had the same problem in VS 2015 Update 3. 我在VS 2015 Update 3中遇到了同样的问题。
I must remove the folder: 我必须删除该文件夹:
%APPDATA%\Local\Microsoft\VisualStudio\
and then add into: 然后加入:
c:\Users\%username%\AppData\Local\Microsoft\VisualStudio\14.0\devenv.exe.config
in section: 在部分:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
the following lines: 以下几行:
<dependentAssembly>
<assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
<publisherPolicy apply="no" />
</dependentAssembly>
I lost two days searching for solutions... thanks MS :-/ 我失去了两天寻找解决方案......谢谢MS: - /
above answer did not work for me, i fixed the problem by removing the %APPDATA%..\\Local\\Microsoft\\VisualStudio\\ folder. 上面的答案对我不起作用,我通过删除%APPDATA%.. \\ Local \\ Microsoft \\ VisualStudio \\文件夹来解决问题。
Upon restarting VS this folder is recreated and the package manager console works again. 重新启动VS后,将重新创建此文件夹,并且包管理器控制台将再次运行。 A little crude but it does the job.
有点原油,但它做的工作。
After trying the solution in the accepted answer and getting tired of Visual Studio resetting the file, I reinstalled VS 2015 from scratch and haven't had the problem since. 在接受的答案中尝试解决方案并厌倦了Visual Studio重置文件之后,我从头开始重新安装VS 2015并且从那时起就没有问题了。 If you find the issue persists, the nuclear option is definitely worth a try.
如果你发现这个问题仍然存在,核选项绝对值得一试。
Install the appropriate version of PowerShell for your OS: 为您的操作系统安装适当版本的PowerShell:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.