question

DmitriyReznik-4665 avatar image
0 Votes"
DmitriyReznik-4665 asked ShwetaMathur commented

Cannot load file or assembly 'System.Runtime'

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://docs.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.

azure-active-directorydotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ShwetaMathur avatar image
1 Vote"
ShwetaMathur answered ShwetaMathur commented

Hi @DmitriyReznik-4665,

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

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your answer.

When I remove

 <bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.1.1.1" />

The issue seems to be gone. Is it really not needed? If it just creates a problem, why was it even there?
And how should I make the version sync?

0 Votes 0 ·
ShwetaMathur avatar image ShwetaMathur DmitriyReznik-4665 ·

This is because of the conflicts in the new versions and older versions. When you compile the application, binding redirects be automatically added to the app configuration file
If you haven't explicitly enabled or disabled autogenerated binding redirection and you upgrade an existing project, the feature is automatically enabled and add binding redirect as per upgraded project.

Hope this will help.

Thanks,
Shweta


Please remember to "Accept Answer" if answer helped you, so it will help others in the community.


0 Votes 0 ·

Thank you again,

Not everything is clear to me though.

Could you please confirm that the binding redirect is not needed in my case, and can remove it safely?

Also, could you answer the question I asked previosly, "And how should I make the version sync?"

Thank you very much.

0 Votes 0 ·
Show more comments