Deserialization in debug mode?

Deserialization in debug mode?

Ask Question

10 years, 6 months ago

10 years, 6 months ago

582 times



Can anyone explain why the following is happening:

When we serialize a file in debug mode, we can open it again in debug mode, but not at runtime.
When we serialize a file in runtime mode, we can open it again in runtime mode, but not at debug mode.

Now I know you’re gonna say: thats because they have different assemblies.
But we use a custom Binder, as specified below …
Furthermore, if we compare both types, “bool same = (o.GetType() == c.GetType())”, we get always “true” as result ???

Then why can’t we open the file ??

public class Binder : SerializationBinder {

public override Type BindToType(string assemblyName, string typeName) {
Type tyType = null;
string sShortAssemblyName = assemblyName.Split(‘,’)[0];
Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
if (sShortAssemblyName.ToLower() == “debugName”)
sShortAssemblyName = “runtimeName”;
foreach (Assembly ayAssembly in ayAssemblies) {
if (sShortAssemblyName == ayAssembly.FullName.Split(‘,’)[0]) {
tyType = ayAssembly.GetType(typeName);
return tyType;

public static DocumentClass Read(string fullFilePath, bool useSimpleFormat)
DocumentClass c = new DocumentClass();
c.CreatedFromReadFile = true;

Stream s = File.OpenRead(fullFilePath);// f.Open(FileMode.Open);
BinaryFormatter b = new BinaryFormatter();
if (useSimpleFormat)
b.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
b.Binder = new Binder();

object o = b.Deserialize(s);
c = (DocumentClass)o;
c.CreatedFromReadFile = true;

string objOriginal = o.GetType().AssemblyQualifiedName + “_” + o.GetType().FullName;
string objTarget = c.GetType().AssemblyQualifiedName + “_” + c.GetType().FullName;
bool same = (o.GetType() == c.GetType());

if (c.DocumentTypeID <= 0)
throw new Exception(“Invalid file format”);
catch( Exception exc )
if (!useSimpleFormat)
return Read(fullFilePath, true);
throw exc;

return c;

c# serialization debugging mode

share|improve this question

asked Sep 15 ’09 at 14:30


2,42111 gold badge3131 silver badges5252 bronze badges

add a comment

3 Answers





oh no … i’m an idiot …

some of the fields of the class are obfuscated in runtime mode …

hits head to table *

sorry people … thanks for all the help …

share|improve this answer

answered Sep 15 ’09 at 14:44


2,42111 gold badge3131 silver badges5252 bronze badges

add a comment


It sounds like you are using conditional compilation, eg:

class Foo {
int Bar;

If so, you wont be able to deserialize it automatically.

You have 2 choices then.

Dont use conditional compilation on serialized types – or –
Provide a custom serializer by adding the serializable constructor.

share|improve this answer

answered Sep 15 ’09 at 14:34


104k1616 gold badges179179 silver badges282282 bronze badges

we aren’t using conditional compilation … I’ve just searched the entire VS project, and nowhere is there a “#if DEBUG” line … thanks for a possible solution though ..

– Run CMD
Sep 15 ’09 at 14:39

add a comment


Simple questiion first – are you executing with the same credentials in both runtime and debug mode?

share|improve this answer

answered Sep 15 ’09 at 14:35


64444 silver badges55 bronze badges

I don’t know if i exactly understand what you mean, but we are running and debugging as the same Windows user …

– Run CMD
Sep 15 ’09 at 14:41

add a comment

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password


Post as a guest


Required, but never shown

Post Your Answer


By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged c# serialization debugging mode or ask your own question.

The Overflow Blog

Podcast Episode 220: Fully Remote

Tracking down performance pitfalls in Vue.js

Featured on Meta

Planned maintenance scheduled for Saturday, March 28, 2020 at 13:00 UTC (9AM…

An Update On Creative Commons Licensing

Community and Moderator guidelines for escalating issues via new response…

How does the Triage queue work?

Triage needs to be fixed urgently, and users need to be notified upon…


465How to Deserialize XML document2Serialization problem1563How do I debug Node.js applications?948Deserialize JSON into C# dynamic object?426#if DEBUG vs. Conditional(“DEBUG”)973Run/install/debug Android applications over Wi-Fi?1Type.GetType returns Nothing in SerializationBinder

Hot Network Questions

Constructing a lexicon and frequency array from a long string

Confusion about the definition of the uncertainty principle

Why John 1:1 in DRB is not literal translation from the Latin Vulgate?

Who owns the washing machine?

How much project management is a software developer supposed to do?

Why does camouflage make some planes fly slower?

Does anyone know a way to use patterns in Query?

How can I get a potential employer to reissue an offer I rejected?

Why would a ‘first world’ alien opt to have a brood of dumb children rather than one smart one?

What does the red R in old manual lenses mean?

Does there exist an aggregation of videos on optimization?

Why is sleep spelled with an aleph in Tehillim 127?

Sci-fi short story about extra sense that can be experienced by humans only once (probably from 1960’s or 70’s)

Did Russia release lions onto the streets to keep people in isolation?

Can a creature take turns as normal if they are inside an Antimagic Field while another creature casts Time Stop?

How do “tip jet” helicopters cancel the torque effect of the main rotor?

Is it true that Netscape Navigator eventually became Mozilla Firefox?

VertexContract and contraction of vertices of degree 2

What did Frodo and Sam eat when they crossed Mordor on foot?

A suit that realistically protects against impact, falling, being thrown around?

Why don’t laws have examples?

Can a fighter use Indomitable multiple times on the same save?

Is a creature standing in an Antimagic Field subject to the effects produced by Control Weather?

Can I create an image with a specific size in bytes?

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.


Leave a Reply

Your email address will not be published. Required fields are marked *