6

Artinsoft の VB6 to .NET ウィザードを使用して VB6 アプリケーションを C# に変換しましたが、Err.Number が以前に使用されていた場所でアップグレードの警告が表示されます。

//UPGRADE_WARNING: (2081) Err.Number には新しい動作があります。

変換されたコードは参照しています。

Microsoft.VisualBasic.Information.Err().Number

違いが何であるかを見つけるのは運がありませんでした。誰かがそれが何であるかを知っていますか、またはこの警告を無視しても安全ですか?

アップデート

将来、この質問に出くわす人のために - 警告の言葉。C# .NET アプリケーションで Err.Number を使い続けるのは安全ではありません。プロパティは引き続き使用できますが、エラーが発生した後、期待どおりに値が入力されません。期待どおりに値が設定される唯一のケースは、エラーが COM コンポーネントから発生した場合です。

通常のエラー (DB アクセス、IO 操作など) は Err().Number に値を与えないため、残念ながらその使用はリファクタリングする必要があります。

奇妙なことに、VB .NET ではまだ期待どおりに動作するため、変換先の言語を決定する際には、これを念頭に置いておく必要があります。

4

3 に答える 3

4

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

于 2010-09-24T21:33:27.163 に答える
1

2000 年 10 月の VB6 Err.Number の説明 MSDN:

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

MSDNからの VB.NET Err.Number の説明:

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

2000 年 10 月の MSDN のコメントは、例を含む VB.NET のオンライン バージョンにそのままコピーされています。両者に違いはないようです。

于 2010-09-17T20:50:32.717 に答える
0

使われている数字が変わったのかな?

于 2010-09-17T20:53:11.727 に答える