473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A problem with porting 1.1 to 2.0

Udi
Hi All,
I have a function that I need to call on reflection that has an out
parameter
(maybe more than one).
My problem is that I'm not receiving the out values.

The following code works fine on VS2003, but not on 2005:

ArrayList myArgs = new ArrayList();
Int outVal;
myArgs.Add( outVal );
obj.GetType().InvokeMember( "GetValue",
BindingFlags.SetProperty | BindingFlags.Public |
BindingFlags.Instance,
null,
obj,
(Object [])myArgs.ToArray(typeof(Object)) // FAILS ON 2005
value always returns 0
);
However, this fixes the problem:

object [] myArgs = {new int() };
obj.GetType().InvokeMember( "Memory",
BindingFlags.SetProperty | BindingFlags.Public |
BindingFlags.Instance,
null,
obj,
myArgs) // WORKS FINE
);

I guess this is related to a temporary array that is returned from
'ToArray()' and gets lost,
but I still don't really understand what's happening there.
Can anyone please explain to me what's exactly happening behind the
scenes, or point me to some links?
Thanks a lot!

Jul 24 '06 #1
1 1279
Udi wrote:

<snip>
However, this fixes the problem:

object [] myArgs = {new int() };
obj.GetType().InvokeMember( "Memory",
BindingFlags.SetProperty | BindingFlags.Public |
BindingFlags.Instance,
null,
obj,
myArgs) // WORKS FINE
);

I guess this is related to a temporary array that is returned from
'ToArray()' and gets lost,
but I still don't really understand what's happening there.
Can anyone please explain to me what's exactly happening behind the
scenes, or point me to some links?
I believe the difference is in terms of what happens to the contents of
the array. Remember that at this stage, the array contains a boxed int
- the same reference which is in the ArrayList in the original sample.

In .NET 1.1, the contents of the box is changed by the out parameter
being set. In .NET 2.0, the array element is replaced with a new boxed
int.

Here's a short but complete program which demonstrates the difference
in behaviour:

using System;
using System.Reflection;

class Test
{
static void Main()
{
object x = 0; // x is a reference to a boxed int
object[] args = new object[]{x};

typeof(Test).GetMethod("DoSomething").Invoke(null, args);
Console.WriteLine("x={0}", x);
Console.WriteLine("args[0]={0}", args[0]);
// Note *reference* equality is used here
Console.WriteLine("x==args[0]? {0}", x==args[0]);
}

public static void DoSomething(out int i)
{
i=10;
}
}

..NET 1.1 results:
x=10
args[0]=10
x==args[0]? True

..NET 2.0 results:
x=0
args[0]=10
x==args[0]? False

Jon

Jul 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anand | last post by:
Hi Are there any tools that would help in porting code from Pyton 2.3 to 2.4 ? I have gone through the whatsnew documents and created a document comparing Python 2.4 to 2.3. But so far has not...
4
by: golu | last post by:
Has any body done the porting from oracle to sql server, what were the issues in porting the data bases? Also suggest some resources which can be helpful in the porting project TIA Golu
4
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
1
by: Robin Charisse | last post by:
Hi, I have a VC++6 project that uses msxml to parse XML documents. I have been asked to port this to a .NET project but from the research I've done so far it looks as though the only way to do...
6
by: Raghavendra | last post by:
Hi All, I have one big system application, which is developed for HPUX and Windows in C-language. I need to port it to Linux. What all things do I need to consider to do this. Can you please...
5
by: Michael D. Reed | last post by:
I have legacy DLL code written in C++ that is essentially C code, an implementation of a set of formulas used in our industry. There are no DB or GUI interfaces, just exposed methods. I would...
1
by: Bill | last post by:
Does anyone know how to fix this problem? On form submittal I'm getting the following error in Visual Studio 2005: The state information is invalid for this page and might be corrupted....
0
by: follower | last post by:
This post is mostly Google-bait for anyone else that might want to compile SpiderMonkey ( libjs / libjs.so / libjs.dylib ) for OS X (10.4.5 in my case) and then use it with Python's ctypes. I can't...
34
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
11
by: DC | last post by:
Hi, I easily ported a .Net 2.0 c# app to x64, but there is one major problem left: the app imports excel data via OleDB, and there are no Jet drivers and no ODBC divers (other than SQL Server)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.