简体   繁体   English

System.IO.FileNotFoundException,Newtonsoft.Json .Net

[英]System.IO.FileNotFoundException, Newtonsoft.Json .Net

I have .NET console application and there is a problem with newtonsoft library. 我有.NET控制台应用程序,并且newtonsoft库有问题。 When I start console application with Visual studio by clicking start button, there is no problem. 当我通过单击开始按钮使用Visual Studio启动控制台应用程序时,没有问题。 Everything is good. 万事皆安。 However, If i try to run myprogram.exe under the obj/debug folder, it gives following error: 但是,如果我尝试在obj / debug文件夹下运行myprogram.exe,则会出现以下错误:

"System.IO.FileNotFoundException: 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'file or compilation, or one of its dependencies. The system can not find the specified file.File Name: 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' Location: Barcode_Form.Cloud_Form.Check_Cloud(String username, String password)" “ System.IO.FileNotFoundException:'Newtonsoft.Json,版本= 9.0.0.0,区域性=中性,PublicKeyToken = 30ad4fe6b2a6aeed'文件或编译,或其依赖项之一。系统找不到指定的文件。文件名:'Newtonsoft .Json,版本= 9.0.0.0,文化=中性,PublicKeyToken = 30ad4fe6b2a6aeed'位置:Barcode_Form.Cloud_Form.Check_Cloud(字符串用户名,字符串密码)“

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;
         }
    }

it gives error check_cloud function. 它提供了错误check_cloud函数。 How can i run myprogram.exe without getting error? 如何运行myprogram.exe而不会出现错误? Thanks in advance. 提前致谢。

Don't run it from the obj\\Debug directory - the obj directory is basically temporary build artefacts. 不要从obj\\Debug目录运行它obj目录基本上是临时构建工件。 Instead, run it from the bin\\Debug directory, where you'll find all the dependencies (in this case Newtonsoft.Json.dll ) are present as well. 而是从bin\\Debug目录运行它,在这里您还将找到所有依赖项(在本例中为Newtonsoft.Json.dll )。

Basically, you can ignore the obj directory in almost all cases - it's extremely rare for it to be relevant. 基本上,您几乎可以在所有情况下都忽略obj目录-很少具有相关性。 The bin directory is the real output folder containing useful results. bin目录是包含有用结果的实际输出文件夹。

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

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