-
Notifications
You must be signed in to change notification settings - Fork 710
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
Crash single-instanced app when drag and drop #9061
Comments
Hi, can you help me understand what you're dragging? I built the DrumPad repo and ran the sample, I don't see any UI content that's draggable. I tried clicking and dragging in the app as well, but it has no effect. |
@JesseCol Yes, there are no UI content that's draggable. I have created DrumPad sample with textblock "Kick 1" that's draggable DrumpPad_link |
Any news on this issue? My company is facing the same problem, we had to disable a drag and drop feature in our app after making it single instanced. Any plan on when will this be fixed? |
@Juansero29 Yes, we're able to repro the crash internally and are investigating a fix. |
The issue appears to be making Main async to support single-instance. Can you make it synchronous instead?
|
It still crashes after making it synchronous as suggested above.
|
All three d&d event handlers are empty in my case:
|
And being registered on ListView as follows:
|
Thanks @mareksm - is yours the DrumPad repro attached earlier to this issue? If it's different, could you attach your repro and/or a crash dump here? |
@Scottj1s @Bondarenko1990 I did this and drag n drop works without crashing (although an error shows for Main that doesn't prevent building: <!-- added to .csproj to get rid of an error message -->
<StartupObject>DrumPad.Program</StartupObject> [STAThread]
static int Main(string[] args)
{
WinRT.ComWrappersSupport.InitializeComWrappers();
bool isRedirect = DecideRedirection();
if (!isRedirect)
{
Microsoft.UI.Xaml.Application.Start((p) =>
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
return 0;
}
private static bool DecideRedirection()
{
bool isRedirect = false;
AppActivationArguments args = AppInstance.GetCurrent().GetActivatedEventArgs();
ExtendedActivationKind kind = args.Kind;
AppInstance keyInstance = AppInstance.FindOrRegisterForKey("randomKey");
if (keyInstance.IsCurrent)
{
keyInstance.Activated += OnActivated;
}
else
{
isRedirect = true;
keyInstance.RedirectActivationToAsync(args).GetAwaiter().GetResult();
}
return isRedirect;
} Note that as with all drag n drop operations, this spams non-fatal native exceptions at a very high rate as reported here #8851:
|
@kmgallahan yes, your solution of making Main sync is what I found to work as well. What error are you seeing for Main? Btw, you can make it void since it's no longer returning a Task. |
@Scottj1s VS reported an error about multiple entry points being defined with a red squigle under |
@kmgallahan I suspect you need to add this to your csproj: |
@Scottj1s I was just running the repo the OP provided which includes this line:
Changing capitalization and cleaning the project didn't matter:
namespace DrumPad
{
#if !DISABLE_XAML_GENERATED_MAIN
/// <summary>
/// Program class
/// </summary>
public static class Program
{
[global::System.Runtime.InteropServices.DllImport("Microsoft.ui.xaml.dll")]
private static extern void XamlCheckProcessRequirements();
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.UI.Xaml.Markup.Compiler"," 3.0.0.2306")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.STAThreadAttribute]
static void Main(string[] args)
{
XamlCheckProcessRequirements();
global::WinRT.ComWrappersSupport.InitializeComWrappers();
global::Microsoft.UI.Xaml.Application.Start((p) => {
var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
}
#endif |
In my case (C++ app) adding this to WinMain: winrt::init_apartment(winrt::apartment_type::single_threaded); fixed D&D crash issue. Everything else, including single-instance code in OnLaunched remain unchanged. |
Closing this issue as it appears that everyone posting here has found their solution/workaround. |
Discussed in microsoft/WindowsAppSDK#3936
Originally posted by Bondarenko1990 November 3, 2023


I remade the application according to this example Making the app single-instanced (Part 3)
Windows App SDK 1.4.231008000
And when I do a drag the grid control I get a crash:
Event Viewer logs:
The text was updated successfully, but these errors were encountered: