简体   繁体   中英

Why can't mono C# find System.IO.File with my code?

I am trying to deserialize a very large json file (63mb) by parsing it directly using JSON.Net and StreamReader. I am developing in Ubuntu 18.04 using mono+monodevelop. I need to keep things as portable as I can.

on this page of JSON.Net's documentation it gives an example of how to directly read in a file to deserialize

// deserialize JSON directly from a file
using (StreamReader file = File.OpenText(@"c:\movie.json"))
{
    JsonSerializer serializer = new JsonSerializer();
    Movie movie2 = (Movie)serializer.Deserialize(file, typeof(Movie));
}

So I'm trying to do this

using System;
using System.IO;
using Newtonsoft.Json;

private void LoadJson(string path)
{
    using (StreamReader json_file = File.OpenText(path))
    {
        blah blah
    }
}

however, monodevelop complains with The name 'File' does not exist in the current context

I can't even address it directly with System.IO.File.OpenText

Does anybody know why mono isn't finding System.IO.File?

Found the reason.

Apparently the full .NET API is not available if I create a portable library project. Which kind of bites because I need this code to run on at least MacOS and Windows, but I'll figure something out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM