0

I am getting System.IO.FileNotFoundException and I am not sure why. It looks

System.IO.FileNotFoundException: 'Could not load file or assembly 'Pixelation Tool.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'

public static T LoadFromFile<T>(string name) where T : IName
{
    XmlSerializer xml = new XmlSerializer(typeof(T));
    (new FileInfo(filePath + name + ".mox")).Directory.Create();
    FileStream fs = new FileStream(filePath + name + ".mox", FileMode.OpenOrCreate);
    try
    {
        return (T)xml.Deserialize(fs);
    }     
    finally
    {
        fs.Close();
    }
}

it is calling it at the 1st line :

XmlSerializer xml = new XmlSerializer(typeof(T));
Sach
  • 10,091
  • 8
  • 47
  • 84
Nia2
  • 25
  • 4
  • 2
    Well, did you check to see if there is a file named `Pixelation Tool.XmlSerializers` in your references or deployed directory? – Igor Oct 24 '19 at 20:59
  • You are probably missing a reference, or missing a package. Check your nuget dependencies and your project references. – Espen Oct 24 '19 at 21:37
  • Igar it is there – Nia2 Oct 25 '19 at 13:23
  • Does this answer your question? [XmlSerializer giving FileNotFoundException at constructor](https://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor) – Wai Ha Lee Apr 26 '23 at 16:47

1 Answers1

0

I guess this is a simple misunderstood made by visual studio intellisense “add using” helper.

Try to specify the full namespace, just like this:

System.Xml.XmlSerializer xml = new System.Xml.XmlSerializer(typeof(T))

and eventually remove references and usings to Pixelation Tools

T-moty
  • 2,679
  • 1
  • 26
  • 31
  • it does not know what System.Xml.XmlSerializer is... I am getting an error – Nia2 Oct 25 '19 at 13:30
  • Ok, you need to add a reference to System.Xml assembly, so: in the solution explorer right click on the project, then Add->Add reference, then scroll down to System.Xml and select it, then click OK – T-moty Oct 25 '19 at 13:39