Open atriusfox opened 5 years ago
I'm experience the exact same behavior. Haven't found a solution yet. Please help.
I got the same issue. Currently use: ASP.NET Core 3.0 and LigerShark.WebOptimizer.Core 3.0.250
I just tested this (CSS and JS bundling) with what's in master as well as what's in NuGet. Both succeeded. Please look at the WebOptimizer.Core.Mvc3 sample for reference.
I just tested this (CSS and JS bundling) with what's in master as well as what's in NuGet. Both succeeded. Please look at the WebOptimizer.Core.Mvc3 sample for reference.
I tried your sample as well an it's working. But I have several projects which this is not the case. Haven't found the differences.
For now I have found a Workaround @ndtien84 @atriusfox
I configured for each stylesheet the absolut path /wwwroot/src/css/foo.css
instead of src/css.foo.css
and used the extension method UseContentRoot()
. For consistency I did the same for my js files even it's not necessary for those. With this adjustment everythin is working fine.
thanks @skimedic @dannyyy
I also tried WebOptimizer.Core.Mvc3 and it work great. But not work for my project
@dannyyy workaround solution is super, thank you so much.
I also tried to include the project WebOptimizer.Core into my solution. I found that the issue may be in this file: RelativePathAdjuster.cs. I debug both example project and my project and found the different: (I dont't know why :()
example project (work great)
my project (not work)
Hi @skimedic When I use the following frameworks👇 in ASP.NET Core 3.1 together LigerShark.WebOptimizer.Core There is a problem and it cannot work properly
`
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.0" />`
I think an error in LigerShark.WebOptimizer.Core There is a use with these frameworks
How should we fix the problem?
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request. System.ArgumentNullException: Value cannot be null. (Parameter 'fileName')
for Improve This Error
Convert this Line of Code
content[key] = Adjust(config.Content[key].AsString(), input.PhysicalPath, output.PhysicalPath);
To 👇 :
content[key] = Adjust(config.Content[key].AsString(), input.PhysicalPath, output.Name);
From what I can tell, this issue is caused when using a CompositeFileProvider. WebRootFileProvider is often a CompositeFileProvider by default when using a razor class library with static assets.
ComposteFileProvider.GetFileInfo() iterates through it's providers and returns the first non-null file info it finds where Exists = true. If it doesn't find one, it returns a NotFoundFileInfo which returns null for PhysicalPath (https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.fileproviders.notfoundfileinfo?view=dotnet-plat-ext-3.1).
RelativePathAdjuster attempts to get a file info from the provider for the output (which will never exist, or shouldn't). It gets a NotFoundFileInfo back which returns null when attempting to get PhysicalPath for the Adjust() call. Adjust() then attempts to create a new FileInfo using the outputPath (which is null) and throws an exception.
Had the same problem and somehow this "works":
bundle.AddCssBundle("/Content/css.css",
"/wwwroot/Content/metro-bootstrap.css",
"/wwwroot/Content/jquery.fileupload-ui.css",
"/wwwroot/Content/font-awesome.css",
"/wwwroot/Content/tablesorter.theme.default.css",
"/wwwroot/Content/jquery.bonsai.css",
"/wwwroot/Content/DataTables/css/jquery.dataTables.css",
"/wwwroot/Content/DataTables/css/buttons.dataTables.css",
"/wwwroot/Content/DataTables/css/buttons.bootstrap.css",
"/wwwroot/Content/Site.css").UseContentRoot().AdjustRelativePaths();
@robertmuehsig In blazor, image url in css file will have prefix "/wwwroot", which is not found.
I found that when bundle process go through Concatenator(), filePath has been change to Guid, and CssFingerprinter() cannot get a PhysicalPath.
My "working" solution is use Concatenate() or FingerprintUrls(), or even call FingerprintUrls() before Concatenate() !!! (not recommend from docs /// NOTE: Make sure to call Concatinate() before this method
)
pipeline.AddBundle("/bundle.css", "text/css; charset=UTF-8",
"css/bootstrap.min.css",
"css/style.css")
.EnforceFileExtensions(".css")
.AdjustRelativePaths()
.Concatenate()
//.FingerprintUrls()
.AddResponseHeader("X-Content-Type-Options", "nosniff")
.MinifyCss(new CssSettings());
as @robertmuehsig suggested also works for me pipeline.AddCssBundle("/bundle.css", "wwwroot/css/*/.css").UseContentRoot().AdjustRelativePaths();
For me it was IWebHostEnvironment.WebRootPath, which was null. This happens when you don't have 'wwwroot' folder in your project.
AddCssBundler is failing. AddJavaScriptBundler works fine.
I tried copy pasting the exact CSS from the sample and paths (/css/a.css and /css/b.css)
This was post upgrade from .net 2.1 to .net 3.0 going from WebOptimizer version 1.0.236 to 3.0.250 to support .net 3.0
Everything worked pre-upgrade
Used this line of code for the pipeline call:
pipeline.AddCssBundle("/css/bundle.css", "css/a.css", "css/b.css");
Attached picture of error when trying to access https://localhost/css/bundle.css
I'm unsure how to debug this further.
I attempted to confirm through tracing the sample project that it should be getting the correct fullpath name when attempting to get FileInfo and when I do it manually I think I'm getting it right but I'm unable to step into the WebOptimizer middleware code to see what's different in my project vs the sample.