[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

IMethodReturnMessage Question

Al Tenhundfeld

10/6/2004 10:41:00 PM

I am fairly new to Remoting, and as a learning excersise, I have implemented
what I call a "Logging Aspect." I am using using implementations of
IMessageSink, ContextBoundObject, and ContextAttribute to intercept method
calls and write the input parameter values and return values to a log file.
(If I need to be more specific, I can be; I don't know how common this
pattern is.)

My simple logging system worked well initially when I was using a native
types as the return values. Then I decided to have some functions return a
custom struct, and the logging mechanism no longer retrieved the correct
return values. When I cast the return value to my struct and access the
appropriate field, incorrect data is returned. It seems to be static
incorrect data, the same incorrect value for all fields of a specific type.
For example all Int32 fields of my struct return 17442916, and all DateTime
fields return #5/28/0238 4:56:16 AM#. If I change my custom struct to a
custom class, everything performs as desired. I have tried using FCL native
structs, like SqlTypes.SqlInt32, with the same incorrect result.

It feels that I am missing something obvious, but I haven't been able to
find anybody saying "you can't use derived value types in message sinks".

I have included a bit of sample code below. Again, I think this pattern is
pretty common. I have seen it in several articles on AOP, but I can
certainly post a more comprehensive code sample, if required.

Thanks.
Al Tenhundfeld.

Sample Code:
//My custom struct, which is returned by a function implemented in a class
derived
//from ContextBoundObject with a custom ContextAttribute.
public struct MyStruct
{
public MyStruct() {}

public DateTime Date
{
get{return DateTime.Parse("02/02/2002");}
}
}

//Method inside my IMessageSink.SyncProcessMessage implementation.
private void AfterProcess(IMessage msg, IMessage msgReturn)
{
IMethodReturnMessage retMsg = (IMethodReturnMessage)msgReturn;

MyStruct m = (MyStruct)retMsg.ReturnValue;

Console.Write(m.Date.ToString);
} //You would expect m.Date to return "02/02/2002", but it returns
#5/28/0238 4:56:16 AM#. .
//This works as expected when MyStruct is a class.