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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ravikanth
  • 24,922
  • 4
  • 60
  • 60

3 Answers3

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
felix Antony
  • 1,450
  • 14
  • 28
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

expirat001
  • 2,125
  • 4
  • 30
  • 40