Skip to content
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

"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll #40

Open
EverBS2014 opened this issue Nov 29, 2017 · 22 comments
Open

Comments

@EverBS2014
Copy link

I'm using VS2017 on Windows 10. My WPF application is using the lastest version of this API and has a Realtek onboard sound card

I want to set the volume of the windows setting to max like that:

 CoreAudioDevice defaultCaptureDevice = new CoreAudioController().DefaultCaptureDevice;
 defaultCaptureDevice.Volume = 100;

So far it's working but after the first call my CPU usage is increasing and I constantely receive this message in the VS2017 output window:

"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.NullReferenceException" in AudioSwitcher.AudioApi.CoreAudio.dll
....

It's not stopping. What is wrong?

I'm using AudioSwitcher.AudioApi.CoreAudio. 3.0.0.1 And I have to problem with Win 7 and Win 10

My WPF application has as target framework .NET 4.5.2

@EverBS2014
Copy link
Author

EverBS2014 commented Nov 29, 2017

In the other link you suggested to try the version 4, how can I do that? In NuGet in the VS2017 I see only the version 3.0.0.1

@xenolightning
Copy link
Owner

xenolightning commented Nov 29, 2017

You can include pre-release versions, there's a checkbox at the top of the nuget window in VS.

https://www.nuget.org/packages/AudioSwitcher.AudioApi.CoreAudio/4.0.0-alpha5

You can see all the versions down the bottom.

@EverBS2014
Copy link
Author

Thank you for the link. I still get a few the exception messages when I set the Mic or Speaker to 100 but it's not an endless loop anymore

@xenolightning
Copy link
Owner

The same exception messages?

@EverBS2014
Copy link
Author

Yes I get this message a few times at the same time:

"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll
"System.ArgumentNullException" in AudioSwitcher.AudioApi.CoreAudio.dll

but then it stopps at least and is not printed in an endless loop. Unfortunately my catch (Exception ex) isn't working so I don't see any further informations. I don't know why this is so

@EverBS2014
Copy link
Author

EverBS2014 commented Nov 30, 2017

When I call this:

CoreAudioController Controller = new CoreAudioController();

I get that message 13 times.

this gives me an IOException "System.IO.IOException" in System.dll
defaultCaptureDevice = Controller.DefaultCaptureDevice;

but nevertheless this seems to work
defaultCaptureDevice.SetVolumeAsync(100);

Is it possible to loop through a list of all available speakers and change volume only for a special one? The same for the mirophones? I only want to change the volume of the extermal Mic & Speaker (both USB devices) and not the system devices

@xenolightning
Copy link
Owner

Might be something to do with the realtek device. I can't replicate it. As long as it doesn't break anything I'm not too worried about it, the exceptions are probably being caught, and handled for a reason.

You can try debugging the api project if you want to get more information.

var playback = await Controller.GetPlaybackDevicesAsync(DeviceState.Active);
var specialDevices = playback.Where(x => x.Name.Contains("Special"));

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

I just debugged the error as I too have multiple ArgumentNullExceptions on startup, with the pre-release version.

The error thrown is in the CoreAudioDevice.Internal.cs
Line 115
_audioMeterInformationPtr = Marshal.GetIUnknownForObject(result);
System.ArgumentNullException: 'Value cannot be null. Parameter name: o'

System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Parameter name: o
Source=mscorlib
StackTrace:
at System.Runtime.InteropServices.Marshal.GetIUnknownForObjectNative(Object o, Boolean onlyInContext)
at AudioSwitcher.AudioApi.CoreAudio.CoreAudioDevice.LoadAudioMeterInformation() in C:\Users\morga\Downloads\AudioSwitcher-master\AudioSwitcher.AudioApi.CoreAudio\CoreAudioDevice.Internal.cs:line 115

@xenolightning xenolightning reopened this Oct 29, 2018
@xenolightning
Copy link
Owner

@MorGuux Are you able to share the audio devices you are running in your system? And the version of Windows?

@xenolightning
Copy link
Owner

I wonder if the device doesn't have audio meter support, in which case it's not returning anything from the call to Activate.

And to double check, these exceptions are being handled internally? They aren't an unhandled exception outside of the Api?

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

Windows 10 Pro Version 10.0.16299
Logitech G430 Headset
Oculus Rift
NVIDIA High Definition Audio (TV through HDMI)
Realktek High Definition Audio (Speakers)

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

The exception is handled with a try catch, I just allowed VS to break on ArgumentNullExceptions

@xenolightning
Copy link
Owner

Are there any disabled devices too? I wonder if it's trying to call that on a disabled/disconnected device and then throwing an exception.

There's definitely a nicer way to handle this without throwing an exception too

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

Yeah, one capture device, Stereo Mix. I've not tried with that enabled.

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

There's plenty of disconnected devices, that'll never be connected again ;)

@xenolightning
Copy link
Owner

I wonder if that's what is causing it. It would make sense if it is.

The solution would be to null check the COM Activate() call. I'll push up a commit if you'd like to test it

@MorGuux
Copy link

MorGuux commented Oct 29, 2018

Yeah no problems

@JoshWobbles
Copy link

I too am getting an endless loop of these messages. Is there a fix yet?

@MorGuux
Copy link

MorGuux commented Dec 19, 2018

Try updating to the latest pre-release version instead of the stable version. It doesn't have the endless loop bug, just a few on startup.

@JoshWobbles
Copy link

Yup that fixes the loop bug. It doesn't seem to be specific to hardware persay but more likely driver as I never had this bug when developing my app but I recently did a fresh format and am starting fresh and now have it happen on the same hardware, all that I can imagine is different is some different drivers.

@Jagreaper
Copy link

Hi Guys,

All of a sudden today I starting getting this issue when building new binaries. My binaries built from the exact same commit prior to encountering this problem work fine. Has anyone figured out what is causing the issue?

@jesusvallejo
Copy link

I've got the same issue from time to time, strangely CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; throws the exception but after doing this CoreAudioDevice defaultCaptureDevice = new CoreAudioController().DefaultCaptureDevice; defaultCaptureDevice.Volume = 100; it worked again like it restarted something no clue why mb this info helps to identify why this occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants