Conversion from .NET framework 4.6 to 4.8

Dutta, Pijush 1 Reputation point
2021-07-27T04:37:09.453+00:00

I have converted my web api framework target from 4.6.2 --> 4.8, this is the error I get after I change target framework and reinstalling nuget packages:-

The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception.. error ASPRUNTIME.

My web config have information of old library and new as below:-

<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
</dependentAssembly>

Can anyone suggest what is problem here. Thanks for help.

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
293 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2021-07-27T06:56:20.457+00:00

    Hi @Dutta, Pijush ,
    As far as I think,there are two ways you could try:
    1.Open ‘Package Manager Console’ and select the project present where WebAPI is present and run the following code:

    Install-Package Microsoft.AspNet.WebApi -IncludePrerelease  
    

    2.From ‘Manage NuGet Packages’ from Tools > NuGet Package Manager uninstall WebAPI libraries and reinstall WebAPI new libraries, where in you may find back missing libraries.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Ravi Shankar Kakarla 161 Reputation points
    2021-08-22T16:43:51.133+00:00

    install Microsoft.AspNet.WebApi.Client 5.2.7 nuget package and try to run the app.

    If this does not work, try commenting on this line.

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

    0 comments No comments