Slion / VirtualDesktop

C# wrapper for the Virtual Desktop API on Windows 11.
MIT License
21 stars 9 forks source link

Windows build 22621.2361 not supported #15

Closed mzomparelli closed 10 months ago

mzomparelli commented 1 year ago

I don't have time to test right now, but it did break my app that is not using this repo but is using the vd interfaces. I will investigate further tonight.

SemperFu commented 1 year ago

I just started using this today on Win11 22621.2361 and can't get it to fire with the just the notification for testing.

VirtualDesktop.CurrentChanged += (_, args) => Console.WriteLine($"Switched: {args.NewDesktop.Name}");

mzomparelli commented 1 year ago

I'm downloading the Win11 updates to test further. I don't use Win11 much so I'm a little behind. I may not get this resolved until this weekend.

Slion commented 1 year ago

Two breakages in a matter of weeks 🥳 Microsoft is on top of its game 😁 I'm not running that version yet.

mzomparelli commented 1 year ago

I get an AccessViolationException when calling IVirtualDesktopManagerInternal.GetCurrentDesktop()

It's not clear why yet. The GUID is the same and all the signatures appear to be the same. I must be missing something so I'll keep digging.

mzomparelli commented 1 year ago

22621.2361.txt

Here is the dump. Maybe you can see what I'm missing

3dtoall commented 1 year ago

Thanks a lot for your efforts on this one. You think there'll be solution for this version? Thanks again!

mzomparelli commented 1 year ago

Almost certainly we'll resolve this. When is the better question. That comes down to time and dedication.

I think I might have found the change causing the issue. It appears that IApplicationViewCollection has been modified. This would explain the AccessViolation from the other interface. I have the updated interface methods but I'm still trying to find the guid to see if that changed. I suspect it has.

Slion commented 1 year ago

Is that dump coming from your reverse engineering tool? Would it make sense to commit them in the repository for future reference? Thus it would be really easy to check the differences between versions.

mzomparelli commented 1 year ago

That dump is from a python script and yes it does make sense to be included in this repo. IApplicationViewCollection was not being dumped. It is now. Let me iron out this issue and then I'll cleanup the python script and add it. I also use IDA to get the guids for IApplicationView and IApplicationViewCollection becuse I can't seem to get to them via the py script.

mzomparelli commented 1 year ago

@Slion One thing I can say for sure, your idea to switch to including the minor version was indeed needed. Two separate breaking changes in the same major version.

mzomparelli commented 1 year ago

So IApplicationViewCollection has not changed. Nothing has changed as far as I can tell, but something surely has.

I think somehow memory is getting corrupt when IVirtualDesktopNotification.VirtualDesktopSwitched() is called. We don't implement this, we only define it in the interface.

This repo is hard to debug. Maybe it's just that I don't know how to debug it properly, but with my other implementation of this I can debug more easily. What I am seeing is that everything works fine up until VirtualDesktopSwitched is called. After that, any calls to IVirtualDesktopManagerInternal get an AccessViolationException.

Slion commented 12 months ago

Weirdly it seems to be working fine on 22621.2428, for the functions I have been using anyway.

SemperFu commented 12 months ago

I just tried it on 22621.2428. Made the function as basic as possible.

 public static void Main()
        {
            // Ensure Virtual Desktop is available on this system.
            if (!VirtualDesktop.IsSupported)
            {
                Console.WriteLine("Virtual Desktop is not supported on this system.");
                return;
            }

            VirtualDesktop.Configure();

            // Notification of desktop switching
            VirtualDesktop.CurrentChanged += (_, args) =>
            {
                Console.WriteLine($"Switched: {args.NewDesktop.Name}");
            };

            Console.ReadKey();
        }

The program '[33612] ' has exited with code 3221225477 (0xc0000005) 'Access violation'.

Slion commented 12 months ago

I do not call Configure nor IsSupported, at least not explicitly from my code. I do use that CurrentChanged callback and it seems to be working fine. What I do first is just call VirtualDesktop.Current.Id in a try block and if it throws an exception I know it is not supported. Though looking at the code for Current it should be exactly the same as your sample, it calls IsSupported first and then does the same as Configure. So I'm not sure why it would work on multiple machines for me but not for you. The only think I can think of is that you might be trying to use it earlier than me in the life time of your application.

Slion commented 12 months ago

Just tested the VirtualDesktop.Showcase app in debug mode from Visual Studio and it works fine too.

SemperFu commented 12 months ago

This is the entire program

using System.Windows;
using WindowsDesktop;

namespace VirtualDesktopMute
{
    public class Program
    {
        [STAThread]
        public static void Main()
        {

            try
            {
                var CID = VirtualDesktop.Current.Id;
                Console.WriteLine("Current ID : " + CID);
            }
            catch
            {
                MessageBox.Show("Virtual Desktop is not supported on this system.");
                return;
            }

            VirtualDesktop.CurrentChanged += (_, args) =>
            {
                Console.WriteLine($"Switched: {args.NewDesktop.Name}");
            };

            Console.ReadKey();
        }
    }
}

It outputs the ID. I switch desktops and back I get a million lines that show

at WindowsDesktop.Interop.Build22621.VirtualDesktopNotification.VirtualDesktopSwitched()
at WindowsDesktop.Interop.Build22621.VirtualDesktopNotification.VirtualDesktopSwitched()

Then bin\Debug\net7.0-windows10.0.19041.0\VirtualDesktopMute.exe (process 37364) exited with code -1073741819.

'VirtualDesktopMute.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Private.CoreLib.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded '\bin\Debug\net7.0-windows10.0.19041.0\VirtualDesktopMute.dll'. Symbols loaded.
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Runtime.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'd:\apps\microsoft visual studio\2022\preview\common7\ide\commonextensions\microsoft\hotreload\Microsoft.Extensions.DotNetDeltaApplier.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.IO.Pipes.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Linq.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Collections.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Console.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Threading.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Runtime.InteropServices.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Threading.Overlapped.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Security.AccessControl.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Security.Principal.Windows.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Security.Claims.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Runtime.Loader.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded '\bin\Debug\net7.0-windows10.0.19041.0\VirtualDesktop.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Collections.Concurrent.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\PresentationFramework.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\Microsoft.Win32.Registry.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Memory.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\PresentationCore.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\WindowsBase.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\DirectWriteForwarder.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Runtime.Extensions.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Diagnostics.Debug.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Runtime.CompilerServices.VisualC.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\Microsoft.Win32.Primitives.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Collections.NonGeneric.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Threading.Thread.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Diagnostics.TraceSource.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Collections.Specialized.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.ComponentModel.Primitives.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\System.Configuration.ConfigurationManager.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Private.Uri.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Xml.ReaderWriter.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Private.Xml.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Net.WebClient.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.ComponentModel.EventBasedAsync.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Text.Encoding.Extensions.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\7.0.12\UIAutomationTypes.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Diagnostics.Process.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Text.RegularExpressions.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Reflection.Metadata.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.IO.MemoryMappedFiles.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.12\System.Collections.Immutable.dll'. 
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded '\AppData\Local\slions.net\VirtualDesktop\assemblies\VirtualDesktop.10.0.22621.2428.generated.dll'. Module was built without symbols.
'VirtualDesktopMute.exe' (CoreCLR: clrhost): Loaded '\bin\Debug\net7.0-windows10.0.19041.0\WinRT.Runtime.dll'. 
The program '[37364] .exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.
Slion commented 12 months ago

Are you having that same issue with the show case application?

SemperFu commented 12 months ago

Yes, Crashes right when I switch. Does output to debug the switch.

Switched: Main -> Back
The program '[38644] VirtualDesktop.Showcase.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.
Slion commented 11 months ago

So weird guys, I could not reproduce that bug on two different machines running 22621.2428.

3dtoall commented 11 months ago

I also get: The program '[16620] VirtualDesktop.Showcase.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'. with: Windows 22621.2506

3dtoall commented 11 months ago

I downloaded the zip from https://github.com/Slion/VirtualDesktop , build the dll's and tested the showcase... I notice it creates/switch desktops and after that the error and app close happens... Maybe a workaround can be to have it separated from main code so when it crashes at least won't close main code, because afterall the full operation wanted is successful before the access violation crash

Slion commented 11 months ago

Now I have that crash with 22621.2506. The desktop switch happens then it crashes.

3dtoall commented 11 months ago

Not sure if it's possible to avoid the error stopping the code with a "try/catch", because the task (create and or switch) is successfully complete before the crash

Slion commented 11 months ago

@3dtoall Good thinking but that's unlikely to be that simple. I don't think you can catch those access violations.

3dtoall commented 11 months ago

I see, last idea, Dirty/Workaround: What if it's like a command line with parameters separated app so we call it with parameters to switch/create so if internally crash it doesn't matter because the task is complete anyway and the main app can call it again if needed. I know it's not elegant solution, just to bring some ideas. Thank you for your efforts on this one.

mzomparelli commented 11 months ago

The access violation implies one of the interfaces is wrong. It could be as simple as being out of order or the data type in the signatures. I spent hours a few weeks ago trying to find any differences with no luck. I'm on PTO the week of 2023-11-13 and I'll get back into this then. I'll try to make time to get in before that.

salehio commented 11 months ago

Is it possible to enumerate all the interfaces that we need to check that could have changed? @mzomparelli ruled out IApplicationViewCollection, but what else is there?

patriq commented 11 months ago

Hey guys, after a recent windows update I started experiencing the same crash after the "action" is completed. Windows 22621.2715 is the build.

Also tried the showcase, and to my surprise switching works but crashes right after:

The program '[11948] VirtualDesktop.Showcase.exe' has exited with code 3221225477 (0xc0000005) 'Access violation'.

Thanks @mzomparelli for looking into it 👍

AkazaRenn commented 11 months ago

I believe it's the part that detects virtual desktop switch and sends events out got changed by Microsoft, everything else I used seems ok.

AkazaRenn commented 11 months ago

Made a fix here: https://github.com/Slion/VirtualDesktop/pull/18 Does anyone mind giving it a try?

Dexterously commented 11 months ago

image

Got these compiling errors, but once fixed,.... it works great. It just needs those methods under EventProxy.cs

patriq commented 11 months ago

Works great thanks @AkazaRenn !! For those wondering how to disable the desktop switching notification they added, check: https://superuser.com/questions/1800216/windows-11-hide-remove-virtual-desktop-indicator-while-changing