Powershell 2.0 Remoting loading a .Net 4.0 dll

喜你入骨 提交于 2019-12-07 01:13:40

问题


I am trying to load a .Net 4.0 assembly, using [Reflection.Assembly]::LoadFrom, inside of a remote Powershell 2.0 session. It works locally, due to a change I made to the powershell.exe.config file, but fails with a "This assembly is built by a runtime newer ..." exception in a remote session.

Both machines involved have .Net 2.0 and 4.0, and have the powershell.exe.config change for the x86 and x64 bit powershell executables. I've also tried changing the server powershell registry keys: HKLM:\Software\Microsoft\Powershell\1\PowerShellEngine\RuntimeVersion HKLM:\Software\Wow6432Node\Microsoft\Powershell\1\PowerShellEngine\RuntimeVersion

I must be missing something, but I don't know what it is.

Edit: Following is an example of the code I am executing.

PS C:\>Enter-PSSession -ComputerName server1
[server1]: PS C:\stuff> dir *.dll | foreach { [Reflection.Assembly]::LoadFrom( $_.FullName ) }

回答1:


The solution is to create a c:\windows\System32\wsmprovhost.exe.config file and a c:\windows\SysWOW64\wsmprovhost.exe.config file, on the server, similar to the one I found at: http://poshcode.com/2045

<?xml version="1.0" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0" />
  </startup>
</configuration>

I found the following article, which hinted at wsmprovhost.exe needing to be configured just like the powershell.exe file. http://tfl09.blogspot.com/2010/08/using-later-versions-of-net-framework.html



来源:https://stackoverflow.com/questions/4631710/powershell-2-0-remoting-loading-a-net-4-0-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!