Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am getting an occasional System.OverflowException with msg "Overflow" in a .NET call to a VB6 DLL COM server.

The exception seems to be happening somewhere in the transition from COM to .NET:

  • The top of the stack is the COM call itself, at ComClient.VBComClass.ApplicationState()
  • The VB6 ErrorHandler code is not executed, which means that the VB6 function exited normally

Is there a value or condition of a VB6 Long that would overflow a .NET int?

Code snippets:

.NET COM Client:

VBCom comObj = new VBCom();
int appState;
appState = comObj.ApplicationState();

.NET imported COM interface:

[DispId(1610809347)]
int ApplicationState();

VB6 DLL COM Server:

Public Function ApplicationState() As Long
    On Error GoTo ErrorHandler
    ApplicationState = {...call into another VB6 application...}
    Exit Function

    ErrorHandler:
    ApplicationState = -1
    RaiseEvent ErrorHandled("ApplicationState", Err, Error(Err))
End Function
share|improve this question

1 Answer 1

Have you seen this ?
Troubleshooting Exceptions: System.OverflowException
An OverflowException exception is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow. An overflow occurs when an operation produces a value too large for the destination type, infinity, or Not a Number (NaN).

share|improve this answer
    
Yes, I am asking if there is a VB6 Long value or some other condition that could cause this to throw when (I'm assuming) the .NET Interop marshals this as a CLR int. I don't see how since they are the same size. – JMH Jul 16 '12 at 19:23
    
PS If the value inside the VB6 call assigned to ApplicationState was too large, I would have expected the On Error GoTo to be invoked. Instead the VB6 function exits normally and the .NET runtime exception is thrown. – JMH Jul 16 '12 at 19:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.