You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio for Mac中C#项目使用SoundPlayer类报错的解决建议咨询

Fixing the SoundPlayer "Type Not Found" Error in Visual Studio for Mac

Hey there! I've run into this exact issue before when working with SoundPlayer on Mac, so let's get you sorted out quickly.

The error message is telling you exactly what's wrong: SoundPlayer lives in the System.Windows.Extensions assembly, which isn't included by default in most .NET Core/.NET 5+ projects (which is what you're probably using in Visual Studio for Mac). Here's how to fix it step by step:

  • Add the required NuGet package

    1. In your Visual Studio for Mac solution explorer, right-click your project name and select Add > Add NuGet Package...
    2. In the search bar, type System.Windows.Extensions and hit enter. Look for the official package published by Microsoft.
    3. Click Add Package to install it into your project.
  • Verify your using statement
    Once the package is installed, make sure your code includes this at the top:

    using System.Media;
    

    Now the SoundPlayer type should be recognized without errors.

  • Quick test snippet
    If you want to confirm everything's working, try this simple example (replace the file path with a valid WAV file on your Mac):

    var soundPlayer = new SoundPlayer("/Users/yourname/Documents/test.wav");
    soundPlayer.Play();
    

A quick note: This fix applies to .NET Core 3.0+ and .NET 5/6/7/8 projects. If you're using an older .NET Framework project (less common on Mac), you'd instead add a direct assembly reference, but NuGet is the modern and recommended approach here.

内容的提问来源于stack exchange,提问作者Umberto Boldarin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 17:12:50