OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.36k stars 2.37k forks source link

OrchardCore.Media Feature "kill" site once enabled (In Release only) #7056

Closed vitalybrandes closed 3 years ago

vitalybrandes commented 4 years ago

Once enable OrchardCore.Media feature via recipe or via admin panel the website theme not available, this is the log file: (In Release only)

image

I am using in appsettings.json

"OrchardCore.Media": { "MaxCacheDays": 365, "MaxFileSize": 30000000, "AllowedFileExtensions": [ ".zip", ".7zip" ] }

2020-09-10 12:51:56.5948|Default||97b06c24-4d720cae6636819b.||Microsoft.AspNetCore.Server.Kestrel|ERROR|Connection id "0HM2LDS4JUI3T", Request id "0HM2LDS4JUI3T:00000027": An unhandled exception was thrown by the application. System.ArgumentNullException: Parameter "WebRootPath" must be not null. (Parameter 'WebRootPath') at SixLabors.ThrowHelper.ThrowArgumentNullException(String name, String message) at SixLabors.ThrowHelper.ThrowArgumentExceptionForNotNullOrWhitespace(String value, String name) at SixLabors.ImageSharp.Web.Caching.PhysicalFileSystemCache..ctor(IOptions1 cacheOptions, IWebHostEnvironment environment, IOptions1 options, FormatUtilities formatUtilities) at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build() at OrchardCore.Modules.ModularTenantRouterMiddleware.BuildTenantPipeline() in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 108 at OrchardCore.Modules.ModularTenantRouterMiddleware.InitializePipelineAsync(ShellContext shellContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 77 at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 63 at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func2 execute) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 206 at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 59 at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application) at SixLabors.ThrowHelper.ThrowArgumentNullException(String name, String message) at SixLabors.ThrowHelper.ThrowArgumentExceptionForNotNullOrWhitespace(String value, String name) at SixLabors.ImageSharp.Web.Caching.PhysicalFileSystemCache..ctor(IOptions1 cacheOptions, IWebHostEnvironment environment, IOptions1 options, FormatUtilities formatUtilities) at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build() at OrchardCore.Modules.ModularTenantRouterMiddleware.BuildTenantPipeline() in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 108 at OrchardCore.Modules.ModularTenantRouterMiddleware.InitializePipelineAsync(ShellContext shellContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 77 at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantRouterMiddleware.cs:line 63 at OrchardCore.Environment.Shell.Scope.ShellScope.UsingAsync(Func2 execute) in C:\projects\orchardcore\src\OrchardCore\OrchardCore.Abstractions\Shell\Scope\ShellScope.cs:line 206 at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchardcore\src\OrchardCore\OrchardCore\Modules\ModularTenantContainerMiddleware.cs:line 59 at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

deanmarcussen commented 4 years ago

Please make sure you have an empty wwwroot folder (put an empty file in it called .placeholder if it has been lost during publish) in your host startup project.

I am surprised there isn't as we have an MSBuild command to force create the .placeholder file

vitalybrandes commented 4 years ago

Please make sure you have an empty wwwroot folder (put an empty file in it called .placeholder if it has been lost during publish) in your host startup project.

I am surprised there isn't as we have an MSBuild command to force create the .placeholder file

Hi @deanmarcussen Folder and file exist image

deanmarcussen commented 4 years ago

Have you made some alterations to the IWebHostEnvironment ?

or IHostEnvironment file providers?

I assume by Release mode, you mean when you change the Environment from Development to Production.

Suggest you try injecting IWebHostEnvironment in your Startup and logging the value for IWebHostEnvironment.WebRootPath

ImageSharp depends on having a value for the WebRootPath which is normally provided by having a wwwroot folder.

Certain modules, like Blazor, can manipulate it, so best to check the value yourself.

vitalybrandes commented 4 years ago

Have you made some alterations to the IWebHostEnvironment ?

or IHostEnvironment file providers?

I assume by Release mode, you mean when you change the Environment from Development to Production.

Suggest you try injecting IWebHostEnvironment in your Startup and logging the value for IWebHostEnvironment.WebRootPath

ImageSharp depends on having a value for the WebRootPath which is normally provided by having a wwwroot folder.

Certain modules, like Blazor, can manipulate it, so best to check the value yourself.

@deanmarcussen Clean orchard Application.Cms.Targets project running in Production, Once enable the Media module in Features the web UI and admin not available. I used SAAS recipe.

WWW folder exist and no other modules / theme added.

Log: Microsoft.AspNetCore.Server.Kestrel|ERROR|Connection id "0HM2NPJ7RLN1D", Request id "0HM2NPJ7RLN1D:00000025": An unhandled exception was thrown by the application. System.ArgumentNullException: Parameter "WebRootPath" must be not null. (Parameter 'WebRootPath')

To reproduce, just create clean Orchard CMC project, compile in Release and run. Then enable Media feature.

Exactly the same in Debug running fine.

deanmarcussen commented 4 years ago

Couldn't repro I'm afraid

Can you make sure you have this in your hosts startup project

  <ItemGroup>
    <Folder Include="wwwroot\" />
    <Folder Include="Localization\" />
  </ItemGroup>

and do as I suggested before

Suggest you try injecting IWebHostEnvironment in your Startup and logging the value for IWebHostEnvironment.WebRootPath

vitalybrandes commented 4 years ago

Couldn't repro I'm afraid

Can you make sure you have this in your hosts startup project

  <ItemGroup>
    <Folder Include="wwwroot\" />
    <Folder Include="Localization\" />
  </ItemGroup>

I have this in host project, do i need to add that also to modules?

and do as I suggested before

Suggest you try injecting IWebHostEnvironment in your Startup and logging the value for IWebHostEnvironment.WebRootPath

Did it, and path is to wwwroot folder of host app. .placeholder located inside this folder :-(.

Can you maybe share with me your repro where this was OK?

vitalybrandes commented 4 years ago

@deanmarcussen I download this repository https://github.com/OrchardCMS/TryOrchardCore update nugets to latest and build it as release image

Then run the .exe process from the output folder and setup the site with existing recipe. image

Once complied, login to Admin - > features - > Enable Media feature. image

Site down with same error. image

Microsoft.AspNetCore.Server.Kestrel|ERROR|Connection id "0HM2PIS8FM7U3", Request id "0HM2PIS8FM7U3:00000049": An unhandled exception was thrown by the application. System.ArgumentNullException: Parameter "WebRootPath" must be not null. (Parameter 'WebRootPath')

Did i done something wrong to compile site in production? did i miss something? I am trying to build docker container for production and its fail each time on same media module.

thanks for help.

deanmarcussen commented 4 years ago

@vitalybrandes This is proving difficult to understand as you keep telling me new things about what you are trying to do.

Is it a docker container you are building / a production / release build?

It sounds like you are trying to create a self contained deployment (because you have an exe)

Here is some info about what the differences are https://stackoverflow.com/questions/39155571/how-to-run-net-core-console-app-from-the-command-line

Can you make it fail with a standard release build that is not self contained and uses dotnet run The.dll and doesn't involve docker at all?

Or can you be a lot more specific about repro steps please?

vitalybrandes commented 4 years ago

@vitalybrandes This is proving difficult to understand as you keep telling me new things about what you are trying to do.

Is it a docker container you are building / a production / release build?

It sounds like you are trying to create a self contained deployment (because you have an exe)

Here is some info about what the differences are https://stackoverflow.com/questions/39155571/how-to-run-net-core-console-app-from-the-command-line

Can you make it fail with a standard release build that is not self contained and uses dotnet run The.dll and doesn't involve docker at all?

Or can you be a lot more specific about repro steps please?

@deanmarcussen Docker container is my target, I am publishing the App using VS 2019. The output folder include .exe file that running app using kestrel in 5000/5001 port.

See in my previews comment, this is steps to reproduce. 1 . I copy the Orchard core Try solution form https://github.com/OrchardCMS/TryOrchardCore

  1. Update the nugets to latest
  2. Run app as SAAS recipe
  3. From admin, enable the Media module.

p.s - All this in Latest visual studio 2019.

vitalybrandes commented 3 years ago

To fix this in my case, i just delete the publish profile, and this help, but...... if you do build and run App as release with no publish, the wwwroot folder no exist, following that the media feature fail.