none
"Catastrophic failure" when accessing an OCX library from C# RRS feed

  • Question

  • Hi,

    I'm currently trying to use a third-party DLL from my C# application. I've registered the DLL and added it as a reference from the list of COM component. As I understand, this should create the necessary interop classes to access this DLL from C#.

    On attempting to call any methods from within the DLL I get the following exception:-

     

     

    System.Runtime.InteropServices.COMException was unhandled
     Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
     Source=mscorlib
     ErrorCode=-2147418113
     StackTrace:
      at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
      at OCXDLL._OCXDLL.MyMethod(Int32 param0, String param1, String param2, String param3, Int32 param4)
      at MyApplication.Program.Main(String[] args) in C:\MyApplication\Program.cs:line 29
      at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
     InnerException: 
    

     

    And the code I'm using to call the library:-

     

     

    using OCXDLL;
    
    namespace MyApplication
    {
     class Program
     {
      static void Main(string[] args)
      {
       OCXDLL libObj = new OCXDLL();
       libObj .MyMethod(....);<br/>   }
     }
    }
    

     

    Does anyone have any ideas as to where I'm going wrong?

     

    Thanks


    Wednesday, April 13, 2011 2:14 PM

Answers

  • Hello Pirate Adam,

    1. From the call stack, it looks like the exception was thrown by the third-party COM DLL itself, within the MyMethod() method.

    2. To help us analyse the problem, please provide the following :

    2.1 Please list out for us the IDL declaration of the MyMethod() method. You can use OLEVIEW.exe to open the DLL. The type library which is contained in the DLL will be translated into IDL and then displayed.

    2.2 On the C# side, please list out for us the Interop Assembly's C# declaration of the MyMethod() method as listed in the Object Browser of the Visual Studio IDE.

    - Bio.

     

    • Marked as answer by Paul Zhou Wednesday, April 27, 2011 8:48 AM
    Thursday, April 14, 2011 9:37 AM
  •  

    Hi Pirate,

     

    Welcome to the MSDN forum!

     

    Since haven't get more information from you, I would like to suggest you do the troubleshooting steps below.

    As you said, you can add the dll as a reference to project, I assume that the dll is a managed dll.

    1. Check the platform option. The exception may occur when the platform is not suitable to project. For example, if project built with x86, but the dll is built with x64, dll won’t be called well in the process of project.

    Much further information, please refer to /platform

    2. Check the .NET Framework target. You can check the target .NET Framework version of project and dll. Different targets version of .NET Framework may cause this issue.

    3. As Bio said, check methods in the dll.

    I hope this can help you resolve the problem.

    Have a nice day!

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Paul Zhou Wednesday, April 27, 2011 8:48 AM
    Tuesday, April 26, 2011 3:30 AM

All replies

  • Hello Pirate Adam,

    1. From the call stack, it looks like the exception was thrown by the third-party COM DLL itself, within the MyMethod() method.

    2. To help us analyse the problem, please provide the following :

    2.1 Please list out for us the IDL declaration of the MyMethod() method. You can use OLEVIEW.exe to open the DLL. The type library which is contained in the DLL will be translated into IDL and then displayed.

    2.2 On the C# side, please list out for us the Interop Assembly's C# declaration of the MyMethod() method as listed in the Object Browser of the Visual Studio IDE.

    - Bio.

     

    • Marked as answer by Paul Zhou Wednesday, April 27, 2011 8:48 AM
    Thursday, April 14, 2011 9:37 AM
  •  

    Hi Pirate,

     

    Welcome to the MSDN forum!

     

    Since haven't get more information from you, I would like to suggest you do the troubleshooting steps below.

    As you said, you can add the dll as a reference to project, I assume that the dll is a managed dll.

    1. Check the platform option. The exception may occur when the platform is not suitable to project. For example, if project built with x86, but the dll is built with x64, dll won’t be called well in the process of project.

    Much further information, please refer to /platform

    2. Check the .NET Framework target. You can check the target .NET Framework version of project and dll. Different targets version of .NET Framework may cause this issue.

    3. As Bio said, check methods in the dll.

    I hope this can help you resolve the problem.

    Have a nice day!

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Paul Zhou Wednesday, April 27, 2011 8:48 AM
    Tuesday, April 26, 2011 3:30 AM
  • Make sure that you are calling your com object's method in order... for example if you have an init method in com server, make sure it was called before calling any other functions...
    - Rajesh K http://thoughtsontechies.blogspot.com/
    Tuesday, April 26, 2011 5:34 AM