microsoft / microsoft/WindowsAppSDK
CredUIPromptForWindowsCredentials crashes in unpackaged app
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
### Describe the bug
Please see the attached solution, there are three projects, one packaged WASDK, one unpackaged WASDK and one WinForms project. All three projects use the same `CredentialService` file/class to display the credential ui. The unpackaged app crashes here:

```
Not Flagged 29672 1 Main Thread Main Thread UnpackagedWASDK.dll!TestCredPicker.CredentialService.NativeMethods.CredUIPromptForWindowsCredentials
Not Flagged 60556 4 Worker Thread .NET Counter Poller System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck
Not Flagged 31620 5 Worker Thread .NET TP Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
Not Flagged 18440 6 Worker Thread .NET TP Gate System.Private.CoreLib.dll!System.Threading.WaitHandle.WaitOneNoCheck
Not Flagged 31444 7 Worker Thread .NET TP Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
Not Flagged 62060 8 Worker Thread .NET ThreadPool IO System.Private.CoreLib.dll!System.Threading.PortableThreadPool.IOCompletionPoller.Poll
Not Flagged 67480 9 Worker Thread .NET TP Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
Not Flagged 39756 10 Worker Thread .NET TP Worker System.Private.CoreLib.dll!Interop.Kernel32.GetQueuedCompletionStatus
Not Flagged > 57496 0 Worker Thread UnpackagedWASDK.dll!UnpackagedWASDK.App.InitializeComponent.AnonymousMethod__4_2
```
```
UnpackagedWASDK.dll!UnpackagedWASDK.App.InitializeComponent.AnonymousMethod__4_2(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Line 75 C#
Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_UnhandledExceptionEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Unknown
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.UnhandledExceptionEventHandler.Do_Abi_Invoke(nint thisPtr, nint sender, nint e) Unknown
```
### Steps to reproduce the bug
- See the attached sample app: [TestCredPicker.zip](https://github.com/microsoft/WindowsAppSDK/files/14978306/TestCredPicker.zip)
- Should display the credential dialog for the current logged on user:

### Expected behavior
I would expect that either all projects crash, because there may be something wrong with my PInvoke code, or none. But as both packaged and WinForms project run without problems, i suspect there is something wrong with the unpackaged nature of the project.
### Screenshots
_No response_
### NuGet package version
Windows App SDK 1.5.2: 1.5.240404000
### Packaging type
Unpackaged
### Windows version
Windows 10 version 22H2 (19045, 2022 Update)
### IDE
Visual Studio 2022
### Additional context
I don't know what version of WASDK introduced this problem, because at some point in time this code was developed and working with WASD (1.2.221116.1).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the attached TestCredPicker.zip solution and its shared CredentialService file, then run the packaged WASDK, unpackaged WASDK, and WinForms projects on Windows 10 22H2. Compare the CredUIPromptForWindowsCredentials behavior and the unhandled-exception stack trace; done means the unpackaged project no longer crashes and shows the credential dialog like the other projects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100