question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NAudio device enumeration stops working when combined with AudioSwitcher

See original GitHub issue

With NAudio commit 420e607 or NAudio NuGet version 1.8.5, I receive the following exception, when trying to create a new instance of MMDeviceEnumerator.

System.InvalidCastException: ‘Unable to cast object of type ‘System.__ComObject’ to type ‘NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject’.’

The problem occurs if calling the following code:

var coreAudioController = new AudioSwitcher.AudioApi.CoreAudio.CoreAudioController();
var deviceEnumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

The problem does not occur if calling the following code:

var deviceEnumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

It appears that AudioSwitcher interferes with the creation of the NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject object that NAudio uses for device enumeration.

Since this problem only occurs when using both AudioSwitcher (Version 3.0.0) and NAudio, I don’t know if this is the correct place to report the problem or if I should post it in the AudioSwitcher project.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
snippyycommented, Mar 9, 2022

Same problem but i solved it. The AudioSwitcher.AudioApi.CoreAudio has conflict with NAudio.CoreAudioApi, you need to switch the order. set the AudioSwitcher.AudioApi.CoreAudio under the NAudio.CoreAudioApi.

0reactions
KWBcommented, May 5, 2023

@snippyy Same problem here, but what exactly do you mean by “set the AudioSwitcher.AudioApi.CoreAudio under the NAudio.CoreAudioApi.”

Can you give me a hint please.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Change default audio output device with NAudio
I want to change windows 10 default audio output with NAudio. NAudio has an api to get the default audio endpoint: var enumerator...
Read more >
Keyboard macro to change default audio device
I am hoping to find a quick way to macro a key to switch to headphones, and a key to switch to speakers....
Read more >
[Tutorial] Easily switch audio devices with a single click
I've encounterd this multiple times (e.g. playing a video on Youtube) so sometimes the audio will not switch, but it does indeed work...
Read more >
Automatically change your Audio Input, Output and Volume ...
I recently blogged about an amazing little utility called AudioSwitcher that makes it two-clicks easy to switch your audio inputs and ...
Read more >
Audio Switcher : r/Rainmeter
I made a small skin to remove the need to constantly open my playback devices to switch audio devices. It's a relatively simply...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found