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

[Bug] MissingMethodException due to forced WAM upgrade #3964

Closed
1 of 7 tasks
Tracked by #3375
azchohfi opened this issue Feb 14, 2023 · 7 comments · Fixed by #3967
Closed
1 of 7 tasks
Tracked by #3375

[Bug] MissingMethodException due to forced WAM upgrade #3964

azchohfi opened this issue Feb 14, 2023 · 7 comments · Fixed by #3967

Comments

@azchohfi
Copy link

Logs and network traces

System.MissingMethodException: Method not found: 'Void Microsoft.Identity.Client.Core.MsalLoggerExtensions.Verbose(Microsoft.Identity.Client.Core.ILoggerAdapter, System.String)'.
   at Microsoft.Identity.Client.Broker.RuntimeBroker.IsBrokerInstalledAndInvokable(AuthorityType authorityType)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsFromBrokerAsync(String homeAccountIdFilter, ICacheSessionManager cacheSessionManager, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsInternalAsync(ApiIds apiId, String homeAccountIdFilter, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsAsync()

Which version of MSAL.NET are you using?
MSAL.NET 4.50.0

Platform
net7.0

What authentication flow has the issue?

  • Desktop / Mobile
    • Interactive
    • Integrated Windows Authentication
    • Username Password
    • Device code flow (browserless)
  • Web app
    • Authorization code
    • On-Behalf-Of
  • Daemon app
    • Service to Service calls

Is this a new or existing app?
The app is in production, and I have upgraded to a new version of MSAL.

Repro

var app = PublicClientApplicationBuilder
    .Create(ClientId)
    .WithDefaultRedirectUri()
    .WithBrokerPreview()
    .WithParentActivityOrWindow(....)
    .Build();
var accounts = await app.GetAccountsAsync();

Expected behavior
Works just like in 0.49.1.

Actual behavior
Throws MissingMethodException.

@pmaytak
Copy link
Contributor

pmaytak commented Feb 14, 2023

I can't repro this. Do you reference Microsoft.Identity.Client.NativeInterop? Can you make sure to explicitly reference 0.13.5?

@bgavrilMS
Copy link
Member

That's most likely the case. You upgraded MSAL but didn't upgrade the NativeInterop package.

@pmaytak In hindsight, relying on InternalsVisibleTo will make it impossible to detect "actual public api" changes in NativeInterop package. I wonder if we can improve the supportability / error message here?

@azchohfi
Copy link
Author

I see what the problem was.
I went to VS and updated all my packages to the latest available versions, but, by default, VS does that only for stable packages, not for the preview ones, so it only updated Microsoft.Identity.Client from 4.49.1 to 4.50.0 and Microsoft.Identity.Client.Extensions.Msal from 2.25.3 to 2.26.0. It did not update Microsoft.Identity.Client.Broker from 4.49.1-preview to 4.50.0-preview.
Still, after updating to the latest, I get a different exception:

Unhandled exception: MSAL.NetCore.4.50.0.0.MsalClientException:
        ErrorCode: wam_runtime_init_failed
Microsoft.Identity.Client.MsalClientException: Unable to load DLL 'msalruntime' or one of its dependencies: The specified module could not be found. (0x8007007E) See https://aka.ms/msal-net-wam#troubleshooting
 ---> System.DllNotFoundException: Unable to load DLL 'msalruntime' or one of its dependencies: The specified module could not be found. (0x8007007E)
   at Microsoft.Identity.Client.NativeInterop.API.x64.MSALRUNTIME_Startup()
   at Microsoft.Identity.Client.NativeInterop.API.x64.Startup()
   at Microsoft.Identity.Client.NativeInterop.Module.AddRef(String handleName)
   at Microsoft.Identity.Client.NativeInterop.Core..ctor()
   at Microsoft.Identity.Client.Broker.RuntimeBroker.<>c.<.cctor>b__24_0()
   --- End of inner exception stack trace ---
   at Microsoft.Identity.Client.Broker.RuntimeBroker.<>c.<.cctor>b__24_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Microsoft.Identity.Client.Broker.RuntimeBroker.IsBrokerInstalledAndInvokable(AuthorityType authorityType)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsFromBrokerAsync(String homeAccountIdFilter, ICacheSessionManager cacheSessionManager, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsInternalAsync(ApiIds apiId, String homeAccountIdFilter, CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsAsync(CancellationToken cancellationToken)
   at Microsoft.Identity.Client.ClientApplicationBase.GetAccountsAsync()

I've looked at the source of that package, and I only see a build folder, not a buildTransitive. That is probably why the need of a manual installation is needed. I believe this should be addressed.

I also agree with @bgavrilMS, the InternalsVisibleTo is makes it impossible to detect breaking changes, but this could/should also be solved at a NuGet level. The new package has a binary incompatibility with the previous version, so in semver that would mean a major version bump. The package should have a dependency on a specific major version, with an upper bound.

@bgavrilMS
Copy link
Member

CC @gladjohn for the native DLL not found exception - I believe there is a workaround. I think we need to fix this before GA-ing WAM broker.

@gladjohn
Copy link
Contributor

@azchohfi Are you testing this for the MSIX packaging in NETFX? in MSAL 4.50.0 we fixed the packaging issue, you need to add a reference to the Interop in your WapProj

@azchohfi
Copy link
Author

Nop, that is not the case here. This is a net7.0-windows10.0.17763.0 application.
I will do that eventually but haven't tried it yet.

@gladjohn gladjohn assigned gladjohn and unassigned SameerK-MSFT Feb 15, 2023
@gladjohn gladjohn added this to the 4.51.0 milestone Feb 15, 2023
@bgavrilMS bgavrilMS changed the title [Bug] IPublicClientApplication.GetAccountsAsync fails with MissingMethodException after upgrading to [Bug] MissingMethodException due to forced WAM upgrade Feb 24, 2023
@pmaytak
Copy link
Contributor

pmaytak commented Feb 25, 2023

That's most likely the case. You upgraded MSAL but didn't upgrade the NativeInterop package.

@pmaytak In hindsight, relying on InternalsVisibleTo will make it impossible to detect "actual public api" changes in NativeInterop package. I wonder if we can improve the supportability / error message here?

Hmm, well we rely a lot on internals, so can't remove InternalsVisibleTo. Somehow globally catching MissingMethodEx and retrowing may not be accurate. Not sure what proper way to do this would be. Once the fix for packaging goes in the next release, that should reduce these errors, since Interop will be loaded automatically.

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

Successfully merging a pull request may close this issue.

5 participants