Search code examples
c#.netubuntumonomcs

I am unable to compile a c# application that uses the microsoft.extensions.configuration.configurationbuilder json api with mono mcs under Ubuntu


I am attempting to compile a simple example code snippet that can be found here: but I haven't had any luck to get it to compile without errors.

First, I wrapped the code snippet on the web site into a main function like this:

using System;
using Microsoft.Extensions.Configuration;

internal class Program
{
  static void Main(string[] args)
  {
    IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile(".\appsettings.json", false, true);
    IConfigurationRoot root = builder.Build();

    Console.WriteLine($"Hello, { root["weather"] } world!");
  }
}

My build script:

#!/bin/bash
mcs monotest.cs \
-r:/usr/lib/dotnet/sdk/8.0.103/Microsoft.Extensions.Configuration.dll \
-r:/usr/lib/dotnet/shared/Microsoft.AspNetCore.App/8.0.3/Microsoft.Extensions.Configuration.Abstractions.dll

However, I still get the following error: monotest.cs(10,41): error CS0012: The type System.Object is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (The extra quotes in the error message were removed before pasting here.)

I searched for "System.Runtime" in /usr/lib and found several different instances of this file name:

$ find /usr/lib -name "System.Runtime.dll"
/usr/lib/dotnet/sdk/8.0.103/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll
/usr/lib/dotnet/shared/Microsoft.NETCore.App/8.0.3/System.Runtime.dll
/usr/lib/dotnet/packs/Microsoft.NETCore.App.Runtime.ubuntu.22.04-x64/8.0.3/runtimes/ubuntu.22.04-x64/lib/net8.0/System.Runtime.dll
/usr/lib/dotnet/packs/NETStandard.Library.Ref/2.1.0/ref/netstandard2.1/System.Runtime.dll
/usr/lib/dotnet/packs/Microsoft.NETCore.App.Ref/8.0.3/ref/net8.0/System.Runtime.dll
/usr/lib/mono/4.5-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6.2-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5.2-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5/Facades/System.Runtime.dll
/usr/lib/mono/4.8-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7.2-api/Facades/System.Runtime.dll

I have no idea which one of these to add to my script. I tried a few of these but they just causes yet more errors like: error CS1070: The type System.Object has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly System.Private.CoreLib... etc.

Maybe I need a whole shitload more of these with just the right combo but I was hoping someone would know the answer so I wouldn't have to try them all.

I just want to know if anyone else has tried something like this.

My OS:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:  Ubuntu 22.04.4 LTS
Release:  22.04
Codename: jammy

mono version:

$ mono --version
Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Wed Jun 30 05:34:49 UTC 2021)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
  TLS:           __thread
  SIGSEGV:       altstack
  Notifications: epoll
  Architecture:  amd64
  Disabled:      none
  Misc:          softdebug
  Interpreter:   yes
  LLVM:          supported, not enabled.
  Suspend:       hybrid
  GC:            sgen (concurrent by default)

BTW, if anyone wants to ask "what are you trying to do", here is the answer: nothing specific, I'm just trying to learn something. I saw some code similar to this on a learning web site but I didn't want to go through the hassle of signing up for a Microsoft account just so that I could download Visual Studio Community Edition and run it on my Windows box.

Thanks in advance!


Solution

  • Barring any further information, I believe the right answer is: "Mono is not maintained... use VS Code. Please refer to comments following original question." Switching to a different framework solved my issue. Thanks to @Lex Li for sending me in the right direction.