Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "Method '~' of object '~' failed" at runtime mean?

Tags:

com

vb6

I'm trying to run a legacy VB6 application on my desktop (it doesn't have a user interface, being a command-line app), and when I do, I get a message box saying

Run-time error '4099':

Method '~' of object '~' failed

This means nothing to me; does anyone have an idea what is going wrong?

like image 672
Cyberherbalist Avatar asked Aug 19 '09 19:08

Cyberherbalist


4 Answers

That can happen when supporting libraries (dlls or ocxs) are not registered properly or the versions of the installed libraries are different (and incompatible) with the version the app was compiled against originally.

Make sure all dependent libraries are registered and the proper version.

You may have to recompile the app to make it work with newer versions of the supporting libraries.

like image 151
DJ. Avatar answered Oct 02 '22 06:10

DJ.


This message occurs when a Visual Basic 6 application makes a COM interface call which throws an exception (i.e. returns a failure HRESULT). In this case, VB6 jumps to an exception handler (as set by On Error). In the exception handler there is visible an object Err which contains details of the exception.

If the object implements ISupportErrorInfo, and it does actually support error info, and it did set error info, then Err.Description takes the string that is in the error info set by the object. Otherwise, Err.Description takes the string Method ~ of ~ failed.

IDK whether other versions of VB do the same thing; or if the message is also set in other scenarios besides the one I have just described.

like image 44
M.M Avatar answered Oct 02 '22 05:10

M.M


Another cause can be when using automation, some minor-version mismatch of Office:

I have a legacy VB5+Access app (which i'm in the process of rewriting in Delphi and replacing all the automation mess with clean OpenDocument generation) that ran well on some systems and gave the error on others.

This error would happen when generating an Excel spreadsheet, and seemed harmless (except the annoyance and as it would show a dozen times the risk of user clicking 'Abort' in the middle) as if always clicking 'Ignore' everything worked as expected.

I eventually found the cause was the way Office 97 was installed:

The error would show up if the Office 97 setup sequence was:

  • Office 97 SR0 install CD
  • apply SR1 patch
  • apply SR2 patch

but not if it was installed with:

  • Office 97 SR1 install CD
  • apply SR2 patch

Doing an uninstall / reinstall with SR1 setup on the affected systems solved the problem.

like image 41
Julien Marodon Avatar answered Oct 02 '22 05:10

Julien Marodon


I have VB6 SP6 and I can reproduce this behavior. In a fresh project, put this code into a form. The project runs normally with F5. Right click the project and select Publish then Build Outputs. This generates the error message.

Option Explicit

Public Sub Init()
    Dim blnErrorHandling As Boolean

    If False Then
        blnErrorHandling = True
    Else
        blnErrorHandling = False
End Sub

Now comment out the last four lines:

Option Explicit

Public Sub Init()
    Dim blnErrorHandling As Boolean

'    If False Then
'        blnErrorHandling = True
'    Else
'        blnErrorHandling = False
End Sub

You no longer get the error and the outputs are built normally. I was quickly adding in some error handling to locate the source of a crash and If False Then is perfectly valid. The MDAC checker said all was ok and a reboot didn't solve the problem.

like image 28
Brian Leeming Avatar answered Oct 02 '22 05:10

Brian Leeming