使用 CSCore 音频库接收 NotSupportedException
Receiving NotSupportedException with CSCore audio library
我正在尝试在 Unity 中使用 CSCore (https://github.com/filoe/cscore) 运行 获取默认音频端点,我收到了 System.NotSupportedException
。我正在使用 Unity NUnit 测试框架对此进行测试。奇怪的是,当 运行 编辑器中的代码正常工作时,构建会收到此异常。有人可以解释为什么会这样吗?
我正在构建的是 x64,我检查过我正在使用的 DLL 是为 x86 和 x64 构建的。我正在使用 1.2.0 Release 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
原因最终是虽然我的脚本运行时版本是 .NET 4.X,但我的 API 兼容性级别仍然设置为 2.0。这意味着 Unity 遗漏了 CSCore 所依赖的必需的 .NET 4.X 依赖项。
正确 配置,从播放器设置访问:
我正在尝试在 Unity 中使用 CSCore (https://github.com/filoe/cscore) 运行 获取默认音频端点,我收到了 System.NotSupportedException
。我正在使用 Unity NUnit 测试框架对此进行测试。奇怪的是,当 运行 编辑器中的代码正常工作时,构建会收到此异常。有人可以解释为什么会这样吗?
我正在构建的是 x64,我检查过我正在使用的 DLL 是为 x86 和 x64 构建的。我正在使用 1.2.0 Release 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
原因最终是虽然我的脚本运行时版本是 .NET 4.X,但我的 API 兼容性级别仍然设置为 2.0。这意味着 Unity 遗漏了 CSCore 所依赖的必需的 .NET 4.X 依赖项。
正确 配置,从播放器设置访问: