By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,143 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,143 IT Pros & Developers. It's quick & easy.

HELP: Serializing and Deserializing

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.