Dotnet Core 3.1 & CSC: Predefined type 'System.Object' is not defined or imported

Viewed 408

I have to extend an in-house build system to compile C# files targeting .Net Core 3.

As of now, the system is capable of processing source sets, references, and lib directories, where it generates the following command:

"C:\Program Files\dotnet\dotnet.exe" exec "C:/Program Files/dotnet/sdk/3.1.300/Roslyn/bincore/csc.dll" -nologo -target:library "-lib:C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4" -r:netstandard.dll C:/Users/kirsch/Documents/Repositories/ComplexProject/lib/csharp/native/VeryComplexLogic.cs -out:C:/Users/kirsch/Documents/Repositories/ComplexProject/default/ComplexProject.net.626a237a/ComplexProject.net.dll

Sadly, this fails with the following error:

error CS0518: Predefined type 'System.Object' is not defined or imported

I tried to search for a solution. The proposed solutions either suggested something, that was not related (like deleting some generated directory), or suggested to add references. Pursuing the latter, I added the following references:

  • netstandard.dll
  • mscorlib.dll
  • System.dll
  • System.Core.dll

Referencing these did, however, not solve the problem.

To conclude my question: Which reference am I missing?

If it's not a reference, what else am I missing then?

1 Answers

You need System.Runtime.dll.

Please note that just providing

/lib:"C:/Program Files/dotnet/shared/Microsoft.NETCore.App/3.1.4"

is not enough. This is only a directory where the referenced assemblies will be searched for. But you still need to provide each particular referenced assembly by the /reference (or /r) option:

/reference:mscorlib.dll /reference:netstandard.dll /reference:System.Collections.dll /reference:System.Console.dll

... etc

MSBuild or dotnet.exe do this for you.

Related