none
.Net and VBA (Excel) Interop issue -2147024894 (80070002) Automation Error

    Question

  • I have a third party library, which I wrapped up using the .Net 4.0 C# code. I have checked the "Register for COM interop" option while building and also included a strong name to it. Once I got the tlb file, it is working pretty well on my dev machine. When I exported these dll's and registered using the regasm on my other test machine, it is having issues (-2147024894 (80070002) Automation Error).

     

    The code block for the wrapper is as below

        [Guid("89F80170-9634-4CCD-84E2-C2004893069C")]
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        public interface _Order
        {
            #region Methods
                int Launch();
            #endregion Methods
         }
    
      [Guid("71F5F31E-D86B-4FF1-89CA-BFCC3B8117BA")]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        public class Order : _Order, IDisposable
        {
    
        public Order() 
        {
           //Do Something
         } 
    
         public int Launch()
            {
                //This method calls the ThirdParty Libraries
                return this.LaunchWithAck();
            }
    
         }
    
    
    
    
    

    In the Excel, I'm able to see this class in References and can add it. But when I try to instantiate the Order class, this is when I get the run time issue.

    Run-Time Error '-2147024894 (80070002)

    Automation error

    The system cannot find the file specified

     

     

    I would appreciate your help in getting this resolved

     

    • Changed type iam_venny Thursday, September 22, 2011 10:32 PM Popped up one more question
    Tuesday, September 20, 2011 2:00 PM

Answers

  • Hello iam_venny,

     

    1. The effects of the "Register for COM interop" option.

    1.1 One potential cause of the problem could be that the assembly could not be located at runtime.

    1.2 By checking the "Register for COM interop" option in the IDE during development, the IDE will call regasm on the target assembly together with the /codebase option.

    1.3 In your particular case, this will cause regasm.exe to add the following registry entry for the Order class :

    HKEY_CLASSES_ROOT\CLSID\{71F5F31E-D86B-4FF1-89CA-BFCC3B8117BA}\InprocServer32\CodeBase=<path to your assembly> 

    1.4 This will enable the CLR to locate your assembly by following the path to your assembly.

    1.5 Without the codebase path, the CLR will have to locate your assembly (and its dependencies) using the standard search algorithm.

     

    2. Solution.

    2.1 Generally speaking, one must be familiar with the way the runtime searches for assemblies (refer to “How the Runtime Locates Assemblies” (http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.71).aspx)).

    2.2 To confirm that assembly location is the cause of the problem, one of three techniques may be used :

    • Use the /codebase flag when calling REGASM.EXE.
    • Copy all assemblies (and their dependencies) to the same folder as the client application itself.
    • Register the assemblies into the GAC.

    2.3 Note that the second technique (copying all assemblies into the same folder as the client app itself) is another way that the runtime locates assemblies. However, this may mean that you must copy the assemblies into the same folder as the Excel application (not a good idea).

    2.4 I would recommend that you first confirm the problem by using the /codebase option.

    2.5 If the problem is thereafter resolved, first unregister the assembly using regasm.exe with the /unregieter option. Then register the assembly into the GAC by using gacutil.exe. Finally run regasm.exe again on the target assembly, this time without the /codebase option.

     

    - Bio.

     

     

     


    Please visit my blog : http://limbioliong.wordpress.com/
    • Marked as answer by iam_venny Wednesday, September 21, 2011 12:46 PM
    • Marked as answer by iam_venny Friday, September 23, 2011 12:40 PM
    Wednesday, September 21, 2011 12:41 AM

All replies

  • Hello iam_venny,

     

    1. The effects of the "Register for COM interop" option.

    1.1 One potential cause of the problem could be that the assembly could not be located at runtime.

    1.2 By checking the "Register for COM interop" option in the IDE during development, the IDE will call regasm on the target assembly together with the /codebase option.

    1.3 In your particular case, this will cause regasm.exe to add the following registry entry for the Order class :

    HKEY_CLASSES_ROOT\CLSID\{71F5F31E-D86B-4FF1-89CA-BFCC3B8117BA}\InprocServer32\CodeBase=<path to your assembly> 

    1.4 This will enable the CLR to locate your assembly by following the path to your assembly.

    1.5 Without the codebase path, the CLR will have to locate your assembly (and its dependencies) using the standard search algorithm.

     

    2. Solution.

    2.1 Generally speaking, one must be familiar with the way the runtime searches for assemblies (refer to “How the Runtime Locates Assemblies” (http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.71).aspx)).

    2.2 To confirm that assembly location is the cause of the problem, one of three techniques may be used :

    • Use the /codebase flag when calling REGASM.EXE.
    • Copy all assemblies (and their dependencies) to the same folder as the client application itself.
    • Register the assemblies into the GAC.

    2.3 Note that the second technique (copying all assemblies into the same folder as the client app itself) is another way that the runtime locates assemblies. However, this may mean that you must copy the assemblies into the same folder as the Excel application (not a good idea).

    2.4 I would recommend that you first confirm the problem by using the /codebase option.

    2.5 If the problem is thereafter resolved, first unregister the assembly using regasm.exe with the /unregieter option. Then register the assembly into the GAC by using gacutil.exe. Finally run regasm.exe again on the target assembly, this time without the /codebase option.

     

    - Bio.

     

     

     


    Please visit my blog : http://limbioliong.wordpress.com/
    • Marked as answer by iam_venny Wednesday, September 21, 2011 12:46 PM
    • Marked as answer by iam_venny Friday, September 23, 2011 12:40 PM
    Wednesday, September 21, 2011 12:41 AM
  • Thanks Bio. The /codebase option worked perfectly fine.
    Wednesday, September 21, 2011 12:48 PM
  • I think it is related to Launch method. In the Launch method, after using StreamWriter objects, you need to release them.

    Moreover, it seems that your problem in original post has been resolved and you encounter another issue. Could you please mark an answer of this thread and post a new thread in correct forum: VBA forum.

    Thank you for your posting and understanding.


    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.

    Friday, September 23, 2011 6:10 AM