Open Closed

Blazor App is not running ok when the environment is anything other than Development. #2024


User avatar
0
VivekKoppula created

I created a starter Balzor Server project and ran in two scenerios. The two scenerios differ only in the fact that the ASPNETCORE_ENVIRONMENT is different. In one case its 'Development', and in the other case its 'DevelopmentTwo', anything other then 'Development'

First the necessary details are as follows.

The dotnet version is 6.0.100-rc.2.21505.57 ABP version is 4.4.3 (Stable)

UI Type is Blazor Server. No Preview(Its just .net 5)

DB Provide: Ef Core

Tiered (MVC) or Identity Server Separated (Angular): No

Now the two scenerios.

I am running the blazor app running on my localhost.

In the scenerio one, I connect to the local db database on my local machine. The ASPNETCORE_ENVIRONMENT is 'Development'. For this I selected the IIS Express profile which looks as follows in launchSettings.json.

"IIS Express": {
	  "commandName": "IISExpress",
	  "launchBrowser": true,
	  "environmentVariables": {
		"ASPNETCORE_ENVIRONMENT": "Development"
	  }
	},
    

I created settings file named it appsettings.Development.json. Its contents are as follows.

{
  "ConnectionStrings": {
	"Default": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BvhHrSita;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
  },
  "SomeVar": "Development Env"
}

I modified the CreateHostBuilder method in the Program.cs file as follows to include the appsettings.development.json file.

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration(build =>
            {

                var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

                build.AddJsonFile("appsettings.secrets.json", optional: false);
                build.AddJsonFile("appsettings.json", optional: false);
                build.AddJsonFile($"appsettings.{env}.json", optional: false);
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .UseAutofac()
            .UseSerilog();
            

In this scenerio, the app works fine as expected.

In the scenerio two, everything is same except the ASPNETCORE_ENVIRONMENT is anything other than 'Development', I choose 'DevelopmentTwo'. To create this scenerio I did the following.

First I made a copy of appsettings.Development.json and named it appsettings.DevelopmentTwo.json. Its contents are as follows.

{
  "ConnectionStrings": {
	"Default": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=BvhHrSita;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
  },
  "SomeVar": "Developemnt Two Env"
}

The Connection String is exactly same, only the SomeVar is now as you can see Development Two Env.

Also I added a new profile in launchSettings.json as follows to help me set env var ASPNETCORE_ENVIRONMENT to DevelopmentTwo as follows.

"IISExpressDevTwo": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "DevelopmentTwo"
  }
},

Here again, the only diff is ASPNETCORE_ENVIRONMENT which is DevelopmentTwo.

Now when I run this profile, the app does not run properly.

If I press F12 to look at the console, I see the following mesages.

DevTools failed to load source map: Could not load content for https://localhost:44313/__bundles/toastr.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load source map: Could not load content for https://localhost:44313/__bundles/bootstrap.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE	

I added a few lines of code to the ConfigureServices Method in BlazorModule.cs file to know exactly which profile is being loaded and what the evn var is as follows. This is just for debugging, and not required for reproducing the issue.

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
        var configuration = context.Services.GetConfiguration();

        var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
        var envName = hostingEnvironment.EnvironmentName;
        var connString = configuration.GetConnectionString("Default");
        //configuration

        var myValue = configuration.GetValue<string>("SomeVar");


        ConfigureUrls(configuration);
        

So now when I launch the app, I see the following

If I select the earlier profile, where the ASPNETCORE_ENVIRONMENT is just Development and not DevelopmentTwo, I see the following as I launch the app.

So as you can see the the only difference is ASPNETCORE_ENVIRONMENT.

In summary, when ever ASPNETCORE_ENVIRONMENT is anything other then Development, the app would not run properly. The F12 shows the following.

DevTools failed to load source map: Could not load content for https://localhost:44313/__bundles/toastr.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
DevTools failed to load source map: Could not load content for https://localhost:44313/__bundles/bootstrap.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE	

And when I see the logs, I see an exception like the following(when the ASPNETCORE_ENVIRONMENT is anything other then Development).

2021-10-24 18:12:09.000 +05:30 [DBG] Added 0 entity changes to the current audit log
2021-10-24 18:12:09.020 +05:30 [ERR] An unhandled exception has occurred while executing the request.
Volo.Abp.AbpException: Could not find file '/_content/Blazorise/blazorise.css'
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundlerBase.GetFileInfo(IBundlerContext context, String file)
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundlerBase.GetAndMinifyFileContent(IBundlerContext context, String fileName)
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundlerBase.GetFileContentConsideringMinification(IBundlerContext context, String fileName)
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundlerBase.Bundle(IBundlerContext context)
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundleManager.<>c__DisplayClass16_0.<GetBundleFilesAsync>b__0()
   at System.Collections.Generic.AbpDictionaryExtensions.&lt;&gt;c__DisplayClass7_0`2.<GetOrAdd>b__0(TKey k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Collections.Generic.AbpDictionaryExtensions.GetOrAdd[TKey,TValue](ConcurrentDictionary`2 dictionary, TKey key, Func`1 factory)
   at Volo.Abp.AspNetCore.Mvc.UI.Bundling.BundleCache.GetOrAdd(String bundleName, Func`1 factory)

Something is fishy with respect to bundling. But when the env var is ASPNETCORE_ENVIRONMENT is Development things run fine.

Hope that I am not missing something trivial here and you will be able to reproduce this. Any advice is appreciated. Let me know if you need any details further.


1 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Hi @VivekKoppula

    Let me know if it happens while running published blazor-server applications

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11