diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs index 133b840543..379523b659 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs @@ -232,7 +232,7 @@ public class AbpAspNetCoreMvcModule : AbpModule public override void OnApplicationInitialization(ApplicationInitializationContext context) { AddApplicationParts(context); - context.ServiceProvider.GetRequiredService().CheckLibs(context); + CheckLibs(context); } private static void AddApplicationParts(ApplicationInitializationContext context) @@ -279,4 +279,9 @@ public class AbpAspNetCoreMvcModule : AbpModule partManager.ApplicationParts.AddIfNotContains(moduleAssembly); } } + + private static void CheckLibs(ApplicationInitializationContext context) + { + context.ServiceProvider.GetRequiredService().CheckLibs(context); + } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs index 532ac18239..5563667438 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Libs/AbpMvcLibsService.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using System.Net; @@ -40,7 +41,7 @@ public class AbpMvcLibsService : IAbpMvcLibsService, ITransientDependency "

⚠️ The Libs folder under the wwwroot/libs directory is empty!

" + "

The Libs folder contains mandatory NPM Packages for running the project.

" + "

Make sure you run the abp install-libs CLI tool command.

" + - "

For more information, check out the ABP CLI documentation

" + + "

For more information, check out the ABP CLI documentation

" + " " + "", Encoding.UTF8 @@ -65,14 +66,23 @@ public class AbpMvcLibsService : IAbpMvcLibsService, ITransientDependency protected virtual Task CheckLibsAsync(HttpContext httpContext) { - var fileProvider = new PhysicalFileProvider(httpContext.RequestServices.GetRequiredService().WebRootPath); - var libsFolder = fileProvider.GetDirectoryContents("/libs"); - if (!libsFolder.Exists || !libsFolder.Any()) + var logger = httpContext.RequestServices.GetRequiredService>(); + try { - var logger = httpContext.RequestServices.GetRequiredService>(); - logger.LogError("The 'wwwroot/libs' folder does not exist or empty!"); - return Task.FromResult(false); + var fileProvider = new PhysicalFileProvider(httpContext.RequestServices.GetRequiredService().WebRootPath); + var libsFolder = fileProvider.GetDirectoryContents("/libs"); + if (!libsFolder.Exists || !libsFolder.Any()) + { + logger.LogError("The 'wwwroot/libs' folder does not exist or empty!"); + return Task.FromResult(false); + } + } + catch (Exception e) + { + // In case of any exception, log it and return true to prevent crashing the application. + logger.LogError(e, "An error occurred while checking the libs folder!"); } + return Task.FromResult(true); } }