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
 
serhat


Guest


hi,

i get the following exception in my outlook add-in.
the same serialization works smooth in regular applications.

can not find the assembly myAssemblyNameHere, Version = 1.0.1906, culture = neutral, publickeytoken = null.

Why do i get thi exception in an add-in and do not get it usual applic.s?

thanks in advance;
serhat.
Posted 20 Mar, 2005 19:33:47 Top
Sergey Grischenko


Add-in Express team


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

Could you please give me more detailed information? What does your code do before the error appears?
Posted 21 Mar, 2005 04:08:31 Top
Guest


Guest


IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(@"c:\Smart.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
object ob = formatter.Deserialize(stream);
smartClass = (SmartClass) formatter.Deserialize(stream);
stream.Close();

smartClass is my serializable class which is implemented as a new class in the same solution.
it simply tries to do the given code above in onstart-up complete.
But i get the exception i mentioned above.

i checked the net and found that assembly path could be a problem, since i am within outlook.exe which has another path like myAddin.dll

what should i do to get assembly path corrected?

thanks,
serhat.




Posted 21 Mar, 2005 05:01:10 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Serhat,

I would like to look at the code of your add-in. Could you send me the code?
Posted 21 Mar, 2005 05:27:35 Top
Guest


Guest


/*
* Project :Smart Plan for Outlook.
* Author :Serhat Adali.
* Date Created :20/03/2005
* Description: project sample implements the following:
* Modifies the standard toolbar and adds new popup buttons.
* Implements a simple interface for placing a pre-defined smart plan item.
*/

namespace RAC_Smart_Plan
{
using System;
using Extensibility;
using System.Runtime.InteropServices;

using System.Reflection;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

/// <summary>
/// The object for implementing an Add-in.
/// </summary>
/// <seealso class='IDTExtensibility2' />
[GuidAttribute("4FEB11F4-11A1-4FD3-83F4-53049EEDBCA5"), ProgId("RAC_Smart_Plan.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
/// <summary>
/// Implements the constructor for the Add-in object.
/// Place your initialization code within this method.
/// </summary>
public Connect()
{
}

/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being loaded.
/// </summary>
/// <param term='application'>
/// Root object of the host application.
/// </param>
/// <param term='connectMode'>
/// Describes how the Add-in is being loaded.
/// </param>
/// <param term='addInInst'>
/// Object representing this Add-in.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{

outlookApp = (Outlook.Application)application;
addInInstance = addInInst;
}

/// <summary>
/// Implements the OnDisconnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being unloaded.
/// </summary>
/// <param term='disconnectMode'>
/// Describes how the Add-in is being unloaded.
/// </param>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
outlookApp = null;
}

/// <summary>
/// Implements the OnAddInsUpdate method of the IDTExtensibility2 interface.
/// Receives notification that the collection of Add-ins has changed.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnAddInsUpdate(ref System.Array custom)
{
}

/// <summary>
/// Implements the OnStartupComplete method of the IDTExtensibility2 interface.
/// Receives notification that the host application has completed loading.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom)
{
// Here i add a couple of buttons
}

public void SerializeSmartClass()
{

try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(@"c:\Smart.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
smartClass = (SmartClass)formatter.Deserialize(stream);
stream.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
smartClass = new SmartClass();
}

}

/// <summary>
/// Implements the OnBeginShutdown method of the IDTExtensibility2 interface.
/// Receives notification that the host application is being unloaded.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnBeginShutdown(ref System.Array custom)
{

}


private Outlook.Application outlookApp;
private object addInInstance;

//Button "Apply Smart Plan"
Office.CommandBarButton btnApplySmartPlan;

Office.CommandBarButton btnApplySmartPlanTool;
Office.CommandBarButton btnViewEditSmartPlan;
SmartClass smartClass;
}
}

Posted 21 Mar, 2005 05:48:39 Top
Guest


Guest


Following is my code (i removed some button adding and eventhandler connections etc.) It gives the exception i mentioned above on line:
"smartClass = (SmartClass)formatter.Deserialize(stream);"

the Smart Class is implemented as follows:
using System;
using System.Collections;
using System.Windows.Forms;

namespace RAC_Smart_Plan
{
/// <summary>
/// Summary description for SmartClass.
/// </summary>
[Serializable]
public class SmartClass
{
public SmartClass()
{
//some construction code here
}
public ArrayList nodeList;

public string GetContact(int nodeIndex)
{
//bla bla..
}

public string GetStartDate(int nodeIndex)
{
//bla bla..
}

public DateTime GetStartDateTime(int nodeIndex)
{
//bla bla..
}
}
[Serializable]
public struct SmartNode
{

//bla bla..
}
}


Posted 21 Mar, 2005 05:48:49 Top
Guest


Guest


I call the SerializeSmartClass(which in fact does the deserialization) function in the body of startup complete.
Posted 21 Mar, 2005 05:50:17 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Serhat, thanks for the code. I will test it.
Posted 21 Mar, 2005 06:10:14 Top
Guest


Guest


sergey,


i have installed the add-in to the folder where my outlook.exe resides, and it worked. what does that mean now??

you do not need to try the code i have given you, i have tried and saw that any attempt of simplest serialization/deserialization fails in the add-in. I believe it is about assembly path or so, apart from the code.


thanks for your time and efforts.
serhat.
Posted 21 Mar, 2005 16:57:39 Top
Guest


Guest


at last,

in project setup, i have included global assembly(GAC) cache folder to folders on target machine, and set my primary output folder to this GAC.
It worked.

regards,
serhat.
Posted 21 Mar, 2005 18:13:15 Top