简体   繁体   English

系统算术异常:Delphi通过C ++ / CLI包装器调用C#DLL

[英]System Arithmetic Exception: Delphi calling C# DLL via C++/CLI wrapper

I have a C# DLL that uses the XslCompiledTransform class for xml manipulations. 我有一个使用XslCompiledTransform类进行xml操作的C#DLL。 I stole a C++/CLI wrapper for the C# DLL. 我偷了C#DLL的C ++ / CLI包装器。

When using Delphi 5 to implement the C++/CLI wrapper, I receive a System Arithmetic error. 使用Delphi 5实现C ++ / CLI包装器时,出现系统算术错误。 Here is the Delphi 5 declaration: 这是Delphi 5声明:

procedure XsltMethod(XmlPath, XsltPath: PWideChar); cdecl; external 'ahma.dll';

The body of the C# public method creates a new XslCompiledTransform object and the exception pops up right when the newly created object runs its load method. C#公共方法的主体创建一个新的XslCompiledTransform对象,并且当新创建的对象运行其load方法时,该异常立即弹出。 For example: 例如:

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XsltFile);

As mentioned earlier, the exception thrown from the .NET DLL is a System Arithmetic Exception. 如前所述,.NET DLL引发的异常是系统算术异常。 This only happens when called from a Delphi executable. 这仅在从Delphi可执行文件中调用时发生。

I guess I should mention calling the object's load method again works fine. 我想我应该提一下再次调用对象的load方法可以正常工作。 So catching the exception and running the method for a second "pass" acts like a popup blocker. 因此,捕获异常并为第二次“通过”运行该方法就像一个弹出窗口阻止程序。 But for exceptions, of course. 但是当然有例外。

Random thoughts: 随意的想法:

  • I think you should start by debugging your assembly from Visual Studio. 我认为您应该首先从Visual Studio调试程序集。 Insert a messagebox or other wait statement in the Delphi code, then attach to process from Visual Studio. 在Delphi代码中插入一个消息框或其他等待语句,然后从Visual Studio附加到进程。 Tracing the C# might provide a couple of hints on what is going wrong. 跟踪C#可能会提供一些关于出问题的提示。 If you can't get it working, at least add logging of the incoming parameters. 如果您无法使其正常运行,请至少添加对传入参数的记录。
  • In delphi, you don't need to escape backslashes. 在delphi中,您不需要转义反斜杠。
  • Are you sure the E0434F4D is not some innocent first-chance exception? 您确定E0434F4D并不是一些无辜的优先机会吗? If you do not debug (or continue from the JIT debugger exception stop, which I'm not entirely sure is possible with Delphi 5), is the behaviour indeed faulty? 如果不进行调试(或者从JIT调试器异常停止处继续(我不确定是不是完全可以通过Delphi 5实现)),则该行为确实存在问题吗?
  • Could we please refer to "native Win32 assembly" as "DLL", like we used to call them for the past 20 years? 能否像过去20年来我们将其称为“ DLL”一样将“本机Win32程序集”称为“ DLL”? :-) :-)

Maybe you suffer from differences in the Floating-Point Control Register as stated here . 也许你从浮点控制寄存器的差异受苦说这里 Also see this QC report. 另请参阅质量控制报告。 You could try calling Set8087CW($133F); 您可以尝试致电Set8087CW($ 133F); in your Delphi program. 在您的Delphi程序中。 Be cautious of floating point problems in your Delphi code after that. 此后,请谨慎使用Delphi代码中的浮点问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM