System.TypeLoadException: 'Could not load type 'System.Web.HttpContextBase' from assembly 'System.Web,
Asked Answered
V

4

14

Whenever I try to load the Chart using System.Web.Helpers namespace in Asp.net Core I get this Exception.

System.TypeLoadException: 'Could not load type 'System.Web.HttpContextBase' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'

Please See the image

new System.Web.Helpers.Chart(width: 800, height: 200).AddTitle("My Chart").AddSeries(chartType: "column", 
           xValue: new[] { _context.DemoTable.Select(o => o.Month) },
           yValues: new[] { _context.DemoTable.Select(o => o.AutomationPercentage) }
          ).Write("png");

What am I doing wrong here??

Vulvitis answered 6/4, 2018 at 8:58 Comment(2)
System.Web.HttpContextBase is part of System.Web assembly. .NET core by default does not add reference of this DLL, and it is also not preferred to do so. I think System.Web.Helpers is .NET Framework library and not .NET CoreBellbird
Thanks for the reply.. Can you please tell me which library do I need to add so as to get this work.Vulvitis
L
6

the class exists in other namespace so make sure you're using Microsoft.AspNetCore.Mvc and not the .NET framework version.

Loggins answered 13/3, 2019 at 22:36 Comment(2)
I get this error while trying to test .NET Framework code from a xUnit .NET Core unit test. What do I need to add to my .NET core project to make this work?Oceanography
Can you please explain what you mean in a bit more detail, what is the namespace we need to reference for the MVC .NET Core version?Maestricht
R
1

I believe you have installed packages that are targeting only for Net MVC and therefore has a dependencies on System.Web.HttpContextBase which don't exist in Net Core. To fix this issue you need to find which package you installed don't have support for your Net core and install an alternative

Ruisdael answered 22/6, 2020 at 19:24 Comment(0)
A
0

In the project dependencies, look the one with warnings, remove them. That should do the trick

Attitude answered 27/7, 2023 at 7:26 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Tarrance
A
0

Removed all Microsoft.Aspnet.* and also Microsoft.Web.Infrastructure from References

Amora answered 26/9, 2023 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.