Skip to content

Adding external dll dependency in Blazor WASM Shared project causing exception when deployed in IIS ! #47551

Open
@harshbhadoria011

Description

@harshbhadoria011

Hi,

I've created a Blazor WASM project in .NET6. In my use case, I need to select a file and that file will be processed by an external dll, it will process the data and return some output.

This external dll I've added in Shared project and from Client project in index.rajor, I'm calling respective methods of this dll. This external dll is .net 6 compiled dll.

In VS2022 on my developent machine, when I ran, it worked smoothly. But when I published and deployed in IIS on other server, I've got issues (pasted below).

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Invalid type TestApp.Shared.TestService for instance field TestApp.Client.Pages.Index:<Svc>k__BackingField System.TypeLoadException: Invalid type TestApp.Shared.TestService for instance field TestApp.Client.Pages.Index:<Svc>k__BackingField at System.RuntimeTypeHandle.CanCastTo(RuntimeType , RuntimeType ) at System.RuntimeType.IsAssignableFrom(Type ) at Microsoft.AspNetCore.Components.RouteTableFactory.<GetRouteableComponents>g__GetRouteableComponents|4_0(List 1 , Assembly ) at Microsoft.AspNetCore.Components.RouteTableFactory.GetRouteableComponents(RouteKey ) at Microsoft.AspNetCore.Components.RouteTableFactory.Create(RouteKey ) at Microsoft.AspNetCore.Components.Routing.Router.RefreshRouteTable() at Microsoft.AspNetCore.Components.Routing.Router.Refresh(Boolean isNavigationIntercepted) at Microsoft.AspNetCore.Components.Routing.Router.RunOnNavigateAsync(String path, Boolean isNavigationIntercepted) at Microsoft.AspNetCore.Components.Routing.Router.<>c__DisplayClass62_0.<RunOnNavigateAsync>b__1(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder , RenderFragment , Exception& )

One More Question: When i was trying to add this external dll dependency in my Blazor WASM Client project, I got error like "File not found". So, Shared project is the correct place to add other dependency?

To Reproduce
Create a Blazor WASM project. Add any external dll dependency in the Shared project.
Create an instance in Client's Program.cs -> builder.Service.AddScoped
Inject this service in index.razor -> @Inject ABCService svc

Further Technical Details
SDK used is .NET 6
IDE VS2022

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Componentsfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssemblyinvestigate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions