简体   繁体   English

在Windows 8 RTM上的.NET应用程序中嵌入Powershell v2.0

[英]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:

  • Windows XP SP2 / Vista / 2003 / 2008 - PowerShell v1.0 Windows XP SP2 / Vista / 2003/2008 - PowerShell v1.0
  • Windows XP SP3 / Vista SP1 / 7 / 2003 SP2 / 2008 R2 - PowerShell v2.0 Windows XP SP3 / Vista SP1 / 7/2003 SP2 / 2008 R2 - PowerShell v2.0
  • Windows 7 SP1 / 8 / 2008 SP1 / 2008 R2 SP1 / 2012 - PowerShell v3.0 Windows 7 SP1 / 8/2008 SP1 / 2008 R2 SP1 / 2012 - PowerShell v3.0
  • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v4.0 Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012/2012 R2 - PowerShell v4.0
  • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v5.0 (as part of Windows Management Framework (WMF) 5.0) Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012/2012 R2 - PowerShell v5.0(作为Windows Management Framework(WMF)5.0的一部分)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是ASP .NET Apps v2.0 *的WMI类? - What is the WMI class for ASP .NET Apps v2.0*? OAuth v2.0与ASP.NET MVC 4 Web API结合使用 - OAuth v2.0 in combination with ASP.NET MVC 4 Web API 从.Net v4.0程序集链接到.Net v2.0程序集也似乎链接(和别名)mscorlib v2.0。 为什么? - Linking to a .Net v2.0 assembly from a .Net v4.0 assembly also appears to link (and alias) mscorlib v2.0. Why? kinect v2.0面部识别(wpf)c# - kinect v2.0 facial recognition (wpf) c# 使用运行时4.0的v2.0目录中的程序集 - Assemblies in v2.0 directory which using runtime 4.0 使用&#39;.NETFramework,Version = v4.6.1&#39;而不是项目目标框架&#39;.NETCoreApp,Version = v2.0&#39;恢复了软件包&#39;Faker.Net 1.0.3&#39; - Package 'Faker.Net 1.0.3' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0' 将 Power BI 嵌入 Windows Forms 应用程序(.NET Framework) - Embedding Power BI into Windows Forms App (.NET Framework) 如果仅存在.NET 2.0 RTM,运行时如何解析对.NET 2.0 SP1程序集的调用 - How does runtime resolve calls to .NET 2.0 SP1 assemblies if only .NET 2.0 RTM is present Windows Server 2008 R2上的.NET Framework 4 RTM - .NET Framework 4 RTM on Windows server 2008 R2 如何说服sql server 2008r2使用clr v4.0而不是v2.0? - How to convince sql server 2008r2 to use clr v4.0 instead of v2.0?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM