Loading a .NET 4.0 beta2 assembly in PowerShell 2.0

I tried loading PresentationFramework.dll from .NET 4.0 beta2 in PowerShell v2.0. But it fails with the following error.

PS C:Windowssystem32> [Reflection.Assembly]::LoadFile("C:WindowsMicrosoft.NETFrameworkv4.0.21006WPFPresentationF ramework.dll")

Exception calling "LoadFile" with "1" argument(s): "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. (Exception from HRESULT: 0x8013101B)" At line:1 char:32 + [Reflection.Assembly]::LoadFile <<<< ("C:WindowsMicrosoft.NETFrameworkv4.0.21006WPFPresentationFramework.dll") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

How can I load this DLL file within PowerShell 2.0?


You can't load it. PowerShell is using the .NET 2.0 CLR, and 4.0 DLL files cannot be loaded.

It might be possible to reconfigure PowerShell to run in the newer CLR or host PowerShell in a .NET 4.0 application, but I wouldn't recommend either of those.


在PowerShell的管理模式下运行此代码:

reg add hklmsoftwaremicrosoft.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklmsoftwarewow6432nodemicrosoft.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1

I had similar issue on Windows Server 2008 (with PowerShell v2) and I resolved by installing these 2 updates :

Microsoft .NET Framework 4.5.1 https://www.microsoft.com/fr-fr/download/details.aspx?id=40779

PowerShell v4 https://www.microsoft.com/en-US/download/details.aspx?id=40855

链接地址: http://www.djcxy.com/p/29038.html

上一篇: 如何在特殊的PowerShell链接命令4命令提示符?

下一篇: 在PowerShell 2.0中加载.NET 4.0 beta2程序集