Skip to content
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

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

Open
harshbhadoria011 opened this issue Apr 4, 2023 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly investigate
Milestone

Comments

@harshbhadoria011
Copy link

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Apr 4, 2023
@mkArtakMSFT
Copy link
Member

Thanks for contacting us. Looks like the assembly you're referencing is being trimmed, impacting the APIs that you rely on.
Consider annotating it to avoid those methods to not be trimmed, following our documentation at: https://learn.microsoft.com/aspnet/core/blazor/host-and-deploy/configure-trimmer?view=aspnetcore-7.0

To confirm this is indeed the case, you can try to simply disable the trimmer for your project and see if that works, by setting the following property in your project file of the Shared project:

<PublishTrimmed>false</PublishTrimmed>

@mkArtakMSFT mkArtakMSFT added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly labels Apr 4, 2023
@ghost
Copy link

ghost commented Apr 4, 2023

Hi @harshbhadoria011. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@harshbhadoria011
Copy link
Author

Hi @mkArtakMSFT , I tried disabling trimming but it didn't work.
For now, instead of dll, I used complete source code of that dll and it worked. Still I'm trying to figure out why dll is not able to resolve at blazor assembly runtime.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Apr 7, 2023
@javiercn
Copy link
Member

@harshbhadoria011 How are you referencing the dll?

It seems that there is a problem in how the dll you are referring to is being consumed, are you using lazy loading? If so, the dll needs to be loaded before the type is even referenced by another type, otherwise you get a typeload exception (as you saw).

@SteveSandersonMS SteveSandersonMS added investigate and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Apr 10, 2023
@SteveSandersonMS SteveSandersonMS added this to the Backlog milestone Apr 10, 2023
@ghost
Copy link

ghost commented Apr 10, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, BlazorPlanning Nov 5, 2023
@MackinnonBuck MackinnonBuck modified the milestones: Planning: WebUI, Backlog Dec 4, 2023
@ghost
Copy link

ghost commented Dec 4, 2023

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-wasm This issue is related to and / or impacts Blazor WebAssembly investigate
Projects
None yet
Development

No branches or pull requests

7 participants
@SteveSandersonMS @javiercn @MackinnonBuck @wtgodbe @mkArtakMSFT @harshbhadoria011 and others