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

Mono编译C#项目报错CS0012:未引用Object定义的程序集求助

Fixing CS0012 Error When Compiling C# with Mono on Raspbian

Alright, let's tackle this CS0012 error you're hitting. The issue boils down to one simple thing: when you're manually invoking csc with custom references, you're missing the core .NET assemblies that define basic types like Object—specifically System.dll and System.Core.dll.

Here are the steps to fix it:

  • Add core assembly references to your compile command
    Modify your csc call to include -r:System.dll and -r:System.Core.dll right at the start. These are required for any C# code since they contain fundamental types your project depends on. Your updated command should look like this:

    csc -r:System.dll -r:System.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Commands.dll -r:./bin/Release/PublishOutput/Discord.Net.WebSocket.dll -r:./bin/Release/PublishOutput/RedditSharp.dll */*.cs
    
  • Verify Mono's core assembly path (if the first step fails)
    If you still get the error, it might be because csc can't find the core assemblies. Check where Mono stores them using:

    find /usr/lib/mono -name System.dll
    

    You'll get a path like /usr/lib/mono/4.5/System.dll (the version number might vary based on your Mono installation). Add this directory to your command with the -lib: flag:

    csc -lib:/usr/lib/mono/4.5 -r:System.dll -r:System.Core.dll -r:./bin/Release/PublishOutput/Discord.Net.Core.dll ... */*.cs
    
  • Use msbuild instead of manual csc calls (recommended)
    Manually writing csc commands is error-prone. If your project has a .csproj file, let Mono's build system handle dependencies automatically:

    msbuild /p:Configuration=Release YourProjectName.csproj
    

    This will automatically pull in all required core assemblies and your project's NuGet references, so you won't have to manually list every DLL.

The root cause here is that when you specify custom references with -r, csc doesn't automatically include the default core assemblies it normally would. Since Object is defined in System.dll, omitting that reference triggers the CS0012 error.

内容的提问来源于stack exchange,提问作者Tommy Muir

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:08:09