473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

HELP: Serializing and Deserializing

I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank

Feb 4 '07 #1
7 2801
This is a previous response to the problem you are describing.
Hope this helps.

**************************************************
If anyone is interested, I ended up solving this problem.

If you serialize in one app, and want to deserialize in another app, an
exception will be thrown if dotnet can't load the assembly that did the
serializing.

Option 1: register the serializing app in the GAC. I didn't try this,
but I assume it would work
Option 2: use the SerializationBinder class to effectively fool the
deserializing app into thinking that it did the serializing:
when setting your BinaryFormatter up to deserialize, set the Binder
property to the class below:

BinaryFormatter b = new BinaryFormatter();
b.Binder = new FooDeserializationBinder();
myClasss = (MyClass) b.Deserialize(stream);

sealed class FooDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string
typeName)
{
return Type.GetType(typeName + ", " +
Assembly.GetExecutingAssembly().FullName);
}
}
************************************************** ***

"fjlaga" <fj****@sbcglobal.netwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank

Feb 5 '07 #2
fjlaga,

Making things everytime more complex to get a solution is seldom helping.
Just try to find the most easiest way don't knit.

http://www.vb-tips.com/dbpages.aspx?...c-61641f5c8d9d

Cor

"fjlaga" <fj****@sbcglobal.netschreef in bericht
news:11**********************@q2g2000cwa.googlegro ups.com...
>I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank

Feb 5 '07 #3
Gino,

Do you know that this is a VB.Net newsgroup. Although you try to be helpful,
don't think by that only to the OP. This newsgroup is more searched on
Google than only by the OP's.

Therefore please use VB.Net code.

Cor

"Gino" <so*****@microsoft.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
This is a previous response to the problem you are describing.
Hope this helps.

**************************************************
If anyone is interested, I ended up solving this problem.

If you serialize in one app, and want to deserialize in another app, an
exception will be thrown if dotnet can't load the assembly that did the
serializing.

Option 1: register the serializing app in the GAC. I didn't try this,
but I assume it would work
Option 2: use the SerializationBinder class to effectively fool the
deserializing app into thinking that it did the serializing:
when setting your BinaryFormatter up to deserialize, set the Binder
property to the class below:

BinaryFormatter b = new BinaryFormatter();
b.Binder = new FooDeserializationBinder();
myClasss = (MyClass) b.Deserialize(stream);

sealed class FooDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string
typeName)
{
return Type.GetType(typeName + ", " +
Assembly.GetExecutingAssembly().FullName);
}
}
************************************************** ***

"fjlaga" <fj****@sbcglobal.netwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
>>I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bi naryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank


Feb 5 '07 #4
Beautiful! It worked like a charm. (the code snippet provided was
easily translated into VB.NET). Thank you.
-Frank

On Feb 4, 3:55 pm, "Gino" <some...@microsoft.comwrote:
This is a previous response to the problem you are describing.
Hope this helps.

**************************************************
If anyone is interested, I ended up solving this problem.

If you serialize in one app, and want to deserialize in another app, an
exception will be thrown if dotnet can't load the assembly that did the
serializing.

Option 1: register the serializing app in the GAC. I didn't try this,
but I assume it would work
Option 2: use the SerializationBinder class to effectively fool the
deserializing app into thinking that it did the serializing:

when setting your BinaryFormatter up to deserialize, set the Binder
property to the class below:

BinaryFormatter b = new BinaryFormatter();
b.Binder = new FooDeserializationBinder();
myClasss = (MyClass) b.Deserialize(stream);

sealed class FooDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string
typeName)
{
return Type.GetType(typeName + ", " +
Assembly.GetExecutingAssembly().FullName);
}}

************************************************** ***

"fjlaga" <fjl...@sbcglobal.netwrote in message

news:11**********************@q2g2000cwa.googlegro ups.com...
I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.
Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:
MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.Bin aryAssemblyInfo.GetAssemb*ly()
...
To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:
C:sn -k "D:\MyAddin\SNKey.snk"
and added the following line to my AssemblyInfo.vb file:
<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>
When I try to build with this I get the error:
Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name
I'm confused about how to get this to work. I just want to read and
write my user settings to disk.
Any help is greatly appreciated.
-Frank- Hide quoted text -

- Show quoted text -

Feb 5 '07 #5
Yes.
And the whole programming world knows that it's C# code on a VB.net
newsgroup, without you telling them.
And you don't have to whine about being politically correct (real men don't
whine).
And the vast majority of vb.net programmers can easily read a C# snipet to
get an idea for a solution (as was indicated by the response to my post,
from the original poster)
And if I see this same question again, I'm going to send this same post.
Gino, from the Socialist Republic of Cambridge
Massachusetts.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Gino,

Do you know that this is a VB.Net newsgroup. Although you try to be
helpful, don't think by that only to the OP. This newsgroup is more
searched on Google than only by the OP's.

Therefore please use VB.Net code.

Cor

"Gino" <so*****@microsoft.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
>This is a previous response to the problem you are describing.
Hope this helps.

************************************************* *
If anyone is interested, I ended up solving this problem.

If you serialize in one app, and want to deserialize in another app, an
exception will be thrown if dotnet can't load the assembly that did the
serializing.

Option 1: register the serializing app in the GAC. I didn't try this,
but I assume it would work
Option 2: use the SerializationBinder class to effectively fool the
deserializing app into thinking that it did the serializing:
when setting your BinaryFormatter up to deserialize, set the Binder
property to the class below:

BinaryFormatter b = new BinaryFormatter();
b.Binder = new FooDeserializationBinder();
myClasss = (MyClass) b.Deserialize(stream);

sealed class FooDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string
typeName)
{
return Type.GetType(typeName + ", " +
Assembly.GetExecutingAssembly().FullName);
}
}
************************************************* ****

"fjlaga" <fj****@sbcglobal.netwrote in message
news:11**********************@q2g2000cwa.googlegr oups.com...
>>>I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary.B inaryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank



Feb 7 '07 #6
Gino,

Een grote aantal mensen actief in deze nieuwsgroep kan eenvoudig Nederlands
lezen en toch doen ze dat niet.

Cor

"Gino" <so*****@microsoft.comschreef in bericht
news:u$**************@TK2MSFTNGP03.phx.gbl...
Yes.
And the whole programming world knows that it's C# code on a VB.net
newsgroup, without you telling them.
And you don't have to whine about being politically correct (real men
don't whine).
And the vast majority of vb.net programmers can easily read a C# snipet to
get an idea for a solution (as was indicated by the response to my post,
from the original poster)
And if I see this same question again, I'm going to send this same post.
Gino, from the Socialist Republic of Cambridge
Massachusetts.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Gino,

Do you know that this is a VB.Net newsgroup. Although you try to be
helpful, don't think by that only to the OP. This newsgroup is more
searched on Google than only by the OP's.

Therefore please use VB.Net code.

Cor

"Gino" <so*****@microsoft.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
>>This is a previous response to the problem you are describing.
Hope this helps.

************************************************ **
If anyone is interested, I ended up solving this problem.

If you serialize in one app, and want to deserialize in another app, an
exception will be thrown if dotnet can't load the assembly that did the
serializing.

Option 1: register the serializing app in the GAC. I didn't try this,
but I assume it would work
Option 2: use the SerializationBinder class to effectively fool the
deserializing app into thinking that it did the serializing:
when setting your BinaryFormatter up to deserialize, set the Binder
property to the class below:

BinaryFormatter b = new BinaryFormatter();
b.Binder = new FooDeserializationBinder();
myClasss = (MyClass) b.Deserialize(stream);

sealed class FooDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string
typeName)
{
return Type.GetType(typeName + ", " +
Assembly.GetExecutingAssembly().FullName);
}
}
************************************************ *****

"fjlaga" <fj****@sbcglobal.netwrote in message
news:11**********************@q2g2000cwa.googleg roups.com...
I have written an Office Add-in for Excel using VB.NET and the .NET
1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I
want to add a User Settings/Prefereneces dialog and allow the user to
specify some settings and I need to persist these settings between
runs. I made a serializable class which uses the BinaryFormatter to
serialize/deserialize the setttings.

Serialization works great. However, when I try to deserialize the
saved settings on subsequent runs the following exception is thrown:

MyAddin.OnConnection Exception: Cannot find the assembly MyAddin,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=null.
at
System.Runtime.Serialization.Formatters.Binary. BinaryAssemblyInfo.GetAssembly()
...

To get around this, it seems I need to register my assembly in the
GAC. So, I generated a key pair using the following command:

C:sn -k "D:\MyAddin\SNKey.snk"

and added the following line to my AssemblyInfo.vb file:

<Assembly: AssemblyKeyFile("D:\MyAddin\SNKey.snk")>

When I try to build with this I get the error:

Unable to emit assembly: Referenced assembly
'Interop.Microsoft.Office.Core' does not have a strong name

I'm confused about how to get this to work. I just want to read and
write my user settings to disk.

Any help is greatly appreciated.
-Frank



Feb 7 '07 #7

"Cor Ligthert [MVP]" wrote
Gino,

Een grote aantal mensen actief in deze nieuwsgroep kan eenvoudig
Nederlands lezen en toch doen ze dat niet.

Cor
That's true.

A large number of people actively in this newsgroup can read simple
Dutch and nevertheless does not do that.

Gino
Feb 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff T. | last post by:
Hello, I have an existing set of C# classes that encapsulate our application data. They are in a heirachy with each subclass defining more specific types of data. I would like to serialize these...
3
by: Bruno Jouhier | last post by:
Is there a way to serialize a graph of objects and get the output as an XML document, without first serializing to text and then parsing the text (I know how to do this but I find it really silly...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
2
by: Earl Teigrob | last post by:
I am saving and restoring value types such as Int32, DateTime and Boolean in strings. I was wondering if there is a mechanism build into .NET for serializing and deserializing these to string...
3
by: MioTheGreat | last post by:
I know how to take a single hashtable, and then use a binaryformatter and a filestream to dump it to a file, but I need to serialize and deserialize a hashtable inside a class. I've been trying...
0
by: Michael Maercker | last post by:
Hi! I'm about to go nuts over my serializing problem. This is my situation: I have a Data-Class that can have children of the same class which are stored in a hashtable, i.e: X has A as a...
15
by: Cesar Ronchese | last post by:
Hi, I built the sample code showing the problem with dates when viewed at different machines, different Time Zones and transported via Remoting. The zip can be downloaded here: ...
0
by: j.askey | last post by:
Hi, I have a class that is inherited from Panel. Because Panel is not serializable, I have implemented the ISerializable interface on this class and I can sucessfully save and load classes from...
2
by: Kurious Oranj | last post by:
I've currently got a database structure which is something like:- class a - member type - effective date and:- class b - client name
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hi, I know this will sound like a lot of hand waving, and I'll be glad to supply some sample code if necessary, but I thought something obvious might jump out at someone without doing so. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.