But in version 4 i get errors with this code and i have to pass everything ByVal instead of ByRef which is bad for memory etc.

I dont really want to pass a whole DataReader by value in each function, so i can only think that i have to pass each value as a separate parameter??

Am i missing something or was this done for a reason??

You get the following error by using ByRef

xpression of type 'System.Object&' cannot be used for parameter of type 'System.Object' of method 'Void Child_Fetch(System.Object ByRef)'

RockfordLhotka replied on Thursday, May 05, 2011

ByVal and ByRef are essentially meaningless when passing reference types like a data reader.

When you pass an object reference ByVal, you are passing the reference pointer (basically an int) by value to the method. The actual referenced object (the data reader) isn't passed at all - only a pointer is passed.

When you pass an object reference ByRef, you are still passing the reference pointer (basically an int) by reference. The only difference here, is that the method can change the reference to point to a new object, and the calling code would see that as a side-effect.

Anyone who did any FORTRAN in the past knows that side-effect-based APIs are almost always a disaster, which is why you rarely see the use of ByRef semantics in anyone's code, or in the .NET APIs.

CSLA actually does use a ByRef semantic in the LoadProperty and SetProperty methods that support private backing fields. This was a concious choice on my part - but having used FORTRAN years ago, I can tell you I thought twice before implementing that API!!

In any case, my ramblings aside, you are misunderstanding the way ByVal works, and since a data reader is a reference type you shouldn't worry about it having negative consequences.