vbObjectError how to use this one into c# code

1.4k views Asked by At

Let me know how to use this "vbObjectError" in c# code: //This is my VB code

Public Enum CryptoErrors
    ErrorAquiringContext = vbObjectError + 1056
    ErrorCreatingHash = vbObjectError + 1057
    ErrorCreatingHashData = vbObjectError + 1058
    ErrorDerivingKey = vbObjectError + 1059
    ErrorEncryptingData = vbObjectError + 1060
    ErrorDecryptingData = vbObjectError + 1061
    ErrorInvalidHexString = vbObjectError + 1062
    ErrorMissingParameter = vbObjectError + 1063
    ErrorBadEncryptionType = vbObjectError + 1064
End Enum
1

There are 1 answers

1
Joe On

You could translate it literally as:

public enum CryptoErrors
{   
     ErrorAcquiringContext = Microsoft.VisualBasic.Constants.vbObjectError + 1056,
     ...
}

in which case you need a reference to Microsoft.VisualBasic.dll.

If you don't want to take a dependency on Microsoft.VisualBasic.dll, you could define your own C# constant instead:

public const int VBObjectError = -2147221504;

But I'd question why you'd need it in a C# application. Constants offset from vbObjectError normally correspond to an HRESULT and are used in a VB Err.Raise statement.

In C# you'd just throw an exception.