【问题标题】:Receiving NotSupportedException with CSCore audio library使用 CSCore 音频库接收 NotSupportedException
【发布时间】:2019-09-20 13:55:38
【问题描述】:

我正在尝试使用在 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

【问题讨论】:

    标签: c# .net unity3d mono


    【解决方案1】:

    最终的原因是,虽然我的脚本运行时版本是 .NET 4.X,但我的 API 兼容性级别仍然设置为 2.0。这意味着 Unity 遗漏了 CSCore 所依赖的必需的 .NET 4.X 依赖项。

    正确配置,从播放器设置访问:

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 2016-09-16
      • 2014-06-28
      • 2012-04-28
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2015-02-02
      相关资源
      最近更新 更多