Click here to Skip to main content
15,915,094 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I retrieve a list of available ports on a specified ip? Pin
wxShayan12-Jan-07 5:23
wxShayan12-Jan-07 5:23 
AnswerRe: How can I retrieve a list of available ports on a specified ip? Pin
Eric Dahlvang12-Jan-07 6:39
Eric Dahlvang12-Jan-07 6:39 
GeneralRe: How can I retrieve a list of available ports on a specified ip? Pin
wxShayan12-Jan-07 17:00
wxShayan12-Jan-07 17:00 
QuestionLCG issue (DynamicMethod / ILGenerator) Pin
rcollina12-Jan-07 5:03
rcollina12-Jan-07 5:03 
AnswerRe: LCG issue (DynamicMethod / ILGenerator) Pin
S. Senthil Kumar12-Jan-07 6:42
S. Senthil Kumar12-Jan-07 6:42 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) [modified] Pin
rcollina12-Jan-07 8:49
rcollina12-Jan-07 8:49 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
S. Senthil Kumar12-Jan-07 20:31
S. Senthil Kumar12-Jan-07 20:31 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) [modified] Pin
rcollina13-Jan-07 13:45
rcollina13-Jan-07 13:45 
Shame on me I didn't notice your reply. First of all, thanks for your valuable help!

I stand corrected about the Ldnull, as I've been doing a test very similar to yours and it gave me the same result. I was linking "void" to a null push to the stack before the ret statement. Funny, but not working. Smile | :)

I have reproduced the AccessViolationException by adding many "ld_arg0" instructions.

<code>
			gen.Emit(OpCodes.Ldarg_0);
			gen.Emit(OpCodes.Call, methodInfo);
			gen.Emit(OpCodes.Ldarg_0);
			gen.Emit(OpCodes.Call, methodInfo);
</code>


I was trying to call the same method twice in your example. I've already found two bugs in my IL generation methods thanks to you.

Here's the problem showing the key to my initial idea:
<code>
	public class Program
	{
		delegate void MyDelegate();
		public void TestMethod() { Console.WriteLine("Hello"); }
		public void TestMethod2() { Console.WriteLine("hey"); }
		public static void Main()
		{
			Program p = new Program();
			MethodInfo methodInfo = p.GetType().GetMethod("TestMethod");
			MethodInfo methodInfo2 = p.GetType().GetMethod("TestMethod2");

			DynamicMethod dynMethod = new DynamicMethod("DynTestMethod", 
                            null, null, typeof(Program));

			ILGenerator gen = dynMethod.GetILGenerator();

			gen.Emit(OpCodes.Ldarg_0);
			gen.Emit(OpCodes.Call, methodInfo);

			//IL instruction missing here
			gen.Emit(OpCodes.Call, methodInfo2); //Most likely to produce the exception.

			gen.Emit(OpCodes.Ret);

			MyDelegate d = (MyDelegate)dynMethod.CreateDelegate(typeof(MyDelegate));
			d.Invoke();
			Console.ReadLine();

		}
	}
</code>


The program gives an "InvalidProgramException" as expected. I wonder if there's a way to make that second Call instruction work. And others, if need be.

Many thanks again for your help and sorry for the delay of this reply.

Roberto

Edit: here's another pseudo-msil dump of what I'm trying to get to run:

<code>
.method void ManagedProcessInput 
{
	ldarg_0
	call void UserInterface.ProcessInput()
	call void UserInterfaceEditor.ProcessInput()
	ret
}
</code>


Note: the methods stored in the MethodInfos are not static. Moreover, they are implementations of an interface.

<code>
interface IMyInterface
{
   void Run();
}

class MyObject : IMyInterface
{
   [ctor / dtor]
   public void Run()
   {
      [impl. here]
   }
}
</code>

-- modified at 20:04 Saturday 13th January, 2007
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
S. Senthil Kumar13-Jan-07 21:07
S. Senthil Kumar13-Jan-07 21:07 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) [modified] Pin
rcollina14-Jan-07 2:27
rcollina14-Jan-07 2:27 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
rcollina15-Jan-07 14:02
rcollina15-Jan-07 14:02 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
rcollina17-Jan-07 13:28
rcollina17-Jan-07 13:28 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
S. Senthil Kumar17-Jan-07 17:51
S. Senthil Kumar17-Jan-07 17:51 
GeneralRe: LCG issue (DynamicMethod / ILGenerator) Pin
rcollina20-Jan-07 10:02
rcollina20-Jan-07 10:02 
QuestionFinding a Sorted DataGridView row in a Dataset Pin
efriese112-Jan-07 4:21
efriese112-Jan-07 4:21 
AnswerRe: Finding a Sorted DataGridView row in a Dataset Pin
Mircea Puiu12-Jan-07 4:34
Mircea Puiu12-Jan-07 4:34 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
efriese112-Jan-07 4:53
efriese112-Jan-07 4:53 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
Mircea Puiu12-Jan-07 5:00
Mircea Puiu12-Jan-07 5:00 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
efriese112-Jan-07 5:09
efriese112-Jan-07 5:09 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
Mircea Puiu12-Jan-07 5:12
Mircea Puiu12-Jan-07 5:12 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
efriese112-Jan-07 5:19
efriese112-Jan-07 5:19 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
Mircea Puiu12-Jan-07 5:20
Mircea Puiu12-Jan-07 5:20 
GeneralRe: Finding a Sorted DataGridView row in a Dataset Pin
efriese112-Jan-07 5:28
efriese112-Jan-07 5:28 
AnswerRe: Finding a Sorted DataGridView row in a Dataset Pin
Drew McGhie12-Jan-07 9:55
Drew McGhie12-Jan-07 9:55 
QuestionMake a web browser that work in single window Pin
Par Witch12-Jan-07 4:15
Par Witch12-Jan-07 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.