我正在尝试使用CSCore (https://github.com/filoe/cscore)来获得默认的音频端点,并且正在接收一个System.NotSupportedException。我正在用统一NUnit测试框架对此进行测试。奇怪的是,当在编辑器中运行代码时,它会工作,但是生成会收到此异常。有人能解释一下为什么会发生这种事吗?
我正在做的构建是x64,我检查了我正在使用的DLL是否已经为x86和x64构建了。我正在使用1.2.0版本的DLL。测试代码和异常堆栈跟踪如下:
[Test]
public void GetAudioEndpoint_Default_NoException()
{
Assert.DoesNotThrow(delegate ()
{
var deviceEnumerator = new MMDeviceEnumerator();
var device = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
});
}GetAudioEndpoint_Default_NoException (0.039s)
---
Expected: No Exception to be thrown
But was: <System.NotSupportedException: Specified method is not supported.
at (wrapper cominterop) CSCore.CoreAudioAPI.MMDeviceEnumerator+MMDeviceEnumeratorObject..ctor()
at CSCore.CoreAudioAPI.MMDeviceEnumerator.CreateMmDeviceEnumerator () [0x00000] in <b6880cc671004d3aa0cc66420dbddb79>:0
at CSCore.CoreAudioAPI.MMDeviceEnumerator..ctor () [0x00000] in <b6880cc671004d3aa0cc66420dbddb79>:0
at CSCore.Tests.DeviceTests+<>c.<GetAudioEndpoint_Default_NoException>b__0_0 () [0x00001] in ***\DeviceTests.cs:13
at NUnit.Framework.Constraints.ThrowsConstraint+VoidInvocationDescriptor.Invoke () [0x00001] in <59819be142c34115ade688f6962021f1>:0
at NUnit.Framework.Constraints.ThrowsConstraint+ExceptionInterceptor.Intercept (System.Object invocation) [0x0000a] in <59819be142c34115ade688f6962021f1>:0 >
---
at CSCore.Tests.DeviceTests.GetAudioEndpoint_Default_NoException () [0x00001] in ***\DeviceTests.cs:11发布于 2019-08-08 06:33:03
其原因是,尽管我的脚本运行时版本是.NET 4.X,但我的API兼容性级别仍然设置为2.0。这意味着,团结没有CSCore所依赖的所需的CSCore 4.X依赖项。
从播放机设置访问的正确的配置:

https://stackoverflow.com/questions/55945751
复制相似问题