mdelpeix
mdelpeix

Reputation: 187

List<Object> Serialization work on dev computer but failed on other computers

I use this function to serialize in xml file a collection of object.

    public void SerializeEnvironment()
    {            
            if (xs == null) xs = new XmlSerializer(typeof(IList<Classes.Environment>));

            using (StreamWriter wr = new StreamWriter(ConfigFilePath))
                xs.Serialize(wr, Environments);            
    }

The program works perfectly on my dev machine. But when i make deployment on other computers, the program failed on the serialization method with this error :

System.InvalidCastException: [A]System.Collections.Generic.List1[Product] cannot be cast to [B]System.Collections.Generic.List1[Product]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterList1.Write3_ArrayOfEnvironment(Object o)

I test many things to resolve but without success. Thanks in advance for any suggestions or resolution :)

In addition, here my object class :

[Serializable]  
public class Environment
{
    public string name { get; set; }
    public string value { get; set; }
    public Environment(){}
    public Environment(string Name, string Value)
    {
        name = Name;
        value = Value;
    }
}

Upvotes: 2

Views: 518

Answers (3)

Dmytro
Dmytro

Reputation: 17196

Try select all you references in solution explorer and set their Copy local property in Properties window to true, so they will be copied to the directory with executable or dll file after compilation. It should help if there are no necessary libraries on the target machine.

Upvotes: 1

Anthony Nichols
Anthony Nichols

Reputation: 1668

I believe your test machines are not using the same version of .net as your release. If you test machines don't have .net 4.0 install it... If you test machines are running Windows XP and your release is in .net 4.5 you will need to downgrade your program to .net 4.0.

Upvotes: 0

DiskJunky
DiskJunky

Reputation: 4981

taking a wild guess, but is your dev machine 64 bit? If so, try compiling your project for x86. You can do this by right-clicking your project in Solution Explorer and going to Properties. Click on the Build tab and change the Platform Target option from "Any CPU"/"x64" to "x86". Build your solution and redeploy to try again.

Upvotes: 2

Related Questions