Shazwazza / ClientDependency

DEPRECATED. A library for managing CSS & JavaScript dependencies and optimization in ASP.Net
139 stars 65 forks source link

Relative URI exception in Azure Production #198

Open skwiggly opened 3 years ago

skwiggly commented 3 years ago

Our team recently upgraded from Umbraco 7.15.6 to 8.11, running in Azure. We are using Client Dependency v1.9.9. In our Test and Staging environments, CDF works fine, no errors. However in Production, we have been getting dozens of exceptions daily like:

Could not load file contents from /css/bootstrap/css/bootstrap.min.css. EXCEPTION: This operation is not supported for a relative URI.

Exception
System.InvalidOperationException: This operation is not supported for a relative URI.
   at System.Uri.get_AbsolutePath()
   at ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.WritePathToStream(ClientDependencyType type, String path, HttpContextBase context, StreamWriter sw) in C:\Users\Shannon\Documents\_Projects\ClientDependency\ClientDependency\src\ClientDependency.Core\CompositeFiles\Providers\BaseCompositeFileProcessingProvider.cs:line 218

The exceptions are for a variety of CSS and JS files, which are are local files, in the "umbraco_assets" folder. Based on timestamps, it appears that only one or a few files throw an exception at a time, not all of them.

This seems to be similar to this issue: https://github.com/Shazwazza/ClientDependency/issues/147 Except we are not using any custom file writers, and no custom file types. We have registered .js and .css as follows: fileDependencyExtensions=".js,.css"

This is an example of how we create our bundles:

BundleManager.CreateCssBundle("ConsumerStylesResponsive",
                new CssFile("~/umbraco_assets/css/bootstrap/css/bootstrap.min.css"),
                new CssFile("~/umbraco_assets/css/v5/consumer_styles_new.css"));

This is the related portion of clientDependency.config:

<compositeFiles defaultProvider="defaultFileProcessingProvider" compositeFileHandlerPath="~/umbraco_assets/DependencyHandler.axd">
    <fileProcessingProviders>
      <add name="CompositeFileProcessor" type="ClientDependency.Core.CompositeFiles.Providers.CompositeFileProcessingProvider, ClientDependency.Core" enableCssMinify="true" enableJsMinify="true" persistFiles="true" compositeFilePath="~/App_Data/ClientDependency" bundleDomains="localhost:123456" urlType="Base64QueryStrings" pathUrlFormat="{dependencyId}/{version}/{type}" />
    </fileProcessingProviders>
    <!-- A file map provider stores references to dependency files by an id to be used in the handler URL when using the MappedId Url type -->
    <fileMapProviders>
      <add name="XmlFileMap" type="ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper, ClientDependency.Core" mapPath="~/App_Data/ClientDependency" />
    </fileMapProviders>
  </compositeFiles>

The only notable thing about the clientDependency.config is that initially, we had this setting: compositeFileHandlerPath="~/DependencyHandler.axd" However, again only in Production, DependencyHandler.axd was throwing a 404 and not loading ANY CSS/JS. Only when we changed it to: compositeFileHandlerPath="~/umbraco_assets/DependencyHandler.axd" Did CDF start working again.

How can we debug what is happening here? I don't have steps to reproduce since everything works when running localhost, Test and Staging; this is only happening in our Production Azure environment, and I have never personally experienced the Prod site not loading CSS/JS.