Wednesday, July 21, 2010

.net Remoting, Will the static method of MBR be executed on server Only? 32/64 bit clr differs

Last day, I spent two hours to nail down on application bug which is caused by the 32/64 bit inner-process communication patterns. here is the rough outline.

The application is a standard .net remoting application, the .net remoting application has been in the .net platform for almost 7 years. The server side is running on IIS 32 bit process which hosted a Lot of Well-known singlecall/singleton remote objects. 
When one end user startup the Client application on Windows 7 /XP 64 bit, one weird bug said It can’t access some configuraton ( the config should be for Server side only, Now the logic is executed in client, why? Is there something wrong with the .net remoting runtime? ) then I spend hours to make sure both client and server side have applied the latest update. NO luck, still get the error which is caused by Some server side logic been executed on client side.

the logic code looks like this
   public class RemoteObject : MarshalByRefObject
       static RemoteObject()
           //try to read some server side configuration, web.config
             config= System.Configuration.ConfigurationSettings.AppSettings["serversideconfig"].Trim();
           System.Console.WriteLine("Static Constructor Method of MBR is executed on Process  " + Process.GetCurrentProcess().ProcessName);
for the client side, for sure there is no serversideconfig config, so will get an exception , nullreference.
Why the static method get executed on Client, It should be on server side only. Client is just a wrapper. then I write a mini demo, to identify the pattern. and it’s pretty easy to reproduce the issue. basically, it is caused by the 64 bit CLR. ( samething for .net framework 2.0/3.0/4.0)
Server 32 Bit Server 64 Bit
Client 32bit Server Execution Only Server Execution Only
Client 64bit Client/Server Both Execution Client/Server Both Execution
From this table, it means for 64 Bit Client,  those MBR object, the static constructor method will always be executed both on server side and client side. pretty weird behavior.  but not a big showstopper, once you know, fix it:)
here is the sample test code.

No comments:

Locations of visitors to this page