是什么原因导致“对象的方法〜失败”?在 VB6 应用程序中?
我正在开发一个旧的 VB6 应用程序,最近添加了西门子 OPC 组件。在 VB6 调试器中运行时没有任何问题。
然后,我创建了一个部署包(包中包含西门子 OPC dll)并将该应用程序部署在同一台 PC 上。然后,在访问 OPC 对象时,我收到以下错误消息:
“对象的方法 ~ 失败”
谁能建议可能导致此问题的原因或我可以采取哪些措施来获取更多信息?
更新 我知道有关此错误消息的其他问题。这里让我不解的是,使用VB调试器时没有任何问题。部署后就会出现问题 - 即使在同一台计算机上也是如此。我本以为所有组件都保持注册状态并可用。
代码
Public Sub InitialiseOPC(ServerIP As String, OpcServerName As String, BaseAddress As String)
On Error GoTo ProcError
IsInitialised = False
Set MyOpcServer = New OPCServer
Dim LocalServers
LocalServers = MyOpcServer.GetOPCServers(ServerIP)
....
调用 GetOPCServers 时发生错误。这是第一次访问 OPC 组件。
有没有办法跟踪VB此时正在做什么(例如dll加载)?
更新
我尝试将西门子 dll 部署到应用程序文件夹而不是默认位置,并且不再出现此错误消息。
I am working on an old VB6 app and have recently added the Siemens OPC component. When running in VB6 debugger I have no problems.
I then created a deployment package (Siemens OPC dlls included in the package) and deployed the app on the same PC. I then get the following error message when accessing the OPC object:
'Method ~ of object ~ failed'
Can anyone suggest what might be causing this or what I can do to get more information?
UPDATE
I am aware of other questions around this error message. What is puzzling me here is that there are no problems when using the VB debugger. The problems occur after deployment - even on the same machine. I would have thought that all the components remain registered and available.
CODE
Public Sub InitialiseOPC(ServerIP As String, OpcServerName As String, BaseAddress As String)
On Error GoTo ProcError
IsInitialised = False
Set MyOpcServer = New OPCServer
Dim LocalServers
LocalServers = MyOpcServer.GetOPCServers(ServerIP)
....
The error occurs when GetOPCServers is called. This is the first time the OPC component is accessed.
Is there any way to trace what VB is doing at this time (e.g. dll loading) ?
UPDATE
I tried deploying the Siemens dlls to the application folder instead of the default locations and this error message no longer appears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Method ~ of object ~ failed
在后期绑定调用期间引发异常 (SEH) 时生成。 VB6 努力“包装”每个后期绑定调用以捕获此类意外行为。在您的情况下,很可能 VC 组件正在尝试加载依赖的 DLL 或 COM 对象并失败,但不会正常处理失败。相反,它会尝试调用空引用上的方法,并引发访问冲突或类似异常。
Method ~ of object ~ failed
is generated when an exception (SEH) is thrown during a late-bound call. VB6 makes the effort to "wrap" each late-bound call to catch such unexpected behavior.In your case most probably a VC component is trying to load a dependent DLL or COM object and fails but does not handle the failure gracefully. Instead it tries to call a method on the empty reference and bombs with an Access Violation or similar exception.