Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Resources duplication causes error on application startup #249

Open
danfma opened this Issue May 9, 2012 · 6 comments

Comments

Projects
None yet
2 participants

danfma commented May 9, 2012

Hey Andrew,

In this last version 1.2.1, a single Bundles.Reference causes the following error when trying to load the application. But I think that the problem is on the configuration of the Cassette.

I am sending the error message

Server Error in '/Atual' Application.
A StylesheetBundle with the path "~/Content/css/accordion.css" has already been added to the collection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: A StylesheetBundle with the path "~/Content/css/accordion.css" has already been added to the collection.

Source Error:

Line 19:             // In production the content will be minified, but the files are not combined.
Line 20:             // So you probably want to tweak these defaults!
Line 21:             bundles.AddPerIndividualFile<StylesheetBundle>("Content");
Line 22:             bundles.AddPerIndividualFile<ScriptBundle>("Scripts");
Line 23: 


Source File: F:\Projetos\SisImob\Server\Atual\CassetteConfiguration.cs    Line: 21

Stack Trace:

[ArgumentException: A StylesheetBundle with the path "~/Content/css/accordion.css" has already been added to the collection.]
   Cassette.Configuration.BundleCollection.Add(Bundle bundle) +174
   Cassette.Configuration.BundleCollectionExtensions.AddPerIndividualFile(BundleCollection bundleCollection, String directoryPath, IFileSearch fileSearch, Action`1 customizeBundle) +428
   Atual.WebSite.CassetteConfiguration.Configure(BundleCollection bundles, CassetteSettings settings) in F:\Projetos\SisImob\Server\Atual\CassetteConfiguration.cs:21
   Cassette.Configuration.CassetteSettings.ExecuteCassetteConfiguration(IEnumerable`1 cassetteConfigurations) +209
   Cassette.Configuration.CassetteSettings.GetBundleContainerFactory(IEnumerable`1 cassetteConfigurations) +15
   Cassette.CassetteApplicationContainerFactoryBase`1.CreateApplication() +114
   Cassette.CassetteApplicationContainer`1.CreateApplication() +59
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   Cassette.Web.StartUp.InitializeApplicationContainer() +110
   Cassette.Web.StartUp.PostApplicationStart() +209

[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.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +233
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +21
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   WebActivator.BaseActivationMethodAttribute.InvokeMethod() +239
   WebActivator.ActivationManager.RunActivationMethods() +495
   WebActivator.ActivationManager.RunPostStartMethods() +27
   WebActivator.StartMethodCallingModule.Init(HttpApplication context) +125
   System.Web.HttpApplication.InitModulesCommon() +80
   System.Web.HttpApplication.InitModules() +64
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +792
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +298
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +322


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17379 

I didn't touch the Configuration of the Cassette (this is a new project) so it is with the factory configuration. The only page that refers to a resource is the layout page with the following:

@{
    Bundles.Reference("Content/css/home.css", "head");
    Bundles.Reference("Scripts/jquery-1.7.2.js", "head");
    Bundles.Reference("Scripts/knockout-2.1.0.js", "head");
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    @Bundles.RenderStylesheets("head")
    @Bundles.RenderScripts("head")
</head>
<body>
    @RenderBody()
    @Bundles.RenderHtmlTemplates()
    @Bundles.RenderScripts()
</body>
</html>

danfma commented May 9, 2012

No problem with the previous version (1.2.0).

Owner

andrewdavey commented May 9, 2012

I wonder if the CassetteConfiguration is somehow getting called twice? Can you put a breakpoint in and see how many times it's hit?

danfma commented May 9, 2012

Ok... I will check that!

danfma commented May 9, 2012

I will check again later but apparently the configuration is not been called twice. But the error has gone, somewhat. I will check with more details as soon as I can. :)

Owner

andrewdavey commented Jun 19, 2012

Have you tried upgrading to the v2 beta? The bundle collection initialization was significantly improved and should fix problems like this.

Owner

andrewdavey commented Sep 10, 2012

v2 has been released. Does this fix the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment