Err.Number(VB6 与 C#)

发布于 2024-09-19 21:46:42 字数 573 浏览 4 评论 0原文

我使用 Artinsoft 的 VB6 到 .NET 向导将 VB6 应用程序转换为 C#,并且在以前使用 Err.Number 的任何地方都收到升级警告;

//UPGRADE_WARNING: (2081) 错误编号 有一个新的行为。

转换后的代码指的是;

Microsoft.VisualBasic.Information.Err().Number

我没有运气找出其中的区别。有谁知道这可能是什么,或者忽略这个警告是否安全?

更新

对于任何将来偶然发现这个问题的人 - 一句警告;在 C# .NET 应用程序中继续使用 Err.Number 是不安全的。该属性仍然可用,但在发生错误后并未按预期填充。唯一按预期填充的情况是错误来自 COM 组件。

正常错误(例如数据库访问、IO 操作等)不会为 Err().Number 提供任何值,因此不幸的是,必须重构其使用。

奇怪的是,在 VB .NET 中,它仍然按预期工作,因此在决定转换的目标语言时,也许需要记住这一点。

I've used Artinsoft's VB6 to .NET wizard to convert a VB6 application to C# and I'm getting an upgrade warning in any place where Err.Number was previously used;

//UPGRADE_WARNING: (2081) Err.Number
has a new behavior.

The converted code is referring to;

Microsoft.VisualBasic.Information.Err().Number

I haven't had any luck finding out what the difference is. Does anyone know what it might be, or is it safe to ignore this warning?

UPDATE

For anyone who stumbles across this question in the future - a word of warning; It is NOT safe to continue using Err.Number in a C# .NET application. The property is still available, however it is not populated after errors as expected. The only case in which it is populated as expected is if the error comes from a COM component.

Normal errors e.g. DB access, IO operations etc. will not give any value to Err().Number, and so its use must be refactored unfortunately.

Strangely enough, in VB .NET, it still does work as expected, so perhaps this is something to keep in mind when making a decision on the target language for conversion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯淡〆 2024-09-26 21:46:42

基本上 VB.NET 支持 Err.Number 属性,并且它的工作方式与 VB6 中几乎相同,但是当升级到 C# 时,Microsoft.VisualBasic.Information.Err().Number 未正确填充,您不应该依靠它。

唯一可以确定设置错误号的情况是错误由 COM 互操作组件生成时,在这种情况下,您可以检查异常的 InnerException 成员中的错误号。

您应该转换 .NET 异常的所有 Err.Number 用法,并修改逻辑以通过结构化错误处理正确运行。

问候

basically VB.NET has support for the Err.Number property, and it works pretty much the same as in VB6, however when upgrading to C# the Microsoft.VisualBasic.Information.Err().Number is not populated correctly, and you should not rely on it.

The only scenario where the error number is set for sure, is when the error is generated by a COM interop component, in which case you can check the error number in the InnerException member of the exception.

You should convert all the Err.Number usages for .NET exceptions, and modify the logic to behave correctly with structured error handling.

regards

方圜几里 2024-09-26 21:46:42

2000 年 10 月 MSDN 中对 VB6 Err.Number 的描述:

返回或设置指定错误的数值。 Number 是 Err 对象的默认属性。读/写。

来自 MSDN

返回或设置指定错误的数值。读/写。

2000 年 10 月 MSDN 中的注释被逐字复制到 VB.NET 的在线版本中,包括示例。两者之间似乎并没有什么不同。

Description of VB6 Err.Number from October 2000 MSDN:

Returns or sets a numeric value specifying an error. Number is the Err object's default property. Read/write.

Description of VB.NET Err.Number from MSDN:

Returns or sets a numeric value specifying an error. Read/write.

The remarks from the Oct 2000 MSDN are copied word for word in the online version for VB.NET including the example. Doesn't seem to be anything different between the two.

少女七分熟 2024-09-26 21:46:42

也许使用的数字已经改变?

Maybe the numbers used have changed?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文