XmlSerializer.Deserialize, Method not found

Posted on 2008-11-11
Last Modified: 2013-11-07
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

Question by:cod3monk3yinc

    Author Comment

    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="" xmlns:xsi="">

    Open in new window


    Author Comment

    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

    LVL 39

    Accepted Solution

    There are some limitations with the XmlSerializer, which are described here: 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:, 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 --

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now