MethodInfo.Invoke() doesnt work properly

IDE: Visual Studio 2015
Version: 9.1.100.2127 + Actual Island version
Target (If relevant): Windows 10/Linux
Description:
Method.Invok(aInstance, Arguments) doesnt work as expected.

First Case:
When i call it on a record, it got crashed at runtime

Second Case:
When i call it on a generic record, it got crashed as well.

Expected Behavior:
It should always return the value of every variable, either record or class.

Actual Behavior:
Have a look: (First Case)

  var auto : Auto;
  Auto.P1 := 'Test';
  Auto.P2 := 2000;
  Auto.P3 := 'X';
  var v := Auto.GetType().Methods.Where(info -> info.Name.StartsWith('get_')).FirstOrDefault(info -> info.Name = 'get_P1').Invoke(Auto, []);  //CRASHED HERE
  writeLn(v);

Have a look: (SecondCase)

  var pair: MyPair<TKey, TValue> := new MyPair<char, int32>('x', 30);
  var v := pair.GetType().Methods.Where(info -> info.Name.StartsWith('get_')).FirstOrDefault().Invoke(Auto, []);  //CRASHED HERE
  writeLn(v);

Steps:
NONE

We can’t fix this bug based on a random bit of code where we can’t see the important parts. Specifically, we the involved records.

That said; as you saw in your previous issue, there was an alignment bug in the invoker api, fixed that locally (should show in tomorrows build) which might just fix these too.

Ok, sry Carlo, i Forget that you Need the proejct for reproducing the bug, got it :smiley:

Test.zip (493 Bytes)

you have attached only .sln.
can you attach whole project, including .pas, .elements , etc ?

Yes of Course:

here:

Test.zip (1006.9 KB)

Fields have no getters/setters.
so you nave received nil after car.GetType().Methods.FirstOrDefault(info -> info.Name = 'get_P1') and later NRE
you can use Fields like car.GetType().Fields.FirstOrDefault(...)

Dude, pls just add the “property” key word and see, that they dont work!

In the Topic before, i send you a screenshot, with this simple testcase where it crashed!

NOW:

it doesnt even work with classes, records and not with generics :confused:

Latest island RTl needs a new compiler

What exactly do you mean by that?

That to use my last commits from yesterday in IslandRTL, you need a new compiler for it to work.

So does this mean for me:

I Need to w8 for the next release?

Or do i Need to reinstall the last Elements-Version
9.1.100.2127

You need to wait for the upcoming Beta build (either today or a little later)

1 Like

Ok, good to know :slight_smile:

I will continue reporting Errors about the invoke here:

  1. As far as I see:

it works for records/classes pretty well, EXCEPT FOR: INT64 and UINT64

they throw total crap values in the console (see “Strange Assignment Bug” for the Project i upload, there you have a good testcase for reproducing it)

Ah and furthermore:

Unfortunately, it still crashes with generics, (you can add a generic property in the Project i gave to you and look) :confused:

this is with .2129?

Mark, unfortunately yes :frowning:

Thats why I said, pretty well, until those with INT64 and UINT64

Ah and what I totally forgot to tell is, sry…,

when you Change the value of the P8 property, for instance, to UInt32.MaxValue and the P2 property to Int64.MinValue, suddenly, it works, at least in my testcase^^

Could you also try this out?

Carlo or Marc, could you find something why it doesnt work, or could you even reproduce this bug?

It’s still early, we haven’t gotten around to this issue yet.