简体   繁体   中英

Issue with system.runtime DLL pointing to older version even after installing the latest version from NUGet package manager

I am currently working to integrate PowerShell script to my ASPX Web Forms and in this process, I am facing below issue which is holding me to move further as I could not even build the solution because of Reference Issues

a) Installed system.Management.automation from NuGet Package manager, however after installing I do not see the references added automatically so I have added this DLL manually from the Project location. Not sure if this will not make an issue, but assuming it should be added automatically

b) system.Management.automation 7.0 version DLL requires System.runtime Version=4.2.2.0, so I have installed System. runtime 4.3 stable version. But when I try to add the latest version it still points to the older 4.1.2.0 version and fails with below error

> Error CS1705  Assembly 'System.Management.Automation' with identity
> 'System.Management.Automation, Version=7.0.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35' uses 'System.Runtime,
> Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
> which has a higher version than referenced assembly 'System.Runtime'
> with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'  WebApplication16    C:\Users\****\source\repos\WebApplication16\WebApplication16\Default.aspx.cs    32  Active

Below are the things I have tried and none of them works

1) Created new project multiple times

2) has cleaned and rebuild the solution

3) Tried giving bindingRedirect in Web.config to make it use the latest version, no luck

4) Removed old version from References and tried to add a new system. runtime Version however it added the older version to the project

Could someone please suggest on this

You are using.Net Framework, not.Net Core, and I assume that's what is causing issue, which is very cryptic, as you can reference the DLL but can not use it.

You need to find older version of this library. Nuget won't do, as the earliest version there is 6.0.4, which is using System.Runtime 4.2.0.

Search for other, older versions on your computer, it's likely to be found in GAC folders. Once found, copy and reference it. Automation DLL version 4.x will likely work in your case.

I had this exact problem when working with.Net, and here is the easy solution:

  1. Open PowerShell and execute the following command

    Copy ([PSObject].Assembly.Location) C:\

That will place a copy of System.Management.Automation on your C: drive path. You can move that into your solution folder instead if you prefer.

  1. In your Visual Studio Project, right click References tree in the Solution Explorer tab, and click Add Reference

  2. Click Browse, and locate the.dll from step 1.

Rebuild, and you should be good to go!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM