Home > front end >  @Scripts.Render("~/bundles/bootstrap") is throwing NullReferenceException
@Scripts.Render("~/bundles/bootstrap") is throwing NullReferenceException

Time:10-12

I am working on this ASP.NET MVC project. I did not do any changes to the _Layout.cshtml or BundleConfig.cs or Web.config. When I ran the project, it is showing the below exception:

System.NullReferenceException: 'Object reference not set to an instance of an object.' [External Code] ASP._Page_Views_Shared__Layout_cshtml.Execute() in _Layout.cshtml

I tried the minification method but still it failed. If it is possible to view, please check the photos below.

Can somebody help me resolve this issue, please?

Picture01

Picture02

Pciture03

CodePudding user response:

Same issue here with an older Web API project after upgrading all NuGet packages, specifically to Bootstrap 5.1

The same happens on a new default Web API project in VS 2019 after upgrading its packages to Bootstrap 5.1 - NullReferenceException in _Layout.cshtml!

Apparently dependencies for Bootstrap 5.1 are not yet handled propery by ASP.NET projects -
Downgrading (via VS Nuget Manager) to the last available 4.x version solved the issue for my projects.

CodePudding user response:

Yes even I got same.Whenever I was updating , same issues coming around.

I tried this and replaced the following:

bundles.Add(new ScriptBundle("~/bundles/mybundle").Include(
            "~/Scripts/...",
            "~/Scripts/..."));

with this:

bundles.Add(new Bundle("~/bundles/mybundle").Include(
            "~/Scripts/...",
            "~/Scripts/..."));

You can try.

  • Related