AzureAD / microsoft-authentication-library-for-dotnet

Microsoft Authentication Library (MSAL) for .NET
https://aka.ms/msal-net
MIT License
1.39k stars 341 forks source link

[Bug] Error in creating UWP package for Microsoft Store Upload #3184

Closed vinodshinde closed 2 years ago

vinodshinde commented 2 years ago

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

Platform UWP

What authentication flow has the issue?

Is this a new or existing app? The app is in production and currently using legacy Live SDK, I am trying to upgraded MSAL, but started seeing this issue.

Expected behavior It should create a UWP app package to upload to store.

Actual behavior App package creation fails with following error C:\Users\User\.nuget\packages\microsoft.net.native.compiler\2.2.11-rel-30601-02\tools\Microsoft.NetNative.targets(805,5): warning : MCG : warning MCG0007: Unresolved P/Invoke method 'ntdll.dll!RtlGetVersion' for method 'System.Int32 Microsoft.Identity.Client.PlatformsCommon.Shared.Win32VersionApi.RtlGetVersion(Microsoft.Identity.Client.PlatformsCommon.Shared.Win32VersionApi.OSVERSIONINFOEXW)'. Calling this method would throw exception at runtime. Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP APIs.

C:\Users\User\.nuget\packages\microsoft.net.native.compiler\2.2.11-rel-30601-02\tools\Microsoft.NetNative.targets(805,5): error : Internal compiler error: Exception of type 'System.OutOfMemoryException' was thrown.

bgavrilMS commented 2 years ago

@vinodshinde - how do you create the package? please use MSAL 4.40 @gladjohn - I think we may need to find another solutuion for the versioning RtlGetVersion as it might not work in UWP. Or maybe this [DllImport(ExactSpelling=true)

vinodshinde commented 2 years ago

I use this menu image

bgavrilMS commented 2 years ago

Ack, please use MSAL 4.40 until we sort this out.

vinodshinde commented 2 years ago

I am actually using Microsoft.Graph which pulls the latest MSAL by default. so not sure how to force Microsoft.Graph to use 4.40 version

bgavrilMS commented 2 years ago

@vinodshinde - you can take a direct dependency on MSAL 4.40 and that will override Microsoft.Graph's dependency.

gladjohn commented 2 years ago

@vinodshinde I do see the warning but I am able to create the package without any errors.

Build started...
1>------ Build started: Project: UWPWAM, Configuration: Release ARM64 ------
1>  UWPWAM -> F:\UWP\UWPWAM\UWPWAM\bin\ARM64\Release\UWPWAM.exe
1>  Processing application code
1>  Computing application closure and generating interop code
1>    Loading 120 modules...
1>C:\Users\gladw\.nuget\packages\microsoft.net.native.compiler\2.2.11-rel-30601-02\tools\Microsoft.NetNative.targets(805,5): warning :       MCG : warning MCG0007: Unresolved P/Invoke method 'ntdll.dll!RtlGetVersion' for method 'System.Int32 Microsoft.Identity.Client.PlatformsCommon.Shared.Win32VersionApi.RtlGetVersion(Microsoft.Identity.Client.PlatformsCommon.Shared.Win32VersionApi.OSVERSIONINFOEXW)'. Calling this method would throw exception at runtime. Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP APIs.
1>    Generating code...
1>    Interop code generated.
1>  Compiling interop code
1>  Generating System.Reflection.DispatchProxy proxy code.
1>  Cleaning up unreferenced code
1>  Generating native code
1>  Generating fixups for native code
1>  UWPWAM -> F:\UWP\UWPWAM\UWPWAM\bin\ARM64\Release\UWPWAM_1.0.2.0_ARM64.msix (unsigned)
1>  UWPWAM -> obj\ARM64\Release\Symbols\UWPWAM_1.0.2.0_ARM64.appxsym
1>  UWPWAM -> F:\UWP\UWPWAM\UWPWAM\AppPackages\UWPWAM_1.0.2.0_Test\UWPWAM_1.0.2.0_x86_x64_arm_arm64.msixbundle
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
A package has been successfully built for Release (x86).
A package has been successfully built for Release (x64).
A package has been successfully built for Release (ARM).
A package has been successfully built for Release (ARM64).
========== Package: 4 succeeded, 0 failed ===========
An app bundle has been successfully built for Release (x86), Release (x64), Release (ARM), Release (ARM64).
========== App Bundle: 1 succeeded, 0 failed ===========

I don't think the error you see is related to the OSDetection Change that was added to MSAL. Created a sample UWP app that uses MSAL 4.42.0 to acquire token and call into Microsoft Graph. Can you please try creating a package from this?

bgavrilMS commented 2 years ago

@gladjohn - can we get rid of those warnings by setting this DllImport(ExactSpelling=true) ? Do we even call this logic in UWP?

gladjohn commented 2 years ago

Yes the plan is to fix the warnings for the next release by adding DllImport(ExactSpelling=true). We do not call into the DesktopOSHelpers for UWP we just enable broker by default.

vinodshinde commented 2 years ago

@bgavrilMS @gladjohn I added direct dependency on MSAL 4.40 but the AppPackage creation still failed. Also tried by deleting all bin and obj folders. Finally ended up removing Microsoft.Graph nuget package completely from project.

Used WebAutheticationBroker for OAuth flow and using direct REST API calls using HttpClient on Microsoft Calendar and OneDrive. I only need List, Upload, Download from OneDrive. On Calendar i needed CRUD on Calendar and CRUD on calendar events. So it was not that bad. Thank you for looking into it.

DRAirey1 commented 2 years ago

Ran into this issue trying to publish to the store. I had everything working just great on my local machine and I decided just to make sure I had the latest version of everything before I published my UWP package to the store. Pulled down Microsoft.Identity.Client 4.42.1 and published. Spent the next hour trying to figure out why my package was rejected with:

Error Found: The supported APIs test detected the following errors:
API RtlGetVersion in ntdll.dll is not supported for this application type. ThetaRex.OpenBook.Desktop.dll calls this API.

Finally, as the only thing I really changed before publishing was the new version of Microsoft.Identity.Client, I dropped back to 4.42.0 and everything passed the validation and published.

bgavrilMS commented 2 years ago

Ack, thanks for the details @DRAirey1 - so it looks like the errors occur at the time you upload the package to the store.

@gladjohn - can we just consider WAM to be available all the time on UWP ? I doubt ppl install UWP apps on Win Server 2016 and if they do, we'll just have to escalate to Windows team for guidance. But until then, I recommend we just ignore the Window versioning stuff on UWP.

DRAirey1 commented 2 years ago

so it looks like the errors occur at the time you upload the package to the store.

Correct. I hadn't used the local app validation cycle in a while, but after getting this error I ran it again and it showed the same error.

bgavrilMS commented 2 years ago

@DRAirey1 - how do you run this app validation cycle on local app?

DRAirey1 commented 2 years ago

@DRAirey1 - how do you run this app validation cycle on local app?

Sorry, should have been more clear. In Solution Explorer, select the UWP project and then: Publish -> Create App Package -> Microsoft Store as <package name> by <company> -> Create -> Launch Windows App Certification Key

This will catch the error as well.