Base solution for your next web application
Open Closed

AspNetCore.Hosting.Internal.WebHost - Hosting startup assembly exception #6418


User avatar
0
kpmg created

Hi everyone!

I use the new 6.5 template with angular and .net core 2.2. I have an error during the startup of the application that results in my opinion in a tenant ID error. On my local maschine I don't get the error. What can I do?

I am hosting it on Azure as a Web App. I think the problem is somewhere else. When I restart the Web App and just call the login screen, the following logs are getting created. First I thought it is my Application Insights but the error bellow still occurs even if I disabled Application Insights.

DEBUG 2019-02-05 10:22:06,135 [1 ] Abp.Modules.AbpModuleManager - Loading Abp modules... DEBUG 2019-02-05 10:22:06,394 [1 ] Abp.Modules.AbpModuleManager - Found 23 ABP modules in total. DEBUG 2019-02-05 10:22:06,523 [1 ] Abp.Modules.AbpModuleManager - 23 modules loaded. DELETED SOME LOGS FOR READABILITY DEBUG 2019-02-05 10:22:27,794 [1 ] cy.SubscriptionExpireEmailNotifierWorker - Start background worker: myappDemo.MultiTenancy.SubscriptionExpireEmailNotifierWorker FATAL 2019-02-05 10:22:31,570 [1 ] soft.AspNetCore.Hosting.Internal.WebHost - Hosting startup assembly exception System.InvalidOperationException: Startup assembly Microsoft.AspNetCore.AzureAppServices.HostingStartup failed to execute. See the inner exception for more details. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.AzureAppServices.HostingStartup, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors) --- End of inner exception stack trace --- INFO 2019-02-05 10:22:32,477 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 OPTIONS http://myapp-dev7854.azurewebsites.net/AbpUserConfiguration/GetAll?d=1549362115780 INFO 2019-02-05 10:22:32,635 [8 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful. INFO 2019-02-05 10:22:32,861 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 366.8468ms 204 INFO 2019-02-05 10:22:33,049 [8 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://myapp-dev7854.azurewebsites.net/AbpUserConfiguration/GetAll?d=1549362115780 application/json INFO 2019-02-05 10:22:33,052 [8 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.

DELETED SOME LOGS FOR READABILITY

INFO 2019-02-05 10:22:40,671 [11 ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://myapp-dev7854.azurewebsites.net/TenantCustomization/GetTenantLogo?skin=light&tenantId=3&id=7ac9b5b4-c56d-c92e-91a3-39eb92117412 INFO 2019-02-05 10:22:40,789 [11 ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'myappDemo.Web.Controllers.TenantCustomizationController.GetTenantLogo (myappDemo.Web.Core)' ERROR 2019-02-05 10:22:40,798 [12 ] Mvc.ExceptionHandling.AbpExceptionFilter - Session.TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users). Abp.AbpException: Session.TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users). at Abp.Runtime.Session.AbpSessionExtensions.GetTenantId(IAbpSession session) at myappDemo.Web.Controllers.TenantCustomizationController.GetCustomCss() in C:\DEV\Repos\myapp\aspnet-core\src\myappDemo.Web.Core\Controllers\TenantCustomizationController.cs:line 170 at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync() INFO 2019-02-05 10:22:40,817 [12 ] ore.Mvc.Internal.ControllerActionInvoker - Executed action myappDemo.Web.Controllers.TenantCustomizationController.GetCustomCss (myappDemo.Web.Core) in 286.7727ms INFO 2019-02-05 10:22:40,818 [12 ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'myappDemo.Web.Controllers.TenantCustomizationController.GetCustomCss (myappDemo.Web.Core)' ERROR 2019-02-05 10:22:40,825 [12 ] Microsoft.AspNetCore.Server.Kestrel - Connection id "0HLKBAFB83ATQ", Request id "0HLKBAFB83ATQ:00000005": An unhandled exception was thrown by the application. Abp.AbpException: Session.TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users). at Abp.Runtime.Session.AbpSessionExtensions.GetTenantId(IAbpSession session) at myappDemo.Web.Controllers.TenantCustomizationController.GetCustomCss() in C:\DEV\Repos\myapp\aspnet-core\src\myappDemo.Web.Core\Controllers\TenantCustomizationController.cs:line 170 at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Abp.AspNetCore.Security.AbpSecurityHeadersMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

Thanks in advance


4 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Duplicate of #4911

  • User Avatar
    0
    kpmg created

    okay fine, but what is the solution and whats about the second error? In the linked post is no solution for these errors described (also not on the github page)

  • User Avatar
    0
    kpmg created

    I finally found the solution! This article here brought me to the right point.

    In the angular project in the file root.module.ts I deleted the four lines (I set a comment in the example) and it worked:

    `function initializeTenantResources(injector: Injector) { let appSessionService: AppSessionService = injector.get(AppSessionService);

    if (appSessionService.tenant && appSessionService.tenant.customCssId) {
        document.head.appendChild(
            DomHelper.createElement('link', [
                {
                    key: 'id',
                    value: 'TenantCustomCss'
                },
                // { 
                //     key: 'rel',
                //     value: 'stylesheet'
                // },
                {
                    key: 'href',
                    value: AppConsts.remoteServiceBaseUrl + '/TenantCustomization/GetCustomCss?tenantId=' + appSessionService.tenant.id
                }])
        );
    }`
    
  • User Avatar
    0
    kpmg created

    I undid the changes from my last post and adjusted the TenantCustomizationController.cs

    [AllowAnonymous]
    public async Task GetCustomCss(int? tenantId)
    
    {
    var tenant = await _tenantManager.GetByIdAsync(AbpSession.GetTenantId());
    if (tenantId.HasValue)
    {
    tenant = await _tenantManager.GetByIdAsync(tenantId.Value);
    }
    if (!tenant.CustomCssId.HasValue)
    {
    return StatusCode((int)HttpStatusCode.NotFound);
    }
    
    using (CurrentUnitOfWork.SetTenantId(tenantId.Value))
    {
    var cssFileObject = await _binaryObjectManager.GetOrNullAsync(tenant.CustomCssId.Value);
    if (cssFileObject == null)
    {
    return StatusCode((int)HttpStatusCode.NotFound);
    }
    return File(cssFileObject.Bytes, MimeTypeNames.TextCss);
    }
    
    }
    

    and the calling URLS in root.module.ts, tenant-settings.component.html and tenant-settings.component.ts

    to

    tenantCustomCss.setAttribute('href', AppConsts.remoteServiceBaseUrl + '/TenantCustomization/GetCustomCss?tenantId=' + this.appSession.tenant.id);
    

    Now it seems to work.