简体   繁体   English

为什么单声道C#找不到我的代码System.IO.File?

[英]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. 我试图通过使用JSON.Net和StreamReader直接解析它来反序列化一个非常大的json文件(63mb)。 I am developing in Ubuntu 18.04 using mono+monodevelop. 我正在使用mono + monodevelop在Ubuntu 18.04中开发。 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 在JSON.Net文档的这个页面上 ,它提供了一个如何直接读入文件以反序列化的示例

// 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 但是,monodevelop抱怨The name 'File' does not exist in the current context

I can't even address it directly with System.IO.File.OpenText 我甚至无法使用System.IO.File.OpenText直接解决它

Does anybody know why mono isn't finding System.IO.File? 有谁知道为什么mono没有找到System.IO.File?

Found the reason. 找到原因。

Apparently the full .NET API is not available if I create a portable library project. 显然,如果我创建一个可移植的库项目,则无法使用完整的.NET API。 Which kind of bites because I need this code to run on at least MacOS and Windows, but I'll figure something out. 因为我需要这个代码至少在MacOS和Windows上运行,所以会有哪些叮咬,但我会想出办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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