Finally I managed to fix it. Instead of downloading Cassette.Aspnet from Nuget, I downloaded Cassette, Cassette.Aspnet and Cassette.Views from their GitHub repo, added to the solution, and it worked.
Cassette NullReferenceException on the latest version
-
26-06-2022 - |
Question
I upgraded from Cassette 2.0.0 to the latest version, and I have the following exception:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Lazy`1.get_Value() +10785860
Cassette.Aspnet.IsolatedStorageContainer.get_IsolatedStorageFile() +27
Cassette.Aspnet.WebHostSettingsConfiguration.<GetCacheDirectory>b__0() +5
Cassette.IO.IsolatedStorageFile.get_Storage() +10
Cassette.IO.IsolatedStorageFile.get_Exists() +13
Cassette.Aspnet.WebHostSettingsConfiguration.IsStaticCacheManifest(CassetteSettings settings) +48
Cassette.Aspnet.WebHostSettingsConfiguration.Configure(CassetteSettings settings) +219
Cassette.ConfigurationEnumerableExtensions.Configure(IEnumerable`1 configurations, T configurable) +151
Cassette.CassetteSettings..ctor(IEnumerable`1 configurations) +33
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +190
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +607
[TinyIoCResolutionException: Unable to resolve type: Cassette.CassetteSettings]
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +642
Cassette.TinyIoC.SingletonFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options) +103
Cassette.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options) +85
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +361
[TinyIoCResolutionException: Unable to resolve type: Cassette.BundleCollection]
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +482
Cassette.TinyIoC.SingletonFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options) +103
Cassette.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options) +85
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +361
[TinyIoCResolutionException: Unable to resolve type: Cassette.Views.BundlesHelper]
Cassette.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options) +482
Cassette.TinyIoC.SingletonFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options) +103
Cassette.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options) +85
Cassette.TinyIoC.TinyIoCContainer.<ResolveAllInternal>b__44(TypeRegistration registration) +32
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +145
System.Linq.<CastIterator>d__b1`1.MoveNext() +85
Cassette.HostBase.RunStartUpTasks() +65
Cassette.HostBase.Initialize() +147
Cassette.Aspnet.CassetteHttpModule.InitWithoutTraceLogging() +34
Cassette.Aspnet.CassetteHttpModule.InitWithTraceLogging() +137
Cassette.Aspnet.CassetteHttpModule.Init(HttpApplication httpApplication) +121
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +418
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Unable to resolve type: Cassette.Views.BundlesHelper]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874568
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
I tried Googling that, but I couldn't find anything. Any ideas?
It also happens when I create a new empty MVC project and install the latest version of Cassette-Aspnet. Here's my web config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="cassette" type="Cassette.CassetteConfigurationSection, Cassette" requirePermission="false" />
</configSections>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Cassette.Views" />
</namespaces>
</pages>
<httpModules>
<add name="CassetteHttpModule" type="Cassette.Aspnet.CassetteHttpModule, Cassette.Aspnet" />
</httpModules>
<httpHandlers>
<add path="cassette.axd" verb="*" type="Cassette.Aspnet.CassetteHttpHandler, Cassette.Aspnet" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="CassetteHttpHandler" path="cassette.axd" preCondition="integratedMode" verb="*" allowPathInfo="true" type="Cassette.Aspnet.CassetteHttpHandler, Cassette.Aspnet" />
</handlers>
<modules>
<add name="CassetteHttpModule" type="Cassette.Aspnet.CassetteHttpModule, Cassette.Aspnet" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AjaxMin" publicKeyToken="21ef50ce11b5d80f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.84.4790.14405" newVersion="4.84.4790.14405" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<cassette />
</configuration>
I tried in both in local IIS and real IIS.
Solution 2
OTHER TIPS
I just upgraded from Cassette 2.0 to Cassette 2.3 via Nuget and ran into this exact same exception on application start. Turns out that the current Nuget package has .NET 4.0 Client Profile targeted instead of plain .NET 4.0 for the Cassette.dll, so Nuget creates a references to the .NET 3.5 version of the DLL which causes this exception.
I had to manually update the path of the Cassette reference from ..\packages\Cassette.2.3.0\lib\net35\Cassette.dll
to ..\packages\Cassette.2.3.0\lib\net40-client\Cassette.dll
in my project file.