microsoft / MIDI

Windows MIDI Services
MIT License
300 stars 24 forks source link

[BUG] Making Midi2 API calls causes COM Exception #342

Closed simonbosley closed 4 months ago

simonbosley commented 4 months ago

Making calls to the Windows.Devices.Midi2 library causes COM Exception.

I installed Windows.MIDI.Services.Developer.Preview.5.x64.1.0.24066.2126.exe also in my code examples I downloaded the NuGet package and successfully installed it as part of my solution. I've also tried manually registering the MIDI2 DLL but that wasn't successful. Not sure what step I'm missing here, probably something simple I haven't done yet.

To Reproduce The simplest way to reproduce the error is to run any command in Microsoft Windows MIDI Services Console after installation:

C:\Users\joebloggs>midi enum ump

Microsoft Windows MIDI Services Console

Error: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))

Also, if I make calls to the library from code I get the following output:

Exception: System.Runtime.InteropServices.COMException (0x80040154): Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at WinRT.ActivationFactory.Get(String typeName)
   at Windows.Devices.Midi2.MidiVirtualEndpointDeviceDefinition.get__objRef_global__Windows_Devices_Midi2_MidiVirtualEndpointDeviceDefinition()
   at Windows.Devices.Midi2.MidiVirtualEndpointDeviceDefinition..ctor()
   at SSL.MidiServer.Connection.OpenConnection() in C:\Code\WindowsMidiServices\Source\MidiServer\Connection.cs:line 19

Screenshots

image

Installer Name or Version Windows.MIDI.Services.Developer.Preview.5.x64.1.0.24066.2126.exe

Desktop

simonbosley commented 4 months ago

I tried copying the Windows.Devices.Midi2.dll library to the following directories on my system:

C:\Windows\System32 C:\Windows\SysWOW64

This fixed the error appearing in the Microsoft Windows MIDI Services Console.

In Visual Studio 2022 I also need to specify x64 target only, (x86 won't work, as I think it's not supported with the preview).

This is all working now!

simonbosley commented 4 months ago

Re-opening, as I suppose I thought these DLLs are installed into the System folders with the Windows.MIDI.Services.Developer.Preview.5.x64.1.0.24066.2126.exe installer.

Psychlist1972 commented 4 months ago

Hi Simon. You don't want to manually register anything or copy files to any other directories.

Please remove the extra copies, and then uninstall the full installer via the Windows Settings app. Then Reinstall via the exe installer. The files get installed under program files \ Windows MIDI

WinRT types need activation entries that point to the implementation DLL. For the dev previews up to 5, we stuff them in the registry for you.

I know this installer has worked for many folks. Is there anything specific/special we should know about your system?

Pete

Psychlist1972 commented 4 months ago

Also please note that the code in main right now is not compatible with dev preview 5. The namespaces and delivery method have changed (see Discord for a note on this).

Psychlist1972 commented 4 months ago

This is where the WinRT system-wide activation entries live

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId

It's a protected key.

MusicMaker commented 4 months ago

Had this same error suddenly on a system that worked fine after upgrading to Canary 1000.26217.5000.0. Ran "Repair" from the service installation .exe, did not work Uninstalling from add/remove programs, then running the exe install again, worked

Before and after "Repair":

Microsoft Windows MIDI Services Console

Pinging MIDI service 20 times... Ping test failed: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)) C:\Windows\System32>midi service ping

After reinstalling:

Microsoft Windows MIDI Services Console

Pinging MIDI service 20 times...

Count 20 responses Total 10186 clock ticks Average 509 clock ticks Average 50.9 microseconds Average 0.0509 milliseconds

simonbosley commented 4 months ago

Hi All,

Thanks for your help!

I removed the manually copied DLLs and after un-installing and re-installing Windows.MIDI.Services.Developer.Preview.5.x64.1.0.24066.2126.exe everything started working again.

I think what happened on my system was that I had upgraded from Win 10 to Win 11 after installing Windows.MIDI.Services.Developer.Preview.5.x64.1.0.24066.2126.exe. Maybe the class registrations were removed during the Windows upgrade? It's the only thing I can think of that might have happened.

Regards,

Simon.

Psychlist1972 commented 4 months ago

That's an important detail. Because of how the WinRT registration is done for Dev Previews through v5 (it's a known unsupported approach), they don't survive an OS upgrade. When you have an insider or other upgrade, uninstall and reinstall the full package.