473,800 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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().I nvokeMember( "GetValue",
BindingFlags.Se tProperty | BindingFlags.Pu blic |
BindingFlags.In stance,
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().I nvokeMember( "Memory",
BindingFlags.Se tProperty | BindingFlags.Pu blic |
BindingFlags.In stance,
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 1294
Udi wrote:

<snip>
However, this fixes the problem:

object [] myArgs = {new int() };
obj.GetType().I nvokeMember( "Memory",
BindingFlags.Se tProperty | BindingFlags.Pu blic |
BindingFlags.In stance,
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.Reflecti on;

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

typeof(Test).Ge tMethod("DoSome thing").Invoke( null, args);
Console.WriteLi ne("x={0}", x);
Console.WriteLi ne("args[0]={0}", args[0]);
// Note *reference* equality is used here
Console.WriteLi ne("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
1908
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 been able to find any tool that will signal code in Python 2.3 that can cause errors in Python 2.4 . rgds
4
2011
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
2397
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, fast database abstraction layer which conforms to the behavior of the MySQL functions in PHP. This means that a large amount of porting work could be made simple using this porting layer if the application was originally used PHP's native MySQL...
1
1473
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 this is to rewrite the project from scratch in C#. Time is at a premium and given that I have no prior experience of either C# or Visual Studio .NET, this is not an acceptable solution. Is there any other way of doing this without wholesale code...
6
1532
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 provide any information or any links to websites? I have searched google, I couldn't find much information on this. Thanks for the help,
5
7059
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 like to convert it to C# and if that is not possible to manage C++. I want to use the DLL in a larger VB.Net program. Is there a tool that will convert C++ to C#? Are there any articles/papers/examples on converting C++ to C#? Are there any...
1
3452
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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: The state...
0
2280
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 say this will work for anyone else, but it worked for me... Using: http://ftp.mozilla.org/pub/mozilla.org/js/js-1.5.tar.gz First up:
34
4077
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
11
4092
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) available for 64 bit apps on the x64 platform. I have x64, Sql Server (must support 2000 and 2005) and Excel sheets (must be able to import mixed mode data), can someone point me into a direction to get this solved without too much trouble?
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.