ArgumentNullException in Blazor #2740
Replies: 4 comments 4 replies
-
@jefffhaynes, assuming this is the new Blazor app in .NET 8: |
Beta Was this translation helpful? Give feedback.
-
Thanks for the questions @jmprieur. My goal is to use all RBAC/SSO so no client secrets. Here is my entire program.cs. This is all being done as an App Service. I have not tried it locally (at least not this part). var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph(options => options.RequestAppToken = true)
.AddInMemoryTokenCaches();
builder.Services.AddControllersWithViews(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}).AddMicrosoftIdentityUI();
builder.Services.AddMicrosoftIdentityConsentHandler();
builder.Services.AddDbContextFactory<MyContext>(options =>
{
options.UseCosmos("<url>",
new DefaultAzureCredential(), MyContext.DatabaseName);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run(); |
Beta Was this translation helpful? Give feedback.
-
@jmprieur do you see any obvious problems with what I'm doing? |
Beta Was this translation helpful? Give feedback.
-
It seems that the app service does not provide you with headers. |
Beta Was this translation helpful? Give feedback.
-
I'm sure I'm missing something obvious but I'm getting an ArgumentNullException in Blazor (.NET 8) when I try to use the
GraphServiceClient
inOnParametersSetAsync
:The exception takes place the second time
OnParametersSetAsync
is called during the render cycle. The first time the call completes successfully.I'm initializing like this:
Beta Was this translation helpful? Give feedback.
All reactions