Microsoft KB Archive/820126

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

Article ID: 820126

Article Last Modified on 5/22/2003

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition

-





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 , 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. .dll. When you build your Web service application, the build sequence creates a virtual directory that is named   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.



Steps to Reproduce the Problem
Steps to Create a COM Component  Run Microsoft Visual Basic 6.0. Select ActiveX DLL and then click Open.  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  On the File menu, click Make Project1.dll to create the ActiveX DLL. Type MyAddNumbersComponent as the component name and then click OK.</li></ol>

Steps to Create a .NET Web Service <ol> Run Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New and then click Project.</li> 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.</li> Type the project name, MyWebService, and then click OK.</li> In Class view, right-click the MyWebService class, point to Add, and then click Add Method.</li> 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</li>  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); </li> In Solution Explorer, right-click Add Reference to add a reference to the COM component.</li> Click Browse to locate your COM component that you created in an earlier section.</li> Select COM component and then click OK to close the Add Reference dialog box.</li>  Open MyWebService.cpp and then add a USING statement before the #INCLUDE &quot;.\MYWEBSERVICECLASS.H&quot; statement. The code looks as follows: using namespace Interop::Project1; </li>  Modify the AddTwoNumbers Web service method: short MyWebService::MyWebServiceClass::AddTwoNumbers(short Num1, short Num2) {  Class1Class *obj = new Class1Class; return obj->AddNumbers (&Num1,&Num2); } </li> Build and then run the application.</li> A Web page appears with the AddTwoNumbers method as a link. Click the AddTwoNumbers method.</li> In the Num1 text box, type the first number. In the Num2 text box, type the second number. Click Invoke.
 * 1) include &quot;.\MyWebServiceClass.h&quot;

The error message exception in the &quot;Symptoms&quot; section may appear.</li></ol>

Keywords: kbbug kbijw kbwebservices kbcominterop KB820126

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.