Alexander Anikin's blog

My personal blog

Posts Tagged ‘microsoft netframework

Using .Net Framework 4 in PowerShell

leave a comment »

I need use 4 in one of my projects. This because some strong differencies in working with WebRequest. The main thing – in version 3.5 WebRequest don’t want support NTLM authentication scheme.  May be it was my fault, but when i chaged version to 4 my code worked fine.

Project needs – use my code from PowerShell, but it gets me this:

Add-PSSnapin : Cannot load Windows PowerShell snap-in NTLMSnapIn because of the following error: Could not load file or  assembly ‘file:///C:\Users\aanikin\Documents\Visual Studio 2010\Projects\NTLMTest\NTLM.Powershell\bin\Debug\NTLM.Power shell.dll’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

This is not a big problem – solution :

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

But this was not the end – this experiments was on my SharePoint Server and this registry keys crashed it (CS1703 error about mscorlib, errro 500 in Central Administration). So OnlyUseLatestCLR key will crash SharePoint. Solution:

reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 0

reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 0

or just delete this key from Registry.

Advertisements

Written by Alex Anikin

January 24, 2012 at 1:36 pm