jsakamoto / Toolbelt.Blazor.FileDropZone

Surround an "input type=file" element by this Blazor component to making a zone that accepts drag and drops files.
https://jsakamoto.github.io/Toolbelt.Blazor.FileDropZone/
Mozilla Public License 2.0
22 stars 0 forks source link

Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'addEventListener') #3

Closed Wolfware2023 closed 4 days ago

Wolfware2023 commented 2 weeks ago

A user got an error with this library. This is what the error log showed:

Unhandled exception in circuit '"VZNZzbmqVHB2_4svbSzYtNbqLy9Ts7IypwiWMg0gXIA"'.
Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'addEventListener')
TypeError: Cannot read properties of null (reading 'addEventListener')
    at https://mydomain.com/myproject/_content/Toolbelt.Blazor.FileDropZone/script.min.js?v=2.1.1:1:394
    at Array.forEach (<anonymous>)
    at new t (https://mydomain.com/myproject/_content/Toolbelt.Blazor.FileDropZone/script.min.js?v=2.1.1:1:381)
    at Module.initializeFileDropZone (https://mydomain.com/myproject/_content/Toolbelt.Blazor.FileDropZone/script.min.js?v=2.1.1:1:40)
    at https://mydomain.com/myproject/_framework/blazor.server.js:1:3501
    at new Promise (<anonymous>)
    at kt.beginInvokeJSFromDotNet (https://mydomain.com/myproject/_framework/blazor.server.js:1:3475)
    at https://mydomain.com/myproject/_framework/blazor.server.js:1:72077
    at Array.forEach (<anonymous>)
    at kt._invokeClientMethod (https://mydomain.com/myproject/_framework/blazor.server.js:1:72063)
   at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
   at Toolbelt.Blazor.FileDropZone.FileDropZone.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

It also created a follow up error:

Unhandled exception in circuit '"VZNZzbmqVHB2_4svbSzYtNbqLy9Ts7IypwiWMg0gXIA"'.
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at MudBlazor.Services.KeyInterceptorFactory.Create()
   at MudBlazor.MudMask.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

Do you know what causes this? Mostly it works fine and I cannot reproduce it myself.

Wolfware2023 commented 2 weeks ago

Maybe this is relevant: Blazor Server - Cannot read properties of null (reading addEventListener)

jsakamoto commented 2 weeks ago

@Wolfware2023 Thank you for your report! Unfortunately, I have no idea why such an exception happened on your side. Usually, the problem you reported must not be caused. Could you send me your project? Otherwise, please tell me more details, such as the target .NET version (.NET6? 7? or 8?), hosting model (Blazor Server? WebAssembly?), etc.

Wolfware2023 commented 2 weeks ago

Sadly the project is company property and cannot be shared.

We are currently still using .Net 6 and Blazor Server. (It is hosted via IIS. The client browser I don't know. Likely Microsoft Edge.)

jsakamoto commented 2 weeks ago

@Wolfware2023 OK, no problem. So, I'll try to resolve this issue using the "Defensive Programming" strategy. Please give me a few days!

jsakamoto commented 2 weeks ago

Hi @Wolfware2023,

I released the improved version, v.3.0.

Could you try it out? Thanks!

Wolfware2023 commented 4 days ago

Hi @jsakamoto, thank you for your quick help! I was able to try the new version v.3.0 for one week in production so far. While I did not get these errors anymore, I received another one via our logs.

I will create a seperate Issue for the new error, since I am not 100% sure whether the issues are related.

jsakamoto commented 4 days ago

@Wolfware2023 Thank you for your reply. So, I'll close this issue and start to work on resolving issue #4 now.