a serialization issue

N

NA_AB

hi all,

am developing an excel com addin using c#. In my addin, I am supposed to
generate few buttons on the excel sheet and perform their events on clicking.
Every thing is working fine. Every button is named 'search' and is associated
with its appropriate event handler(searchButton_Click). The button and its
event handler constitute an object(of 'Result' class). Now I tried to
serialize the class Result so that I can save all the currently exisitng
'Result' objects to a file such that if I save this excel sheet and re open
it, I should be able to deserialize and get back the controls of all the
buttons present on the saved sheet. How ever in the serialize step, I am
getting an exception that says:

C:\guide\guide\CommandBar.resx(115):
<value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>

Could anyone here please help me identify the exact problem here and am I
missing anything? I did mark the class 'Result' as 'Serializable'. In my
'Result' class I have the code to generate a button on the sheet's active
cell and the button's event handler.

Many thanks in advance,
na_ab
 
N

NA_AB

The code is as follows:


[Serializable]
class result
{
OLEObject o;
Shape btn;
private Worksheet sht;
MSForms.CommandButton mbtn_1;
private static object Opt = Type.Missing;
Range act;
public string name;

public result(string s)
{
name = s;
sht = (Worksheet)Connect.MyApplication.ActiveSheet;
act = Connect.MyApplication.ActiveCell;
btn = sht.Shapes.AddOLEObject("Forms.CommandButton.1",
Opt, Opt, Opt, Opt, Opt, Opt,
sht.get_Range(act, act).Left,
sht.get_Range(act, act).Top,
sht.get_Range(act, act).Width,
((double)sht.get_Range(act, act).
Height) * 2);
o = (OLEObject)btn.DrawingObject;
mbtn_1 = (MSForms.CommandButton)(o.Object);
mbtn_1.Caption = "search";
mbtn_1.Click += new
MSForms.CommandButtonEvents_ClickEventHandler(Connect.search_me);
}
public static void search_me()
{
Worksheet sht = (Worksheet)Connect.MyApplication.ActiveSheet;
Range CurCell =
(Range)sht.Application.ActiveWindow.RangeSelection;
for (int i = 2; i < CurCell.Rows.Count + 1; i++)
{
for (int j = 2; j < CurCell.Columns.Count + 1; j++)
{
CurCell.Cells[i, j] = "hello: "+name;
}
}
}

this is the code in my main class:

result str = new result("ravi");
Stream s = File.Open("c:\\New Folder\\sample.txt",
FileMode.Create, FileAccess.ReadWrite);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, str); //---> here, am getting the exception
s.Close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top