Visual basic Script calling a C# dll with COM interop error 80070002 RRS feed

  • Question


    I am working with Visual studio 2010 and have  a  problem


    I  am  calling  a DLL created in C# with COM interopt   but  not  strong  name   and   I am  calling  this  dll with  a Visual basic  script  (5.7)


    I am doing this in some steps 

    1.      Start Visual Studio .NET or Visual Studio 2010.

    2.      Open the solution that contains the project that you want to build for COM interop.

    3.      On the View menu, click Solution Explorer.

    4.      In Solution Explorer, right-click the project that you want to build for COM interop, and then click Properties.

    5.      Click Configuration Properties, and then click the Build node.

    Note In Visual Studio 2010, click Compile in the left pane.

    6.      Click to select the Register for COM Interop check box. This option is only enabled in class library projects.

    7.      Click OK to close the Property Pages dialog box.

    When  we  create the  DLL in C#


    We  check thath [assembly: ComVisible(true)]  is  set  and  also  the  [assembly: Guid("ce98044d-36ca-46b0-9507-a80f4c5d871d")]  is  set.


    This is done automatically in VS2010


    When  we  use  VBS  to call  the DLL


    1.      We  reg the DLL  with Assembly Registration Tool (Regasm.exe)  for .NET Framework 2.0

    2.      Calling from VBS  Set ax = CREATEOBJECT("")

    3.      Then I  get  an  error .the  system cant  find the  file  specified  code: 80070002


    What could  be  wrong




    Monday, May 9, 2011 8:16 AM

All replies

  • I am moving your thread into the Common Language Runtime Forum for specialized support. Thanks.
    Leo Liu [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.

    Thursday, May 12, 2011 2:20 AM
  • You may specify /codebase switch when registering .NET assembly using regasm tool, however, you may need to assign a strong name to your assembly.

    Eric Yang [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.

    Thursday, May 12, 2011 3:16 AM
  • Hello JAC_SUN,


    1. Basic Cause Of Problem.

    1.1 The basic problem is that the CLR is not able to locate your class library.

    1.2 This is so despite the fact that you have already selected the "Register for COM Interop" check box in your class library project.

    1.3 Selecting this checkbox is equivalent to calling : regasm.exe <your class libraray.dll> /tlb /codebase

    1.4 The /codebase flag will add a CodeBase setting to the registry for your class. This CodeBase registry entry contains the full path to your DLL. This enables the runtime to locate your DLL.

    1.5 Hence it is strange indeed that the runtime is still not able to locate your DLL.


    2. Possible Solutions.

    2.1 If you run regasm.exe manually, adding the /codebase flag (as suggested by Eric Yang) may help.

    2.1.1 After performing regasm.exe, lookup the registry entry for your C# class (which has now been registered for COM access).

    2.1.2 This should be located in the following registry path :


    where {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} is the CLSID for your C# class.

    Here there should be a "CodeBase" entry with a string value like the following : file:///...<your class libraray.dll>

    If no such CodeBase entry exists, we will have to investigate the issue further.


    2.2 Does your Class Library reference any other assembly ?

    2.2.1 If so, these must be in the same folder as your original class library.

    2.2.2 Selecting the "Copy Local" property for your assembly reference will ensure that this is done automatically.

    2.2.3 Failure to locate dependency assemblies is another reason for the 80070002 error.


    3. Further Advise.

    3.1 Note that although your VB Script file contains the code to run, it is actually the Script Engine wscript.exe (c:\windows\system32\wscript.exe) that executes the script.

    3.2 As such, the CLR must locate your COM-enabled C# assembly starting from the local folder of wscript.exe (i.e. the c:\windows\system32 directory).

    3.3 Hence one way to ensure that the CLR be able to locate your assembly is to copy it (and its dependency assembies) into the c:\windows\system32 folder.

    3.4 But I must quickly add that this is not a good idea. If necessary, do it only for testing and trouble shooting purposes.

    3.5 Another thing to note is that copying your class library (and all dependencies) into the same directory as your VBS script file will also not help for the reason cited in points 3.1 and 3.2 above.


    - Bio.


    Thursday, May 12, 2011 5:37 AM
  • Hey JAC_SUN.

    I have the same problem.

    Do you find a solution?


    Friday, November 18, 2011 1:12 PM