Tricky Exception Message while Remoting...

Published Sun, Sep 26 2004 19:49 | William

Well, as you may know, I've recently taken a position at a new company. We are doing some really really cool stuff which, amongst other things, takes advantage of .NET Remoting, Service Oriented Architecture, MSMQ, Biztalk Server 2004 and Web Service Enhancements (WSE) 2.0 to name just a few. Well, fortunately we have some really brilliant developers who've helped me out quite a bit getting up to speed with what used to be a big weak spot of mine, Remoting.

So recently I was working on a few components and since they were pieces of our communications layer, they of course needed to be Remotable. If you aren't familiar with Remoting yet, you really owe it to yourself to learn it. I've avoided it for almost 3 years now and am quite embarassed that I did so. Ignoring the communications layer is something you don't want to do in any 'real' distributed environment. I'll be getting into the how's and why's shortly in some new articles I'm working on, but for the time being, trust me on this one. Anyway, I had gotten through about 60% of what I had to do and essentially I was using a reference to the .dll where I created my objects first to make sure they worked, then I removed the references to them, added a reference to their interfaces and remoted them. All was going well until I got to one of the SIMPLEST ones I had - it was simply a collection of Message Queue objects with some other custom information.

There was nothing fancy about this and everything else had been working. But each time I tried to create the object, I recieved a System.Runtime.Serialization.SerializationException with the following information:

 "An unhandled exception of Type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll. Additional Information: BinaryFormatter version incompatibility. Expected Version 1.0. Received Version 1008738336.1684104552'.

So I immediately took it at face value and figured I must have screwed something up in my .config file and specified the wrong Formatter Type. This didn't seem likely though because I didn't remember even writing any formatting information into the .config since well before this problem showed itself. Nonetheless I double checked my config settings and everything seemed correct. So I decided to check out google and came across this article from the Jedi Master himself. I had already read his book and didn't recall any mention of what this could be. After reading through the article I could safely conclude there was a problem here. Furthermore, I figured I'd stop wasting my time looking for problems related to the formatter - after all, he pretty much convinced me that the exception information was completely misleading. So, I decided to take his advice, use PocketSOAP and see what the server was returning. (This in and of itself is a bit of a daunting task at first, but I ASSURE YOU, it's well worth the effort because you'll learn a lot just walking through the excercise). Right there, clear as day was the source of my problem.... The assembly XXXXXXXXX wasn't found, and for good reason, the assembly name was XXXXXXXXXXXY. Even though I thought I carefully checked the spelling, the IDE doesn't typecheck your config entries so they are very prone to typos (which I make quite a few of). So I corrected the typo, tried again, and Boom, I'm off to the races. The reason I write this is mainly because this is one of those problems that can really give you some headaches. First off, you are probably going to try tracking down something that has NOTHING TO DO with the problem. So you may well change a few things (that work) all the while wasting valuable programming time. This is further reinforecement of the fact that if you don't know why you're changing something, you shouldn't change it. Furthermore, it reinforces the notion that you ought not to be using things that you don't understand and that taking time to really understand why things work the way they do will make your programming career a WHOLE lot better. And finally, although Ingo's article definitely tells you what the problem Isn't and how to find it, well, it puts the burden on you to figure out the rest.

If you've never read a tcpTrace then this might seem really too much to deal with. So to that end, I'll tell you that IF YOU'RE GETTING THIS ERROR

1) VERIFY THAT YOU'VE SPELLED EVERYTHING CORRECTLY

2) VERIFY THAT YOU'VE FULLY QUALIFIED YOUR NAMESPACES

3) MAKE SURE YOU AREN'T REFERENCING AN ASSEMBLY NAME WHEN YOU SHOULD BE REFERENCING AN OBJECT NAME, AND VICE VERSA

Ingo's article will give you everything you need to find this on your own and if you find that you just simply mispelled something or misreferenced it, I would still HIGHLY encourage you to walk through the process that he puts forth. After all, in this case it was easy to find the culprit but don't be lulled into thinking that this will always be the case - in all likelihood it won't. .NET Remoting isn't 'impossible' but it's also something that like threading, should be understood before you try to use it in production. There's a lot that can go wrong and tracking things down, particularly if you use the configuration files to set everything up (which trust me - is the only real way to do this), can be a good amount of work.

Finally, since Remoting is quickly becomming one of my new passions, I'd really like to hear your opinions/problems/likes/dislikes/troubespots etc - please write me at Bill AT KNOWDOTNET DOTCOM. I'd really like to hear from you. I'm going to do my best to discuss the pitfalls and roadblocks you may come across when learning Remoting so any and all feedback is greatly appreciated.

Filed under:

Comments

# William said on September 26, 2004 8:32 PM:

Bill,
I have just started working with cross version serialization (trying to make sure our ado.net serializable objects can serialize across frameworks) and I hate it <grin> I am glad to hear that getting this right is somewhat important.

Any good resources on Remoting you can point me to?

# William said on September 26, 2004 10:10 PM:

Hi Angel:

You know, that's a really interesting point that I didn't even consider - it would be pretty darned important that my remotable object in v.X can be consumed by v.Xa for instance. Ingo Rammer is pretty much the man from what I've come across and his book on Advanced .NET REmoting (http://www.apress.com/book/bookDisplay.html?bID=47) is the best resource I've found. Similarly, Matthew MacDonald has a pretty good discussion in his enterprise development book but Ingo's is dedicated to Remoting and totally a must have. ALso, Paul Kimmel who is another dude I pretty much respect the heck out of has a really good discussion in his Visual Basic .NET for Advanced developers book. If you head over to www.thinktecture.com (Ingo's company) he's got some pretty good stuff. The only reason I found the problem was from his site which gave me the info I needed to track it down. The thing that makes this one tricky is that IT'S not a serialization problem but it says it is. And it's not a bug in the framework - it's based on what comes back from the remote machine however it's really misleading in that you're naturally inclined to hunt down something with formatting when in fact it's something else making itself look like its a formatting problem.

This is definitely something that's got my interest up - when I have time tomorrow I'll give it a try. I don't know how far you've gone with it so far, but Remoting ADO.NET objects is particularly interesting b/c in many cases, you just create an interface and use it to grab the remote object. But with a typed dataset for instance, creating an interface for it would be too much of a pain in many cases. But you can return it as a regular dataset and then just set the tablemappings/columnmappings to a locally created typed dataset and use it from there.

When I have some time I might try to use the 1.1 framework to pass a SqlDataReader remotely and access the connection from 5 different threads and see what happens just for giggles. WHat the heck, if Caustic Phil worked with a dude that advocated storing datareaders in session state, why can't I remote one <Hopefully no one will actually take this last nonsensical paragraph seriously).

I'll drop you a line tomorrow evening when I get home b/c this is a pretty interesting thing to look into

# William said on September 27, 2004 5:18 AM:

Fortunatelly for us there are only four main areas in ado.net that we are worried about when it comes to cross version serialization. The DataSet/datatable (huge, I am so glad I don't own this!) the SqlTypes (also not on my plate), managed provider exceptions and managed provider code access permissions. Exceptions are currently broken and I don't think anybody cares about code access security...

I must have missed the blog on session state datareaders *shudders* that must have been interesting. At least you can't serialize datareaders

# William said on September 27, 2004 12:26 PM:

FYI.. you can also just flip the formatter to SOAP in the server and client config files and the real message will come through.

Client:
<channels>
<channel ref="http" useDefaultCredentials="true" port="0">
<clientProviders>
<formatter ref="soap" />
</clientProviders>
</channel>
</channels>

Server:
<channels>
<channel ref="http">
<serverProviders>
<formatter ref="soap" />
</serverProviders>
</channel>
</channels>

# William said on September 27, 2004 1:04 PM:

Thanks for the tip Beth - much appreciated

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications