3

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

oykinn__
  • 31
  • 2

4 Answers4

5

Replace the following:

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

with this:

bundles.Add(new Bundle("~/bundles/mybundle").Include(
            "~/Scripts/...",
            "~/Scripts/..."));
Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
Akanksha
  • 51
  • 1
  • 1
3

In the method BundleConfig.RegisterBundles I replaced all existing instantiation of ScriptBundle to instances of Bundle and it worked as expected.

Peter Csala
  • 10,331
  • 15
  • 20
  • 47
LJILJANA
  • 31
  • 1
2

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.

Jay
  • 6,424
  • 2
  • 36
  • 61
1

The suggested solution provided by Akanksha resolved the originally described problem after I upgraded an older ASP.NET WebAPI project from Bootstrap 3.x to 5.1.x

In the method BundleConfig.RegisterBundles I replaced all existing instantiation of ScriptBundle to instances of Bundle and it worked as expected.

            bundles.Add(new Bundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

Thanks!

JoKi
  • 21
  • 3