andrewdavey/cassette — Issue #108: Custom pipeline causing intermittent error
Author: tomdenny
Created: 2011-11-29 01:06:15+00:00
State: open

I'm trying to create a bundle where the assets are always concatenated regardless if I'm in release mode or debug mode. Can you spot what's going wrong here?

I've attempted this using two different methods but both methods give me a 500 internal error/exception intermittently.

Method1: Custom ScriptPipeline class. The Bundle Processor is replaced during configuration with my custom class. The interesting tidbit in my custom class is:
protected override IEnumerable> CreatePipeline(ScriptBundle bundle, CassetteSettings settings)
{
foreach( IBundleProcessor p in base.CreatePipeline( bundle, settings ) ) {
yield return p;
if( settings.IsDebuggingEnabled && _concatenateOverride && p.GetType() == typeof( SortAssetsByDependency ) )
yield return new ConcatenateAssets();
}
}

Method2: Modify pipeline when creating the bundle.
private static void AddConcatenateAssets(ScriptBundle bundle)
{
((Cassette.BundleProcessing.MutablePipeline)bundle.Processor)
.InsertAfter(new ConcatenateAssets());
}
...
Action concatePipeline = (settings.IsDebuggingEnabled ? (Action)AddConcatenateAssets : null);
bundles.Add("scripts/shim",
topLevelScriptSearch,
concatePipeline);

Exception:
[ObjectDisposedException: Cannot access a closed Stream.]
System.IO.__Error.StreamIsClosed() +57
System.IO.MemoryStream.set_Position(Int64 value) +9629708
Cassette.BundleProcessing.ConcatenatedAsset.OpenStreamCore() +79
Cassette.AssetBase.OpenStream() +148
Cassette.Bundle.OpenStream() +64
Cassette.Web.BundleRequestHandler`1.SendBundle(Bundle bundle, String actualETag) +223
Cassette.Web.BundleRequestHandler`1.ProcessRequest() +374
Cassette.Web.BundleRequestHandler`1.System.Web.IHttpHandler.ProcessRequest(HttpContext unused) +34
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75