Cannot load file or assembly 'System.Runtime'

Dmitriy Reznik 236 Reputation points
2022-06-24T10:24:16.31+00:00

I have an Asp.Net 4.7 WebForms legacy application written in vb.net. To add Azure B2C authentication, I add OWIN middleware NuGet packages like this:

Install-Package Microsoft.Owin.Security.OpenIdConnect
Install-Package Microsoft.Owin.Security.Cookies
Install-Package Microsoft.Owin.Host.SystemWeb

based on this tutorial: https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-asp-webapp

When I try to run the application, I get this error:

Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Here is the log:

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable C:\Program Files\IIS Express\iisexpress.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...
(Fully-specified)
LOG: Appbase = file:///C:/Git Repos/InfoWeb/
LOG: Initial PrivatePath = C:\Git Repos\InfoWeb\bin

Calling assembly : System.Net.Http.Primitives, Version=4.2.29.0, Culture=neutral, PublicKeyToken=....

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Git Repos\InfoWeb\web.config
LOG: Using host configuration file: C:\Users\dreznik\OneDrive - MyCompany\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=...
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/vs/17153f21/a2ffde83/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/vs/17153f21/a2ffde83/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Git Repos/InfoWeb/bin/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Git Repos/InfoWeb/bin/System.Runtime/System.Runtime.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/vs/17153f21/a2ffde83/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/vs/17153f21/a2ffde83/System.Runtime/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Git Repos/InfoWeb/bin/System.Runtime.EXE.
LOG: Attempting download of new URL file:///C:/Git Repos/InfoWeb/bin/System.Runtime/System.Runtime.EXE.

How can this be resolved? I have already tried to delete temporary Asp.Net files.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,473 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shweta Mathur 27,616 Reputation points Microsoft Employee
    2022-06-30T07:48:17.397+00:00

    Hi @Dmitriy Reznik ,

    Thanks for reaching out.

    This issue happens when nuget package references are brought in as dependencies and are not able to match the version of .NET project.

    Did you check the versions in web.config or app.config files? Removing the assembly binding redirects and making the version sync with standard libraries most of the time resolve this issue.

    Thanks,
    Shweta

    2 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. GEMWare 1 Reputation point
    2022-10-04T02:11:34.237+00:00

    Hi,

    Is there more of an specific file and/or location for where I would be able try and remove the <bindingRedirect> tag(s) in hopes to try and resolve my vary exact same issue that I'm currently having?

    I'm trying to make use of the System.Managment namespace with it's class object(s). But I keep getting the exact same error message, and that it's not making none of any since too me at all. I've added the "System.Managment.DLL". reference(s) to my project(s) like any other .Net namespace extensions and my project(s) dose build's without any problem(s) at all. But my API(s) crashes at the vary statement(s) that make's the class object(s) calls like within a Button.Click() event.

    I'm using VS2022 while developing both API APP(s) and .DLL(s) in Visual Basic and WPF while using ether .Net Core 6.0 and .Net Framework 4.8 depending on the project type that I'm working on before that I start rewriting my source file(s) in C# if not C++ for backwards compatibility when and wherever needed. Plus that I'm hoping that this solution would be an fix for all .Net based project type(s) and version.

    Thank you for your time...

    ----------

    Update:

    I've been doing some of my own testing while waiting for a reply and most of my problem seems to be with my .Net Core API's while trying to use .Net Framework control(s) even in my .Net Framework DLL rappers so that I can use the vary same Framework object(s) that is missing in the .Net Core.

    A lot of my control(s) has been quite universal for all kinds of .Net project for using the "Write Once, Use Lot's" method. But for some unknown reason that the System.Management extended object(s) dose not seem to work in the .Net Core project(s) without getting this "DLL Is Missing" error.

    I am still doing testing with the "System.Management.DLL" just in case that the DLL it self has not been updated to work with the .Net Core project(s). And if that is the case, then I'll be making an separate thread.

    0 comments No comments

  2. DHARMARAJAN Jayamanickam 0 Reputation points
    2024-04-12T08:36:32.6033333+00:00

    I'm facing same issue. But after i removed the <bindingRedirect> tag from my web.config file still issue exists. could you please help me to resolve this issue. I have attached the screen shot for your reference.

    User's image

    User's image

    0 comments No comments