basic serialization fails in outlook add-in

Add-in Express™ Support Service
That's what is more important than anything else

basic serialization fails in outlook add-in
 
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Serhat.

Sorry for delay. I was a little busy yesterday and couldn't test your code. I am glad you've solved the issue. Nevertheless I am going to test
the code. I am sure we can find another solution instead of GAC.
Posted 22 Mar, 2005 05:18:37 Top
Guest


Guest


thanks a lot.

I would like to know if something else also works.
Altough technically correct, using GAC is not such a good approach, since i do not actually want it to be a shared assembly.

regards,
serhat.
Posted 22 Mar, 2005 10:38:06 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Altough technically correct, using GAC is not such a good approach, since i do not actually want it to be a shared assembly


Serhat, I agree with you. I will try to find another solution.
Posted 22 Mar, 2005 10:48:22 Top
Daniel McPherson


Guest


Am I hitting the same problem:

---------------------------
MailManager
---------------------------
Load: There is an error in XML document (0, 0). System.IO.FileNotFoundException: File or assembly name MailManager, or one of its dependencies, was not found.

File name: "MailManager"

at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read5_NiftyMailManager()



=== Pre-bind state information ===

LOG: DisplayName = MailManager, Version=1.0.1898.19930, Culture=neutral, PublicKeyToken=null
(Fully-specified)

LOG: Appbase = C:\Program Files\Microsoft Office\OFFICE11\

LOG: Initial PrivatePath = NULL

Calling assembly : (Unknown).

===


LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

LOG: Post-policy reference: MailManager, Version=1.0.1898.19930, Culture=neutral, PublicKeyToken=null

LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Office/OFFICE11/MailManager.DLL.

LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Office/OFFICE11/MailManager/MailManager.DLL.

LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Office/OFFICE11/MailManager.EXE.

LOG: Attempting download of new URL file:///C:/Program Files/Microsoft Office/OFFICE11/MailManager/MailManager.EXE.


---------------------------
OK
---------------------------
Posted 22 Mar, 2005 11:06:07 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Serhat.

What do you think about the code below? I tested this code in my addin and all works fine.

private void Serialize()
{
FileStream fs = new FileStream(@"c:\Smart.bin", FileMode.Create);
SmartClass sc = new SmartClass();
sc.TestString = "My Test";

BinaryFormatter formatter = new BinaryFormatter();
try
{
formatter.Serialize(fs, sc);
}
catch (SerializationException e)
{
Console.WriteLine("Failed to serialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
}
}

private void Deserialize()
{
try
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Binder = new SmartClassBinder();
Stream stream = new FileStream(@"c:\Smart.bin", FileMode.Open, FileAccess.Read, FileShare.Read);

SmartClass smartClass = (SmartClass)formatter.Deserialize(stream);

MessageBox.Show(smartClass.TestString);
stream.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

sealed class SmartClassBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type typeToDeserialize = null;
typeToDeserialize = Type.GetType(String.Format("{0}, {1}",
typeName, assemblyName));
return typeToDeserialize;
}
}
Posted 23 Mar, 2005 08:53:25 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Daniel.

Do you still have any difficulties with the serialization/deserialization in an add-in?
If the code that I wrote for Serhat (see the previous post) will not help you, could you send me the project? I will try to find a proper solution for you.
Posted 23 Mar, 2005 09:04:55 Top
Daniel


Guest


Still having problems, code is below:

Public Function Save() As Boolean
Dim configPath As String
Dim dirTool As IO.Directory

configPath = GetConfigPath()
dirTool.CreateDirectory(configPath)

Try
Dim Serializer As New XmlSerializer(GetType(nmConfiguration))
Dim Writer As New StreamWriter(configPath & configFileName)
Serializer.Serialize(Writer, Me)
Writer.Close()
Catch ex As Exception
MsgBox("Save: " & ex.ToString)
Return False
End Try

Return True

End Function
Posted 23 Mar, 2005 11:10:46 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Daniel, thanks for the code. I will test it and let you know about results.
Posted 23 Mar, 2005 11:23:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Daniel.

I tested out your code. As far as I understand you are trying to serialize your addinmodule. You can't do this because the addinmodule contains some properties that can't be serialized directly (e.g. the Site property).
That's why you should use another class in the addinmodule to seriallize add-in properies. Try the following code:

public class MyClass
{
[SoapAttribute (Namespace = "//www.add-in-express.com")]
public string ClassName;
}

private void XmlSerialize()
{
XmlSerializer mySerializer = new XmlSerializer(typeof(MyNamespace.AddinModule.MyClass));
XmlTextWriter writer = new XmlTextWriter("c:\\data.xml", Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("wrapper");

MyClass myClass = new MyClass();
myClass.ClassName = "My class name";

mySerializer.Serialize(writer, myClass);
writer.WriteEndElement();

writer.Close();
}

private void XmlDeserialize()
{
XmlSerializer mySerializer = new XmlSerializer(typeof(MyNamespace.AddinModule.MyClass));
XmlTextReader reader= new XmlTextReader("c:\\data.xml");
reader.ReadStartElement("wrapper");

MyClass myClass = (MyClass) mySerializer.Deserialize(reader);
MessageBox.Show(myClass.ClassName);

reader.ReadEndElement();
reader.Close();
}
Posted 24 Mar, 2005 10:22:09 Top
Guest


Guest


Sergey,

sorry for delay,
It works great.

Thank you very much..
serhat.
Posted 24 Mar, 2005 18:05:23 Top