Loading a .NET 4.0 beta2 assembly in PowerShell 2.0

3

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

PS C:\Windows\system32> [Reflection.Assembly]::LoadFile("C:\Windows\Microsoft.NET\Framework\v4.0.21006\WPF\PresentationF 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:\Windows\Microsoft.NET\Framework\v4.0.21006\WPF\PresentationFramework.dll") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

How can I load this DLL file within PowerShell 2.0?

powershell-2.0
asked on Stack Overflow Dec 21, 2009 by ravikanth • edited Sep 1, 2013 by Peter Mortensen

3 Answers

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.

answered on Stack Overflow Dec 21, 2009 by Sander Rijken • edited Sep 1, 2013 by Peter Mortensen
0

Run this code in the administrative mode of PowerShell:

reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
answered on Stack Overflow Jun 11, 2014 by felix Antony • edited Jul 23, 2014 by Peter Mortensen
0

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

answered on Stack Overflow Feb 20, 2016 by expirat001

User contributions licensed under CC BY-SA 3.0