473,414 Members | 1,988 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,414 software developers and data experts.

Signed Assembly and FormatterAssemblyStyle.Simple


Hello.

I have been working with a client of mine on their seriazation code and we
seem to have run into an issue when we migrated from .NET 1.1 to .NET 2.0. We
have a framework of business objects that are serialized for persistant
storage. The object graph DOES change as development continues, but it is
required that we be able to deserialized existing classes and handle it
properly (version tolerance). With version 1.1 of the .NET framework, we were
able to create a custom formatter that used a custom SerializationSurrogate
and a custom SerializationBinder (as well as using
FormatterAssemblyStyle.Simple) to get this to work properly. Since, that
time, we have migrated to version 2.0 of the .NET framework, and now we are
finding that we can no longer take this approach due to an apparent, but
intended, defect in the serialization code of 2.0. Since many of the
assemblies in our framework are signed and strong-named (needed for use with
COM and Sharepoint), .NET is now simply ignoreing our request to use
FormatterAssemblyStyle.Simple.

Does anybody know of a way around this? I am fearful we are going to have to
roll our own serialization code that isn't based on .NET seriazation, which is
a horrific waste of our time.

Thank you in advance,

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 11 '06 #1
2 3811
Thomas T. Veldhouse <ve*****@yahoo.comwrote:
>
Does anybody know of a way around this? I am fearful we are going to have to
roll our own serialization code that isn't based on .NET seriazation, which is
a horrific waste of our time.
Well folks, I was able to get a work around, which hasn't solved the problem
entirely, as I still have an issue deserializing object graphs with class
instances that have an inheritance heirarchy which spans two or more strong
named assemblies.

I simply create a binder to thunk types over and use what is available in the
search path by removing all but the base assembly name. This binder is then
assigned to the formatter prior to deserialization:

sealed class SimpleDeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type typeToDeserialize = null;

// replace assembly name with the simple assembly name
// - strip the strong name off of the name
assemblyName = assemblyName.Split(',')[0];

// The following line of code returns the type.
typeToDeserialize = Type.GetType(String.Format("{0}, {1}",
typeName, assemblyName));
return typeToDeserialize;
}
}

NOTE: this code has not been fully tested ;-) .. not too fond of using
String.Split()

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 12 '06 #2
Thomas T. Veldhouse <ve*****@yahoo.comwrote:
>
NOTE: this code has not been fully tested ;-) .. not too fond of using
String.Split()
Hmm ... still having trouble! Why doesn't Microsoft honor "Simple" as the
documentation suggests? Anyway, here is the code we have now, but it STILL
doesn't work perfectly with subclasses of generic lists [themself generic]
being serialzied in an object graph where an the list is defined in one
assembly and the contents of the list are in another. Still, here is the code
we have so far, in case anybody google's this up in the future:

sealed class SimpleDeserializationBinder : SerializationBinder
{
private Regex _assemRegex = new Regex("(?<assembly>^.*?),.*");
private Regex _typeRegex = new
Regex("(?<type>.*?),(?<assembly>.*?),.*(?<end>]])");

public override Type BindToType(string assemblyName, string typeName)
{
// remove strong name from assembly
Match match = _assemRegex.Match(assemblyName);
if (match.Success)
{
assemblyName = match.Groups["assembly"].Value;
}

// remove strong name from any generic collections
match = _typeRegex.Match(typeName);
if (match.Success)
{
typeName = string.Format("{0},{1}{2}",
match.Groups["type"].Value,
match.Groups["assembly"].Value,
match.Groups["end"].Value);
}

Type typeToDeserialize = null;

// replace assembly name with the simple assembly name
// - strip the strong name off of the name
string type = string.Format("{0}, {1}", typeName,
assemblyName);

// The following line of code returns the type.
typeToDeserialize = Type.GetType(type);
return typeToDeserialize;
}
}

This code works for nearly all cases I have encountered, except what I
mentioned above, which is likely very rare.

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1

Jul 13 '06 #3

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

Similar topics

2
by: Bob Rock | last post by:
Hello, is it possible to programmatically read (and how) the public key that is embedded into an assembly that has been strongly signed??? What code would be needed??? Bob Rock
3
by: wschaub | last post by:
We need to inject information (i.e. server details from where a signed file was downloaded) into a signed file, without breaking the signature or integrity of a signed file. Apparently there are...
27
by: REH | last post by:
I asked this on c.l.c++, but they suggested you folks may be better able to answer. Basically, I am trying to write code to detect overflows in signed integer math. I am trying to make it as...
1
by: Peter Rilling | last post by:
I have a create that I am serializing which is then stored for later retrieval. The assembly that contains the class that I serialize is strongly named. I have encountered a problem were each...
2
by: cs | last post by:
is there a way to check trhough c# code if an assembly is signed and if it has the same signature as another assembly? I have some code that uses reflection on some types that belong to some...
0
by: Andy | last post by:
Hi all, I have a few questions about restricting who may call an assembly i'm building. First, I have a business assembly on a web server, with Serializable objects that use remoting to move...
3
by: pranesh.nayak | last post by:
Hello group, I'm facing a problem in calling a signed .Net class library (c#) from VB6 exe. I have a VB6 exe calling .net assembly. The call to .Net dll works fine when i deploy the .Net...
0
by: savajx1 | last post by:
I am loading signed assemblies from a network share. The assemblies are NOT INSTALLED in the GAC as they are part of an enterprise distributed application implemented as a windows service that...
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.