1

In my case I have one project which has one console project(.Net Framework 4.7.2) and one Class library project (.Net standard 2.0). I am calling class library method which using "Newtonsoft.Json" from console app, and I receive a runtime error below:

System.IO.FileNotFoundException:" 'Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.'"

Error message

Console project code:

using TestSdk;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ConnectWeb obj = new ConnectWeb("");
            string pin = obj.test("test");
        }
    }
}

Class library code:

using Newtonsoft.Json;

namespace TestSdk
{
    public class ConnectWeb
    {
        public string test(string testStr)
        {            
            return JsonConvert.DeserializeObject<string>(testStr);
        }
    }
}
Carsten
  • 11,287
  • 7
  • 39
  • 62
  • 1
    Does this answer your question? [How to resolve this System.IO.FileNotFoundException](https://stackoverflow.com/questions/22774135/how-to-resolve-this-system-io-filenotfoundexception) – funie200 Jul 15 '20 at 06:49
  • No @funie200 , that is diffrent than my issue. – Shridhar Mole Jul 15 '20 at 06:59
  • Just a guess are u using the different versions newtonsoft library in both the projects? – MBB Jul 15 '20 at 07:02
  • Does the Newtosoft.dll get copied to your console project build destination? – mcjmzn Jul 15 '20 at 07:03
  • If you could show the two project files, that would make it a lot easier to help you. Basically we should be able to reproduce the problem for ourselves. – Jon Skeet Jul 15 '20 at 07:04
  • (My *guess* is that you're using an "old-style" project file for the console app, and that if you change it to an SDK-style project file, that will resolve the issue due to the different handling of transitive dependencies, but that's only a guess at this point.) – Jon Skeet Jul 15 '20 at 07:05
  • add the [json package to the console application, too](https://stackoverflow.com/a/60876457/1466046) – magicandre1981 Jul 15 '20 at 14:08
  • But why do you have to add the json package to the console application as well? – tnk479 Jan 13 '22 at 05:14

0 Answers0