-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using DryIoc causes Blazor to crash #567
Comments
@MaxwellDAssistek Hi, thanks for notifying. Could you please do as stated in the error message and wrap the code in try/catch and The only caveat, you need to ask for the actual container via |
@dadhi So there is no code to try/catch. Everything happens in a separate Blazor thread which I have no code running in at all. What I was able to do is put a breakpoint in DryIoc.ContainerException.WithDetails and I was able to run:
(Globals is a static class I made just to store the container instance) Unfortunately all I get is: "Unable to get the service registration for the problematic factory with FactoryID=1000" I was able to go up the stack and look at the locals in
|
Thank you for the info. Hope, I can extract useful bits from it. |
This is where that service is added: https://github.com/dotnet/aspnetcore/blob/a7bf7ccdcff6475f144c300a0d21421b6efbb1b3/src/Components/Server/src/DependencyInjection/ComponentServiceCollectionExtensions.cs#L69-L70 Maybe the services that are added to builder.Services are not properly register with DryIoc. I noticed that if I do |
Here is a seemingly related Microsoft article: https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-60-samples?view=aspnetcore-7.0#aspnet-core-6-7 Looks like DryIoc needs to expose an IServiceCollection in some way and that might be the only way to register MS things, since they all use extension methods of IServiceCollection. var diFactory = new DryIocServiceProviderFactory(container);
builder.Host.UseServiceProviderFactory(diFactory);
builder.Host.ConfigureContainer<IServiceCollection>((_, collection) =>
{
collection.AddRazorPages();
collection.AddServerSideBlazor(options =>
{
options.DetailedErrors = true;
});
}); This gives: Edit: This might all be a red-herring. I added |
The problem here is that when you're integrating the existing
I am not sure about this, never heard of this requirement. But will check, thanks for the link. |
@dadhi Still no luck unfortunately. I still get the same exception with the following Program.cs: using BlazorApp2;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using BlazorApp2.Data;
using DryIoc;
using DryIoc.Microsoft.DependencyInjection;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
var container = new Container(
Rules.MicrosoftDependencyInjectionRules.With(
FactoryMethod.ConstructorWithResolvableArguments,
propertiesAndFields: PropertiesAndFields.Auto)
);
Globals.MainContainer = container;
// Here it goes the integration with the existing DryIoc container
var diFactory = new DryIocServiceProviderFactory(container, RegistrySharing.Share);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor(options =>
{
options.DetailedErrors = true;
});
builder.Services.AddSingleton<WeatherForecastService>();
var logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.ReadFrom.Configuration(builder.Configuration)
.Enrich.FromLogContext()
.WriteTo.File("Errors/Log_.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
builder.Host.UseSerilog(logger);
builder.Host.UseServiceProviderFactory(diFactory);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// 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.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run(); |
I am still not sure about the root cause, but regarding this service
|
@dadhi Unfortunately, the issue is that ICircuitAccessor is marked internal so its impossible for me to do anything with it without rebuilding aspnetcore. |
@MaxwellDAssistek |
@MaxwellDAssistek I have added the sample. The error is caused by |
@MaxwellDAssistek ...or you may use container rules with
and filter the properties in |
@dadhi I can confirm that removing PropertiesAndFields fixed it! I should've guessed that it could be the cause, but it just never caused any issues in the other places we use DryIoc like MAUI. Thank you for your help! |
@MaxwellDAssistek Thanks for investing into this issue. |
That's a fantastic. I think we will end up switching to that right away! |
…egistration for Error.WaitForScopedServiceIsCreatedTimeoutExpired for #567
…egistration for Error.WaitForScopedServiceIsCreatedTimeoutExpired for #567
@MaxwellDAssistek |
@dadhi We don't use file uploads in our projects currently so we did not have that issue, but I was able to reproduce it using the code provided and added what the actual exception is that is hiding. What we've found with Blazor is that they like to hide their internal exceptions under the "Debug" log level so we need to lower the log level to that in order to see the exceptions (as I did in the sample code here using Serilog). |
@MaxwellDAssistek Thank you very much, I saw the details on #547. |
@MaxwellDAssistek I have "quickly" added the net7.0 target to both DryIoc.dll and DryIoc.Microsoft.DependencyInjection and released the |
Hello,
When I try to use DryIoc in my Server-size Blazor project, it causes an internal Blazor error.
To reproduce:
The text was updated successfully, but these errors were encountered: