System.IO.FileNotFoundException Exception while trying to Serialize

  • Thread starter Thread starter Hans Baumann
  • Start date Start date
H

Hans Baumann

Hi everybody,

I get the following message when trying to serialize an object: "Unhandled
Exception: System.IO.FileNotFoundException: File or assembly name XXX.dll or
one of its dependencies, was not found.File name: XXX.dll"

This ocurrs with this code:

Module Module1
Sub Main()

Dim p As MyAssemblyNamespace.MyClass = MyClass.Instatiate()
Dim ser As New XmlSerializer(GetType(Persona))
Dim fs As New FileStream("c:\temp\result.xml", IO.FileMode.Create)

ser.Serialize(fs, p)
fs.Close()

End Sub
End Module

But when I use this other it works fine:

Module Module1
Sub Main()

Dim p As MyAssemblyNamespace.MyClass = MyClass.Instatiate()
Dim ser As New SoapFormatter

Dim fs As New FileStream("c:\temp\result.xml", IO.FileMode.Create)

ser.Serialize(fs, p)
fs.Close()

End Sub
End Module

It also works fine with a class defined in the same assembly...

What am I doing wrong?

Thanks in advance.
 
Hi Vadym,

The dll is on the same directory of the exe if you meant that, (I forgot to
replace GetType(Persona) with GetType(MyClass) to more coherent example).

The fact is why soapformatter works and xmlserializer don't!, does my class
needs to have some requirements to be xml-serizable that soapformatter
doesn't need?
 
Thanks for your help Vadym!!

Finally we found that the problem becomes from shadowed properties, in the
base class they have one type and are r/w but in the derived class the
shadow not only modify the data type, but the r/w declaration...

We're now working in modifing the derived class to avoid the shadows... do
you know if there are another way to make the class serializable, for
example just inserting the <XMLIgnore()> _ attribute on the base (shadowed)
property? Or I has to change the classes and make a massive rebuild?

Thanks in advance!
 
Back
Top