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

System.TypeLoadException: Could not load type 'Microsoft.Graph.IAutehnticationProviderOption' from assembly 'Microsoft.Graph.Core' #1854

Closed
dlgombert opened this issue Apr 24, 2023 · 5 comments

Comments

@dlgombert
Copy link

I've tried a million variations of the following code, implementing in services, directly in controllers, etc. Everywhere I try leads to the same error:

 services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApi(configuration.GetSection("AzureAd"))
            .EnableTokenAcquisitionToCallDownstreamApi()
            .AddMicrosoftGraph(configuration.GetSection("MicrosoftGraph"))
            .AddInMemoryTokenCaches();

System.TypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

To Reproduce

  1. Press play to start debugging.
  2. Go to the url I've setup in the controller.

Expected behavior
I expect the graph query I call which is:

   var result = await _graphServiceClient.ServicePrincipals[
            servicePrincipal
        ].AppRoleAssignedTo.GetAsync();

to return the users for the app.

I can show configuration if it helps.

When I tried to create a scoped service, the service was unable to be resolved in the controller. The debugger would never even make it that far, despite having registered it and confirmed that it was registered as scoped.

I'm still somewhat new to Csharp, so this could definitely be operator error, but as far as I can tell, I've followed the documentation, and I've tried enough changes that I ought to have hit on it by now, lol.

@ghost ghost added the Needs: Triage label Apr 24, 2023
@andrueastman
Copy link
Member

Thanks for raising this @dlgombert

This is related to AzureAD/microsoft-identity-web#2097.

Any chance using this works out for you? https://gist.github.com/ashelopukho/5b00944c7744ebb4f9baa348e86f7e0e

@dlgombert
Copy link
Author

I've worked with the gist for awhile,, and I'm unable to make it work. The underlying issue is that TokenProvider gets invoked before the user is Authenticated, and indeed the user is never authenticated. The error here is: MsalUiRequiredException and ErrorCode is user_null. Where before it would either use existing token or callup the login popup, it's now complaining about incremental authentication - something I had trouble with when working with Blazor as well.

I'm invoking EnableTokenAcquisitionForDownstreamApi, but without AddMicrosoftGraph, as it looks like that get's handled during token acquisition. If I do use AddMicrosoftGraph, I get System.TypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. again.

If I'm reading the back and forth correctly, it seems like my best option is to roll back to 4.5? But I can't be the only one with this use case. Any insight?

@jassent
Copy link

jassent commented Apr 28, 2023

I've worked with the gist for awhile,, and I'm unable to make it work. The underlying issue is that TokenProvider gets invoked before the user is Authenticated, and indeed the user is never authenticated. The error here is: MsalUiRequiredException and ErrorCode is user_null. Where before it would either use existing token or callup the login popup, it's now complaining about incremental authentication - something I had trouble with when working with Blazor as well.

I'm invoking EnableTokenAcquisitionForDownstreamApi, but without AddMicrosoftGraph, as it looks like that get's handled during token acquisition. If I do use AddMicrosoftGraph, I get System.TypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. again.

If I'm reading the back and forth correctly, it seems like my best option is to roll back to 4.5? But I can't be the only one with this use case. Any insight?

Also breaking for me to try and upgrade to the new Graph Client in a Blazor Server application that has been working for years using Graph and Azure AD.

@viniciusfonseca-trt17
Copy link

I've managed to get it to work after replacing dependency Microsoft.Identity.Web.MicrosoftGraph with Microsoft.Identity.Web.GraphServiceClient.

https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web.GraphServiceClient/Readme.md

@andrueastman
Copy link
Member

andrueastman commented Feb 9, 2024

Closing this for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants