0

I have an MVC web app that was running just fine on .NET framework 4.6.1. I had a need to change the target framework to 4.7.1 or later so I chose 4.7.2.

I simply changed the Target Framework dropdown under the project properties and updated web.config as follows. <compilation targetFramework="4.7.2" debug="true" />

I then ran Update-Package -Reinstall in Package Manager Console.

After doing so I now get the following runtime error:

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Source= StackTrace:

This error is thrown on the var client line below

public static string getConnectionString(string secretName)
{  
    string kvURL = "https://blah_blah.vault.azure.net/";

    var client = new SecretClient(new Uri(kvURL), new DefaultAzureCredential());
    KeyVaultSecret cs = client.GetSecret(secretName);

    return cs.Value;
}

I have verified the path under references does point to an actual System.Runtime.InteropServices.RuntimeInformation.dll file.

After everything I tried, I finally resorted to running devenv /ResetSkipPkgs from the command line. No change.

Can someone advise what may have gone wrong? Are there additional or different steps I should have taken to change to 4.7.2?

ASPed
  • 51
  • 8

1 Answers1

1

_System.IO.FileNotFoundException HResult=0x80070002 Message Could not load file or assemblySystem.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Your error clearly indicates that there are conflicting issues with the package versions.

  • As you have mentioned I have changed the Target Framework under the project properties and updated Web.config.

  • Make sure the Target Version is reflected in .csproj file.

  • Check whether you have the below settings.

In Web.config:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>

In packages.config:

  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net472" />

In .csproj file:

<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
  <Private>True</Private>
  <Private>True</Private>
</Reference>
  • My .csproj also got updated after running the Update-Package -Reinstall.

enter image description here

Code for getting Secret:

public async Task<ActionResult> Index()
{         
    var kvURL = "https://mykeyvault24Apr.vault.azure.net/";
    var credential = new DefaultAzureCredential();
    var client = new SecretClient(new Uri(kvURL), credential);
    var cs = await client.GetSecretAsync("Secret24April");

    ViewBag.cs = cs.Value.Value.ToString();
    return View();
}

Output of the Migrated 4.7.2 version:

enter image description here

enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9