XmlSerializer FileNotFoundException
Date Published: 21 May 2009
Recently a buddy of mine ran into this problem trying to serialize a custom object. The error message he got back was the ever-so-helpful
An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in mscorlib.dll Additional information: File or assembly name uwzg3j_w.dll, or one of its dependencies, was not found.
After a fair bit of research, he found the answer, which I thought would be worth sharing here for anybody else who’s stuck trying to figure this out. The class already had the [Serializable] attribute on it, but of course the issue was with one of the members. One way to help diagnose these kinds of issues is with the XmlSerializerPreCompiler(GUI version).
Finally, the thing that came to the rescue was being able to see the files that .NET creates, so you can open them up in Notepad and easily see just what the problem is. In this case, the root cause was the lack of an [XmlIgnore] attribute on a static property, but the trick to being able to view the files is to turn off automatic deletion of temporary files, using this configuration script:
<span style="color: #0000ff"><?</span><span style="color: #800000">xml</span> <span style="color: #ff0000">version</span><span style="color: #0000ff">="1.0"</span> <span style="color: #ff0000">encoding</span><span style="color: #0000ff">="utf-8"</span> ?<span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">configuration</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">system.diagnostics</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">switches</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"><</span><span style="color: #800000">add</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="XmlSerialization.Compilation"</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">="4"</span> <span style="color: #0000ff">/></span>
<span style="color: #0000ff"></</span><span style="color: #800000">switches</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">system.diagnostics</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></</span><span style="color: #800000">configuration</span><span
Category - Browse all categories
About Ardalis
Software Architect
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.