Hugo
Hugo

Reputation: 2444

JSON.NET on Ubuntu Linux

I'm trying to start using JSON.NET for Mono on Linux and MonoDevelop. I found the packages in the repository, so I installed them using sudo apt-get install libnewtonsoft-json-cil-dev libnewtonsoft-json-cil monodoc-newtonsoft-json-manual

I have the following code to test if the installation worked:

using System;
using Gtk;
using Newtonsoft.Json;

namespace jsontest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();

            Car my_car = new Car ();
            string json = JsonConvert.SerializeObject (my_car);

            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();
        }
    }

    public class Car
    {
        public string make;
        public string model;

        public Car()
        {
            make = "ford";
            model = "jalopy";
        }
    }
}

When I try to run the program it gives me the following error: The type or namespace name 'Newtonsoft' could not be found. Are you missing an assembly reference?

Why can't MonoDevelop find the library I installed?

Upvotes: 3

Views: 4283

Answers (1)

Lex Li
Lex Li

Reputation: 63153

After installing it via apt-get,

http://packages.ubuntu.com/trusty/all/libnewtonsoft-json5.0-cil/filelist

This dll is available in Mono GAC, which you should be able to access in MonoDevelop by adding a new reference. This reference must be added manually, or you get the error message.

This is not something "unexpected", as even in Visual Studio if you don't get the references right, the same error message is expected.

Upvotes: 4

Related Questions