0

I have ported a DLL from Delphi Prism (version of Delphi, .Net with Pascal-like syntax) to C#. When my C#-based DLL is loaded from the application build in Delphi, the error arises:

Uncaught Exception: System.MissingMethodException: Method not found: "Void ClimateControl.TClimateData..ctor()".
   in DriverBoardTest.ConsoleApp.Main(String[] args)

The data structure TClimateData used to be declarer in Delphi-code like this:

TClimateData = public record
  public
    tempSensor:Double;
    tempHeater:Single;
    humidity:Double;
  end;

In C# it was converted to a struct:

public struct TClimateData
  {
        //public TClimateData() { }
        public double tempSensor;
        public float tempHeater;
        public double humidity;
  }

The decompiler (JetBrain dotPeak) added a constructor with the empty implementation, but apparently it is not allowed in C#, so I deactivated it.

If I try to convert the struct to a class with a default constructor, I get another error:

Uncaught Exception : System.TypeLoadException: The type "ClimateControl.TClimateData" 
in the Assembly "SHT3xTest, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null" 
can't be loaded due to a type conflict 
in DriverBoardTest.ConsoleApp.Main(String[] args)

I think, the Delphi based DLL call the default constructor of the record which is not available when compiled with C#. Could I fix it?

Valentin H
  • 7,240
  • 12
  • 61
  • 111
  • I don't know anything about Delphi. That said, in C# the struct's parameterless constructor is implicit. I would keep it as a struct as it was converted, and instead start reviewing the referenced libraries to ensure all the correct/expected versions are being used... https://stackoverflow.com/questions/8058832/system-missingmethodexception-method-not-found – quaabaam Sep 19 '19 at 16:50
  • @quaabaam: Thank you, I've seen this questions. I've checked the versions and the versions are the same in my DLL an the others as well as the calling EXE – Valentin H Sep 20 '19 at 12:10

0 Answers0