我已经将一个 DLL 从 Delphi Prism(Delphi 版本,具有类似 Pascal 语法的 .Net)移植到 C#。当我的基于 C# 的 DLL 从 Delphi 中的应用程序构建中加载时,会出现错误:
Uncaught Exception: System.MissingMethodException: Method not found: "Void ClimateControl.TClimateData..ctor()".
in DriverBoardTest.ConsoleApp.Main(String[] args)
数据结构 TClimateData 曾经是 Delphi 代码中的声明器,如下所示:
TClimateData = public record
public
tempSensor:Double;
tempHeater:Single;
humidity:Double;
end;
在 C# 中,它被转换为结构:
public struct TClimateData
{
//public TClimateData() { }
public double tempSensor;
public float tempHeater;
public double humidity;
}
反编译器(JetBrain dotPeak)添加了一个带有空实现的构造函数,但显然它在 C# 中是不允许的,所以我停用了它。
如果我尝试将结构转换为具有默认构造函数的类,则会收到另一个错误:
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)
我认为,基于 Delphi 的 DLL 调用了使用 C# 编译时不可用的记录的默认构造函数。我能修好吗?