Hi all
I'm facing this error in event viewer when publish my blazor server app to iis in windows 11 :
System.InvalidCastException: Unable to cast object of type 'Microsoft.Extensions.FileProviders.PhysicalFileProvider' to type 'Microsoft.Extensions.FileProviders.CompositeFileProvider'
And in my browser facing this error :
HTTP Error 500.30 - ASP.NET Core app failed to start.
It works in my visual studio, but i don't know what is the problem in published version!!
The detail info in event viewer is :
Application: w3wp.exe CoreCLR Version: 7.0.523.17405 .NET Version: 7.0.5 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidCastException: Unable to cast object of type 'Microsoft.Extensions.FileProviders.PhysicalFileProvider' to type 'Microsoft.Extensions.FileProviders.CompositeFileProvider'. at SmartMIS.Shared.Extensions.ConfigureStaticModuleFiles(WebApplication app) in E:\Development\Projects\Backups\SmartMIS\14020509.3\SmartMIS\SmartMIS.Shared\Extensions.cs:line 32 at Program.$(String[] args) in E:\Development\Projects\Backups\SmartMIS\14020509.3\SmartMIS\SmartMIS.Web\Program.cs:line 37
And here is my code which cause the problem :
public static WebApplication ConfigureStaticModuleFiles(this WebApplication app)
{
var moduleManagerService = app.Services.GetService<ModuleManager>();
var originalFileProviders = ((CompositeFileProvider)app.Environment.WebRootFileProvider).FileProviders.ToList();
StaticAssetInfo staticAssetInfo = new StaticAssetInfo();
foreach (IModulePackage modulePackage in moduleManagerService.Packages)
{
Assembly assembly = modulePackage.GetType().Assembly;
var newPathProvider = new ManifestEmbeddedFileProvider(assembly, "wwwroot");
originalFileProviders.Add(newPathProvider);
}
app.Environment.WebRootFileProvider = new CompositeFileProvider(originalFileProviders.ToArray());
return app;
}
Any help would be great appreciated.
Thanks in advance.