【问题标题】:System.IO.FileNotFoundException, Newtonsoft.Json .NetSystem.IO.FileNotFoundException,Newtonsoft.Json .Net
【发布时间】:2017-05-05 11:51:48
【问题描述】:

我有 .NET 控制台应用程序,但 newtonsoft 库有问题。当我通过单击开始按钮使用 Visual Studio 启动控制台应用程序时,没有问题。一切都是好的。但是,如果我尝试在 obj/debug 文件夹下运行 myprogram.exe,则会出现以下错误:

"System.IO.FileNotFoundException: 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'文件或编译,或其依赖项之一。系统找不到指定的文件。文件名:'Newtonsoft.Json,版本=9.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed' 位置:Barcode_Form.Cloud_Form.Check_Cloud(String username, String password)"

private void button_login_Click(object sender, EventArgs e)
    {
        label_response.Text = "Baglaniyor...";
        //Make buttons not clickable until the result of login trial
        Button_status(false);
        try {
            if (textbox_password.Text != "" && textbox_id.Text != "")
            {
                //Check the cloud if the user is valid or not
                if (Cloud_Form.Check_Cloud(textbox_id.Text, textbox_password.Text) == true)
                {

                    user_id = textbox_id.Text;
                    user_pass = textbox_password.Text;
                    Network_Form network = new Network_Form();
                    Network_Form.network.Show();
                    Network_Form.network.Enabled = true;
                    this.Hide();
                    this.Enabled = false;
                    Xml_Write_Login();
                }
            }

        } 
        catch(Exception ex)
        {
            this.Enabled = true;
        }
        label_response.Text = "";
        Button_status(true);
    }

public static bool Check_Cloud(string username, string password)
    {
         try {
             string jsonstr2 = Call_Reseller_JsonStr(username, password);
             JObject outp = JObject.Parse(jsonstr2);
             string return_code = (string)outp["code"]; //check if it is successful or not
            if (return_code.Equals("200") == true)
             {
                 return true;
             }
             else {
                Console.Write("false");
                return false;
             }
         }
         catch(Exception ex)
         {
             return false;
         }
    }

它提供了错误 check_cloud 功能。如何运行 myprogram.exe 而不会出错?提前致谢。

【问题讨论】:

  • 给我们看看你的代码!!

标签: c# .net visual-studio json.net


【解决方案1】:

不要从 obj\Debug 目录运行它 - obj 目录基本上是临时构建工件。相反,从bin\Debug 目录运行它,您将在该目录中找到所有依赖项(在本例中为Newtonsoft.Json.dll)。

基本上,在几乎所有情况下,您都可以忽略obj 目录——它非常罕见。 bin 目录是包含有用结果的真正输出文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    • 2016-06-27
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    相关资源
    最近更新 更多