Pregunta

I'm trying to get started with Cassette via NuGet. I'm having issues with it in my app so I rolled back and tried it in a new empty ASP.NET MVC 3 web application.

However, the problem persists. Following the documentation page "Easy to use", I simply can't get it to work. Here's the exception along with a bit of the stack:

"Object reference not set to an instance of an object."

[NullReferenceException: Object reference not set to an instance of an object.]
   Cassette.CassetteApplicationContainer.get_Application() +6
   Cassette.Views.Bundles.Reference(String assetPathOrBundlePathOrUrl, String pageLocation) +14
   ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\Dave\Documents\Visual Studio 2010\Projects\CasetteTest\Views\Shared\_Layout.cshtml:2
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207

I simply followed the two steps in the documentation and this is what I get. What am I doing wrong?

This is what my _Layout.cshtml file looks like:

@{
    Bundles.Reference("Scripts/jquery-1.5.1.min.js");
    Bundles.Reference("Scripts/modernizr-1.7.min.js");    
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>

<body>
    @RenderBody()
    @Bundles.RenderScripts();
</body>
</html>
¿Fue útil?

Solución

I figured it out.

I included the Cassette.Views package which does not create a default CassetteConfiguration.cs file that bundles each script and each css file in its own bundle. That's what triggered the NullReferenceException. In order to get it to work, you'll need to add the Cassette.Web package instead. In my defense, the package descriptions in the NuGet gallery are not clear and one is led to believe that the Views package is required for MVC and the other for WebForms.

The next problem was that I referenced the minified '.min.js' scripts which are not picked up by the bundler (it seems).

Otros consejos

Cannot reproduce the issue.

4 simple steps allowed me to get a fully working prototype in less than 30 seconds:

  1. Create a new ASP.NET MVC 3 project in Visual Studio
  2. Install-Package Cassette.Web
  3. Index.cshtml:

    @using Cassette.Web
    @{
        Bundles.Reference("~/Scripts/jquery-1.5.1.js");
        Bundles.Reference("~/Scripts/jquery-ui-1.8.11.js");
        Bundles.Reference("~/Content/site.css");
        Layout = null;
    }
    <!DOCTYPE html>
    <html>
    <head>
        <title>Web App</title>
        @Bundles.RenderStylesheets()
    </head>
    <body>
        <div>Hello World</div>
        @Bundles.RenderScripts()
    </body>
    </html>
    
  4. Hit Ctrl+F5 to run the project
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top