- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ets2sdk .net 核心项目中的库(最初是用 .net 框架编写的)。
加载此类型导致异常:
System.TypeLoadException: Could not load type 'Ets2SdkData' from assembly 'x' because it contains an object field at offset 20 that is incorrectly aligned or overlapped by a non-object field.
类型正文:
[StructLayout(LayoutKind.Explicit)]
public struct Ets2SdkData
{
[FieldOffset(0)]
public uint time;
[FieldOffset(4)]
public uint paused;
[FieldOffset(8)]
public uint ets2_telemetry_plugin_revision;
[FieldOffset(12)]
public uint ets2_version_major;
[FieldOffset(16)]
public uint ets2_version_minor;
// ***** REVISION 1 ****** //
[FieldOffset(20)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] flags;
// vehicle dynamics
[FieldOffset(24)]
public float speed;
[FieldOffset(28)]
public float accelerationX;
[FieldOffset(32)]
public float accelerationY;
[FieldOffset(36)]
public float accelerationZ;
[FieldOffset(40)]
public float coordinateX;
[FieldOffset(44)]
public float coordinateY;
[FieldOffset(48)]
public float coordinateZ;
[FieldOffset(52)]
public float rotationX;
[FieldOffset(56)]
public float rotationY;
[FieldOffset(60)]
public float rotationZ;
// drivetrain essentials
[FieldOffset(64)]
public int gear;
[FieldOffset(68)]
public int gears;
[FieldOffset(72)]
public int gearRanges;
[FieldOffset(76)]
public int gearRangeActive;
[FieldOffset(80)]
public float engineRpm;
[FieldOffset(84)]
public float engineRpmMax;
[FieldOffset(88)]
public float fuel;
[FieldOffset(92)]
public float fuelCapacity;
[FieldOffset(96)]
public float fuelRate;
[FieldOffset(100)]
public float fuelAvgConsumption;
// user input
[FieldOffset(104)]
public float userSteer;
[FieldOffset(108)]
public float userThrottle;
[FieldOffset(112)]
public float userBrake;
[FieldOffset(116)]
public float userClutch;
[FieldOffset(120)]
public float gameSteer;
[FieldOffset(124)]
public float gameThrottle;
[FieldOffset(128)]
public float gameBrake;
[FieldOffset(132)]
public float gameClutch;
// truck & trailer
[FieldOffset(136)]
public float truckWeight;
[FieldOffset(140)]
public float trailerWeight;
[FieldOffset(144)]
public int modelOffset;
[FieldOffset(148)]
public int modelLength;
[FieldOffset(152)]
public int trailerOffset;
[FieldOffset(156)]
public int trailerLength;
// ***** REVISION 2 ****** //
[FieldOffset(160)]
public int timeAbsolute;
[FieldOffset(164)]
public int gearsReverse;
[FieldOffset(168)]
public float trailerMass;
[FieldOffset(172)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] trailerId;
[FieldOffset(236)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] trailerName;
[FieldOffset(300)]
public int jobIncome;
[FieldOffset(304)]
public int jobDeadline;
[FieldOffset(308)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCitySource;
[FieldOffset(372)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCityDestination;
[FieldOffset(436)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCompanySource;
[FieldOffset(500)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCompanyDestination;
// ***** REVISION 3 ****** //
[FieldOffset(564)]
public int retarderBrake;
[FieldOffset(568)]
public int shifterSlot;
[FieldOffset(572)]
public int shifterToggle;
//[FieldOffset(576)]
//public int fill;
[FieldOffset(580)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public byte[] aux;
[FieldOffset(604)]
public float airPressure;
[FieldOffset(608)]
public float brakeTemperature;
[FieldOffset(612)]
public int fuelWarning;
[FieldOffset(616)]
public float adblue;
[FieldOffset(620)]
public float adblueConsumption;
[FieldOffset(624)]
public float oilPressure;
[FieldOffset(628)]
public float oilTemperature;
[FieldOffset(632)]
public float waterTemperature;
[FieldOffset(636)]
public float batteryVoltage;
[FieldOffset(640)]
public float lightsDashboard;
[FieldOffset(644)]
public float wearEngine;
[FieldOffset(648)]
public float wearTransmission;
[FieldOffset(652)]
public float wearCabin;
[FieldOffset(656)]
public float wearChassis;
[FieldOffset(660)]
public float wearWheels;
[FieldOffset(664)]
public float wearTrailer;
[FieldOffset(668)]
public float truckOdometer;
[FieldOffset(672)]
public float cruiseControlSpeed;
[FieldOffset(676)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] truckMake;
[FieldOffset(740)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] truckMakeId;
[FieldOffset(804)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] truckModel;
// ***** REVISION 4 ****** //
[FieldOffset(868)]
public float speedLimit;
[FieldOffset(872)]
public float routeDistance;
[FieldOffset(876)]
public float routeTime;
[FieldOffset(880)]
public float fuelRange;
[FieldOffset(884)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public float[] gearRatioForward;
[FieldOffset(980)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public float[] gearRatioReverse;
[FieldOffset(1012)]
public float gearRatioDifferential;
[FieldOffset(1016)]
public int gearDashboard;
[FieldOffset(1020)] public byte onJob;
[FieldOffset(1021)] public byte jobFinished;
public bool GetBool(Ets2SdkBoolean i)
{
if (i == Ets2SdkBoolean.TrailerAttached)
return flags[1] > 0;
return aux[(int)i] > 0;
}
}
当然,在原来的 .net framework 演示项目类中工作。
问题可能出在非 DWORD 对齐数组:link
但据我所知,我无法更改数组的大小(这是 C++ 对象在 SharedMemory 中的映射)。
而且我不知道如何处理这个问题 - 以及为什么该代码在 .net 框架上工作。
有什么建议吗?
最佳答案
我使用了不同的库:link .代码现在可以运行了。
它的工作方式相同,但具有不同的数据结构:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal struct Ets2TelemetryStructure
{
public uint time;
public uint paused;
public uint ets2_telemetry_plugin_revision;
public uint ets2_version_major;
public uint ets2_version_minor;
// ***** REVISION 1 ****** //
public short engine_enabled;
public short trailer_attached;
public float speed;
public float accelerationX;
public float accelerationY;
public float accelerationZ;
public float coordinateX;
public float coordinateY;
public float coordinateZ;
public float rotationX;
public float rotationY;
public float rotationZ;
public int gear;
public int gears;
public int gearRanges;
public int gearRangeActive;
public float engineRpm;
public float engineRpmMax;
public float fuel;
public float fuelCapacity;
public float fuelRate;
public float fuelAvgConsumption;
public float userSteer;
public float userThrottle;
public float userBrake;
public float userClutch;
public float gameSteer;
public float gameThrottle;
public float gameBrake;
public float gameClutch;
public float TruckMass;
public float trailerWeight;
public int modelOffset;
public int modelLength;
public int trailerOffset;
public int trailerLength;
public int timeAbsolute;
public int gearsReverse;
public float trailerMass;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] trailerId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] trailerName;
public int jobIncome;
public int jobDeadline;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCitySource;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCityDestination;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCompanySource;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] jobCompanyDestination;
// ***** REVISION 3 ****** //
public int retarderBrake;
public int shifterSlot;
public int shifterToggle;
public int fill;
public byte cruiseControl;
public byte wipers;
public byte parkBrake;
public byte motorBrake;
public byte electricEnabled;
public byte engineEnabled;
public byte blinkerLeftActive;
public byte blinkerRightActive;
public byte blinkerLeftOn;
public byte blinkerRightOn;
public byte lightsParking;
public byte lightsBeamLow;
public byte lightsBeamHigh;
public byte lightsAuxFront;
public byte lightsAuxRoof;
public byte lightsBeacon;
public byte lightsBrake;
public byte lightsReverse;
public byte batteryVoltageWarning;
public byte airPressureWarning;
public byte airPressureEmergency;
public byte adblueWarning;
public byte oilPressureWarning;
public byte waterTemperatureWarning;
public float airPressure;
public float brakeTemperature;
public float fuelWarning;
public float adblue;
public float adblueConsumption;
public float oilPressure;
public float oilTemperature;
public float waterTemperature;
public float batteryVoltage;
public float lightsDashboard;
public float wearEngine;
public float wearTransmission;
public float wearCabin;
public float wearChassis;
public float wearWheels;
public float wearTrailer;
public float truckOdometer;
}
似乎 .net 核心在处理未正确对齐的数组方面存在一些问题 - 在这个库中由两个短变量替换。我认为这是以前使用的库中的错误,例如 Pavel Anikhouski在评论中说。
关于C# System.TypeLoadException : Could not load type because it contains an object field at offset - code from . .net 核心上的 net 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62490086/
我有一个带有帮助页面的 Web API 2 项目,该项目在本地运行良好,但当我将其推送到 Azure 时抛出此错误: Method not found: 'System.String System.S
我有两台服务器,但通常运行相同的设置 - IIS、SQL Server 等。一台给我这个错误,另一台没有。我从 Visual Studio 向两者发布相同的代码。 它们都在运行 .NET CLR Ve
System.out声明为 public static final PrintStream out。 但是你可以调用System.setOut()重新分配它。 嗯?如果它是 final,这怎么可能?
System.out被声明为 public static final PrintStream out。 但是您可以调用System.setOut()重新分配它。 嗯?如果是 final,这怎么可能?
我有这个 linq 查询: private void GetReceivedInvoiceTasks(User user, List tasks) { var areaIds = user.A
我有一个 MonoTouch 应用程序,当我为设备编译它时,出现以下错误: Error MT2002: Can not resolve reference: System.Boolean System
您好,我有一个名为 DailyVisitReport 的 View 。在该 View 中,我有两个名为 FromDate 和 toDate 的字段。如果我选择 FromDate 和 ToDate 取决
是否可以从 ObjectContext 对象中读取元组列表? 我在存储过程中有类似这样的数据库查询 SELECT T.Id as Item1, -- this is guid T.Wo
我正在尝试创建 Odata 端点,但每当我尝试执行任何涉及日期的查询时都会收到此错误。 我在下面的非常简单示例中重新创建了它。 数据库表 EDMX(片段)
我正在尝试创建 Odata 端点,但每当我尝试执行任何涉及日期的查询时都会收到此错误。 我在下面的非常简单示例中重新创建了它。 数据库表 EDMX(片段)
我有一个方法可以从数据读取器的数据中生成类类型列表。 if (datareader != null && datareader .HasRows) { Dictionary pDict= GetP
我有一些旧的 C++ 代码,它们使用 stdio 进行输入和输出。该代码还通过 fork 生成新进程。它将 stdio 重新映射到每个新进程,以便每个 session 获取其各自的数据。 我正在考虑使
我的应用程序可以很好地构建/链接/部署到模拟器,但我只是第一次尝试将应用程序构建/部署到真实设备,并且链接器失败。 我不使用 System.Console或 ConsoleColor在我的应用程序的任
主要是我很好奇。 我们有一个名为 Unit 的对象在我们的代码库中 - 代表桥梁或道路的组件。在我们的例子中,看到带有 Unit 的 ReactiveUI 命令可能会模棱两可。作为声明中的泛型之一。
我试图将Object变量转换为StreamWriter。但是,它不起作用。有什么错? StreamWriter file = (StreamWriter) myObject; 最佳答案 myObjec
为什么以下不编译? using System; using System.Linq; using System.Linq.Expressions; public static class Extens
我正在使用 Visual Studio Community 2015 开发面向 .NET 4.5 的 Visual Basic 应用程序.我没有编写应用程序,所以我使用 NuGet 添加了所有缺失的依
我刚刚开始使用 powershell,我正在制作一个非常简单的加密功能。我想获取字符串中的每个字符,将其转换为 int 并添加一个选定的数字,然后将其转换回一个字符。 这工作正常: function
一些使用我的应用程序的人似乎变得越来越 System.MissingMethodException: Method not found: 'System.Object System.Windows.T
我是 C# 和实体的新手 我想知道是否有人在这里帮助我。我选择了哪个返回我的 customerid,所以我想将它作为参数传递给我的构造函数,我的构造函数参数类型是 guid 但我的选择类型不同,我不知
我是一名优秀的程序员,十分优秀!