Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation

22

I am getting this error whenever I try and run a webjob project with application insight and entity framework.

System.IO.FileLoadException: 'Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I have installed the following nuget packages

Microsoft.Azure.WebJobs.Logging.ApplicationInsights version 2.1.0-beta4

Microsoft.Extensions.Logging version 2.0.0

Microsoft.Extensions.Logging.Console version 2.0.0.

This all works with a new Visual studio 2017 webjob project, its when I try and include an existing code base, primarily using entity framework that I get this error. When I look at the reference in the one that works I don't have the System.Runtime.InteropServices.RuntimeInformation, yet it has been added to the project with entity framework. It seems to be part of .net standard, but how come I don't need .net standard for my new console app!

enter image description here

I'm not sure why its looking for Version 0.0.0.0 either as the one I have is 4.0.2.0

I have also tried adding this to the project file but this didn't work.

<PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
   <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Any help would be greatly appreciated

Many thanks

c#
azure
azure-application-insights
webjob
interopservices
asked on Stack Overflow Jan 30, 2018 by Andrew

3 Answers

36

Confirming the comment made above by dwilliss also worked for me. The solution was to get rid of:

<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 my case from the app.config, for a Windows Service.) My project has an indirect dependency to System.Runtime.InteropServices.RuntimeInformation only. It is a dependency of a NuGet package I imported.

answered on Stack Overflow Dec 2, 2018 by Adam
16

Could you be missing the loaded assembly from your configuration file? Ensure you have something similar to the following within your web.config. NuGet would normally do this but maybe it hasn't and it doesn't know what to load in

<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>
answered on Stack Overflow Jan 30, 2018 by Jono_2007
2

If you have updated a project's .NET runtime version from a version before 4.7.1 to 4.7.1 or later then uninstall the Nuget package, delete / comment out the App.config part if it remains, and re-add the reference from the framework. It is in the framework from 4.7.1 onward, before that you had to add a Nuget package.

[edit]... as per Michael's comment above that I upvoted before living memory.

answered on Stack Overflow Jun 30, 2020 by CAD bloke

User contributions licensed under CC BY-SA 3.0