XmlSerializer.Deserialize, Method not found

I am deserializing from an XML file to a C# .NET 1.1 class in a plugin for ACT!2006. On my development machine (of course) the deserialization works fine. On the end-user machine an exception is thrown during XmlSerializer.Deserialize saying that a setter method is not found. If I remove one property field, the next will throw an exception. Here's an example of the exception text:

There is an error in the XML document.
Method not found: Void MyAssembly.MyClass.set_MyField(System.String).
Stack Trace:    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
   at MyNamespace.MyXmlSerializer.Read(String fn, Type type) in c:\...\myxmlserializer.cs:line 37
   at ...

Both computers are Windows XP  running .NET 1.1 SP1. My Dev is SP2, the Target is SP3. Both are using System.XML Version 1.0.5000.0.

I initially had some issues with UTF-8 vs UTF-16 encoding of these files. I believe I solved that by saving the files with a proper encoding from Visual Studio.

If both machines are using the same version of the framework, why would one fail to find the method and the other find it just fine? Maybe it's one of those screwy Xml Serialization errors and has something to do with permissions on the Temp directory?

I've been banging my head against this for about 8 hours now.

Thanks Anybody!

// the serialization routines
public static void Write(string fn, object o)
	XmlSerializer ser = new XmlSerializer( o.GetType());
	System.Text.StringBuilder sb = new System.Text.StringBuilder();
	System.IO.StringWriter sw = new StringWriter(sb);
	ser.Serialize( sw, o);
	XmlDocument doc = new XmlDocument();
	doc.LoadXml( sb.ToString() );
public static object Read(string fn, Type type)
	XmlDocument doc = new XmlDocument();
	//Assuming doc is an XML document containing a serialized object and objType is a System.Type set to the type of the object.
	XmlNodeReader reader = new XmlNodeReader(doc.DocumentElement);
	XmlSerializer ser = new XmlSerializer(type);
	object obj = ser.Deserialize(reader);
	// Then you just need to cast obj into whatever type it is eg:
	return obj;
// the class to be deserialized (in VB.NET)
Public Class MyClass
    Private _MyField As String
    Public Property MyField() As String
            Return _MyField
        End Get
        Set(ByVal Value As String)
            _MyField = Value
        End Set
    End Property
    ' ... other fields and methods
End Class

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cod3monk3yincAuthor Commented:
To clarify, dev machine is XP SP2 with .NET 1.0, 1.1, and 2.0 installed, target machine is XP SP3 with only .NET 1.1 installed. The XML file to be deserialized is shown in the snipped below.

I've coded the XML file by hand. If I create a new object, then Serialize it to disk and then immediately Deserialize it to another object, everything works fine (on both machines). It seems to be this hand-crafted XML file that I'm having problems with.

<?xml version="1.0" encoding="utf-8" ?>
<MyClass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Open in new window

cod3monk3yincAuthor Commented:
Ok, this is interesting.

When I made a TEST APPLICATION that did serialize/deserialize everything worked fine.

When I run from ACT!2006, I am unable to serialize. This is different from what I spoke(wrote) earlier. Forgive me, I'm tired! I'm attaching the dump from my attempt to Serialize a new instance of my class during the OnLoad routine of the plugin.

The target machine is running without a password. I right clicked the shortcut that starts the application, and went to Shortcut > Advanced and checked [x] Run with different credentials. After clicking the shortcut, I unchecked [ ] Protect my computer and data from unauthorized program activity. This changed nothing. The user is an Administrator on the computer.

Starting to get very lost here...

OnLoad Exception: 
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidCastException: Specified cast is not valid.
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_MyClass(Object o)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
   at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
   at MyXmlSerializer.Write(String fn, Object o) in c:\...\myxmlserializer.cs:line 20
   at ACTPlugIn.Class1.OnLoad(ActApplication App) in C:\..\ActPlugin\Class1.vb:line 263

Open in new window

There are some limitations with the XmlSerializer, which are described here: http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx. It also discusses your error.

What I miss in your code is the Serializable attribute in the class that needs to be serialized. Without it, only the base classes will be serialized. Use your code like this:

// the class to be deserialized (in VB.NET)
<Serializable()> _
Public Class MyClass
    Private _MyField As String
    Public Property MyField() As String
In addition, you may have run into a bug that has been reported by Microsoft and affects all .NET 1.1 installations. The report of the bug is here: http://support.microsoft.com/kb/814187, including a workaround.
I understand that this is a very old question. However, it is quite likely you still have this issue or that people running into the same issue require a solution. Which is why I posted.

-- Abel --

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.