0

In an effort to resolve this problem, I've found many posts that explain this behavior is actually expected. However, I've also found 'Using Microsoft XML Serializer Generator on .NET Core' which provides the steps to generate an associated 'serializer' dll alongside the target dll. Using these steps, I was able to build the XmlSerializer dll, but, it still throws an exception stating it cannot find the dll even though it's in the same folder as the associated target dll.

I'm using the following code to serialize the class.

try
{
    XmlSerializer serializer = new XmlSerializer(typeof(Rss));
    // Create an XmlTextWriter using a FileStream.
    fs = new FileStream(_feedpath, FileMode.Create);
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Encoding = Encoding.UTF8;
    settings.Indent = true;
    settings.DoNotEscapeUriAttributes = false;
    writer = XmlWriter.Create(fs, settings);

    // Serialize using the XmlTextWriter.
    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
    ns.Add("", "");
    serializer.Serialize(writer, mrss, ns);
    writer.Close();
    fs.Close();

    originalMrss = mrss.Clone();
}
catch (FileNotFoundException excp)
{
    //  Trap the XmlSerializer not found message.
    if (!excp.Message.Contains("XmlSerializer"))
        success = false;
}

When the code throws the exception, nothing is written out to the XML file.

My true goal is to serialize a class to XML. I haven't been able to find a way to do this without encountering the above error.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
rrirower
  • 4,338
  • 4
  • 27
  • 45
  • 1
    Please show relevant code – Charlieface May 11 '23 at 21:08
  • 1
    _My true goal is to serialize a class to XML_: The following may be of interest: https://stackoverflow.com/a/73640395/10024425 – Tu deschizi eu inchid May 11 '23 at 23:56
  • I was able to resolve this by using the solution proposed by Frosty @ [XmlSerializer giving FileNotFoundException at constructor](https://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor#1177040) – rrirower May 13 '23 at 14:05

0 Answers0