"with" on record causes bad image on Xamarin Android

Hi,
I created a test class as below:

namespace OxgeneneLib;

interface

type
  TMyRecord = record
   x,y,z : Integer;
  end;
  
  Class1 = public class

  private
    var myrec : TMyRecord ;

  public
    method Test1();
    begin
      Console.WriteLine( 'Test1 Passed' ) ;
    end;
    
    // calling this method fails on Xmarin Android:
    // System.BadImageFormatException: 'Expected value type but got type kind 22'
    method Test2();
    begin
      with myrec do begin
        
      end;
      
      Console.WriteLine( 'Test2 Passed') ;
    end;
  end;

implementation

end.

Calling this class form Xamarin Android causes: System.BadImageFormatException: 'Expected value type but got type kind 22. Bug relates to the existence of “with [record type var] do” statement. With a statement on classes seems to works fine class.
I understand that bug is rather on Mono/Xamiarin side, however, that must be something specific to Oxygene which confuses Mono/Xamarin/Android toolchain.

does it PEVerify correctly?

There is no difference in PE Verifier output from Oxygene and C#

But there is a difference in IL file

Oxygene code:

.locals init (
    [0] valuetype [netstandard]System.TypedReference reference)
L_0000: ldarg.0 
L_0001: ldflda valuetype OxgeneneLib.TMyRecord OxgeneneLib.Class1::myrec
L_0006: mkrefany OxgeneneLib.TMyRecord
L_000b: stloc.0 

Similar code from C# compiled as .NETStandard library (output from Reflector)

   .locals init (
        [0] valuetype [mscorlib]System.TypedReference reference,
        [1] class [OxgeneneLib]OxgeneneLib.Class1 class2)
    L_0000: nop 
    L_0001: ldarg.0 
    L_0002: ldflda valuetype TestOxygene.TMyRecord TestOxygene.MainActivity::myrec
    L_0007: mkrefany TestOxygene.TMyRecord
    L_000c: stloc.0 

Similar code from C# compiled as .NETStandard library (output from ILDASM)

  .maxstack  1
  .locals init (typedref V_0)
  IL_0000:  nop
  IL_0001:  ldarg.0
  IL_0002:  ldflda     valuetype ClassLibrary2.TMyRecord ClassLibrary2.Class1::myrec
  IL_0007:  mkrefany   ClassLibrary2.TMyRecord
  IL_000c:  stloc.0
  IL_000d:  ldstr      "Test"
  IL_0012:  call       void [netstandard]System.Console::WriteLine(string)
  IL_0017:  nop
  IL_0018:  ret

As you see Microsoft refers [mscrorlib] while Oxygene [netstandard]

wait, what — are you building your Oxygene project for .NET or .NET Standard?

.NETStandard2.0 both Oxygene and C# Microsoft’s compiler.

Hm, so a VC# project commixed against .NET Standard uses mscorlib, not .NET Standard? weird. I’ll log an issue.

Workaround for now: buildinf the project form .NET instead should work?

Thanks, logged as bugs://84833

Workaround won’t work. Any news about this issue?

It has top priority for next week, but at this point, no idea for a workaround I’m afraid, no.

Ok, thanks for info.

1 Like

bugs://84833 got closed with status fixed.