MethodInfo.Invoke() doesnt work properly

oxygene
visual-studio
island

(shpend hoti) #1

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


(Carlo Kok) #2

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.


(shpend hoti) #3

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

Test.zip (493 Bytes)


(EvgenyK) #4

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


(shpend hoti) #5

Yes of Course:

here:

Test.zip (1006.9 KB)


(EvgenyK) #6

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(...)


(shpend hoti) #7

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:


(Carlo Kok) #8

Latest island RTl needs a new compiler


(shpend hoti) #9

What exactly do you mean by that?


(Carlo Kok) #10

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


(shpend hoti) #11

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


(Carlo Kok) #12

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


(shpend hoti) #13

Ok, good to know :slight_smile:


(shpend hoti) #14

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)


(shpend hoti) #15

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:


(marc hoffman) #16

this is with .2129?


(shpend hoti) #17

Mark, unfortunately yes :frowning:

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


(shpend hoti) #18

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?


(shpend hoti) #19

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


(Carlo Kok) #20

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