Quirkiness of Blazor Server Apps deployed on Hosted IIS VM on Azure #58956
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
Is there an existing issue for this?
Describe the bug
I am posting this to help me understand what is happening behind the scene with my code in a Blazor Server Application. As mentioned, my Blazor Server App (the App here in after), is, at least to me, a complex mixture of .razor, C# (Classes, Function with HTML, Model, etc.), JavaScript (Cannot forgo this if you are on the web, sadly), and persistence.
In the past as developers we learn that Development Environments may not always translate well to Production Environments. This is the primordial aspect for this post that I wish to learn and understand more. To start out simply, the necessary configuration on IIS for a Blazor application to run, are a maze that even though you may have done it several times, you get lost in the next configuration. Albeit, assuring you crossed all your t's and dotted all your i's, for some reason the Production Environment of an IIS running on Azure VM brings forth my issue of the Quirkiness of how a Blazor Environment behaves running on it.
For starters, the App I developed requires access to a database (SQL Express for this purpose), and in the application.json file the connection string with all the proper credentials, security, encryption, etc. to have the App access the Database. In the App, I am using EF Core Identity for User Management (Why re-invent the wheel), since I require local accounts as well as interaction with OAUTH MS or AWS or Google accounts. The interaction is managed separately since I cannot use the MS Graph library should I access OAUTH for AWS and/or Google.
The core of the problem is the EF Core Identity. Having the following code (excerpt) in a Service in the App:
This service is to be used in Pages and Components alike in the App to implement as best as my beginner's programming skills allow, to circumvent the problem of the EF Core Identity no having a
UserManage.GetUsersAsync()
. In the App in the StartUp.CS file the service is registered as a Scoped serviceservices.AddScoped<UserService>();
. In the pages and the components the service is used as:And although most of the times I have no problem loading the Users Async, the issue that sets the difference in the Production vs. Development environment is if the service is used as follows using LINQ:
works perfectly in the Development Environment, but when the App is deployed into the IIS, it returns the error:
The issue is that the error does not happen in the Development with the same exact code. All compiles, runs and performs as it should. This simple LINQ statement had to be changed to the following loop in order for the code to work on both environments:
Could someone help me identify my mistake or why the issue that the LINQ code works on a one computer using Visual Studio 2022 with all patches and .NET 8.0, and on the server IIS VM configured with all the necessary configuration for a Blazor Server Application on IIS plus the runtime .NET 8.0 does not work? Any insights will save me many hours of development and debugging.
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
.Net 8.0
Anything else?
I am using EF Core Identity.
The text was updated successfully, but these errors were encountered: