BUG: New Interop DLL Is Not Put in the Correct Location for the Project When a COM Component Is Added (820126)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)

SYMPTOMS

You can create a .NET Web service by using Visual C++ .NET. The Web service uses the COM component to perform any complex logic. However, when you try to access the Web service method that uses the Component Object Model (COM) component, you may receive the following error message exception in the browser:

System.IO.FileNotFoundException: File or assembly name <Interop Assembly name>, or one of its dependencies, was not found.

CAUSE

When you add a reference to a COM component in a project, Visual C++ .NET 2003 creates an Interop assembly with the file name Interop.COM component filename.dll. When you build your Web service application, the build sequence creates a virtual directory that is named Project name in http://localhost. Then, the build sequence copies your Web service DLL to the newly created virtual directory. Ideally, the build sequence would copy all dependencies to the virtual directory. However, the build sequence does not do this. When the Web service calls the COM method, the Web service method does not locate the Interop assembly, and an exception is thrown.

RESOLUTION

To resolve this problem, you can manually copy the Interop DLL to the virtual directory that is associated with the project. Interop DLLs exist in the same directory where your Web service DLL exists.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Problem

Steps to Create a COM Component
  1. Run Microsoft Visual Basic 6.0.
  2. Select ActiveX DLL and then click Open.
  3. Open the code window and paste the following code in that window:
    Function AddNumbers(Num1 As Integer, Num2 As Integer) As Integer
        AddNumbers = Num1 + Num2
    End Function
    
  4. On the File menu, click Make Project1.dll to create the ActiveX DLL.
  5. Type MyAddNumbersComponent as the component name and then click OK.
Steps to Create a .NET Web Service
  1. Run Microsoft Visual Studio .NET 2003.
  2. On the File menu, point to New and then click Project.
  3. In the New Project dialog box under the Project Types section, click Visual C++ Projects and then click .NET. Under the Templates section, click ASP.NET Web Service.
  4. Type the project name, MyWebService, and then click OK.
  5. In Class view, right-click the MyWebService class, point to Add, and then click Add Method.
  6. Create a Web service method with the following parameters:

    Function Name: AddTwoNumbers
    Return Type: short

    First Parameter
    Parameter type: short
    Parameter name: Num1

    Second Parameter
    Parameter type: short
    Parameter name: Num2
  7. Open the MyWebServiceClass.h file and then locate the newly added function, AddTwoNumbers. Put the [System::Web::Services::WebMethod] attribute before the function declaration. The code to do this follows:
    [System::Web::Services::WebMethod] 
    short AddTwoNumbers(short Num1, short Num2);
    
  8. In Solution Explorer, right-click Add Reference to add a reference to the COM component.
  9. Click Browse to locate your COM component that you created in an earlier section.
  10. Select COM component and then click OK to close the Add Reference dialog box.
  11. Open MyWebService.cpp and then add a USING statement before the #INCLUDE ".\MYWEBSERVICECLASS.H" statement. The code looks as follows:
    #include ".\MyWebServiceClass.h"
    using namespace Interop::Project1; 
  12. Modify the AddTwoNumbers Web service method:
    short MyWebService::MyWebServiceClass::AddTwoNumbers(short Num1, short Num2)
    {
       Class1Class *obj = new Class1Class(); 
    	
       return obj->AddNumbers (&Num1,&Num2); 
    }
    
  13. Build and then run the application.
  14. A Web page appears with the AddTwoNumbers method as a link. Click the AddTwoNumbers method.
  15. In the Num1 text box, type the first number. In the Num2 text box, type the second number. Click Invoke.

    The error message exception in the "Symptoms" section may appear.

Modification Type:MajorLast Reviewed:5/22/2003
Keywords:kbWebServices kbIJW kbCOMInterop kbbug KB820126 kbAudDeveloper