Microsoft KB Archive/818438

= PRB: Compilation Errors Appear in a Visual J# .NET Application If You Modify the GUID of the COM Component =

Article ID: 818438

Article Last Modified on 5/16/2007

-

APPLIES TO


 * Microsoft Visual J# .NET 2003 Standard Edition

-





SYMPTOMS
You have added a reference to the Component Object Model (COM) component to your Microsoft Visual J# .NET application. When you modify the globally unique identifier (GUID) after you add a reference to the COM component, you receive the following compilation errors:

/reference file  not found

The referenced component  could not be found. Could not load the type library. Could not load the type library. Library not registered.



CAUSE
Each COM component is identified by a GUID. When you refer to the COM component in a Visual J# .NET application, the application uses the GUID to interact with the COM component. When you modify the GUID of the COM component, this change is not reflected in the Visual J# .NET application and you receive the error that is mentioned in the &quot;Symptoms&quot; section of this article.



WORKAROUND
To work around this problem, remove the reference in your Visual J# .NET application, and then add the COM component as a reference. To do this, follow these steps:
 * 1) In Microsoft Visual Studio .NET, open your Visual J# .NET project.
 * 2) In Solution Explorer, right-click COM component, and then click Remove.
 * 3) Right-click Visual J# .NET application, and then click Add Reference.
 * 4) Follow the instructions in the Add Reference Wizard to add the COM component as a reference.



STATUS
This behavior is by design.



Create a COM Component

 * 1) Start Microsoft Visual C++ 6.0.
 * 2) On the File menu, click New.
 * 3) On the Projects tab, click ATL COM AppWizard, type TestCOMLibrary in the Project name box, type C:\TestCOMLibrary in the Location box, and then click OK.
 * 4) Click Finish.
 * 5) Click OK.
 * 6) On the left pane, right-click TestCOMLibrary classes, and then click New Class.
 * 7) Type TestInterface in the Name box, and then click OK.
 * 8) Click to expand the TestCOMLibrary classes node.
 * 9) Right-click ITestInterface, and then click Add Method.
 * 10) Type MyTestMethod in the Method Name box, type [in] int a, [in] int b, [out, retval] int *c in the Parameters box, and then click OK.
 * 11) On the Build menu, click Rebuild All.

Create a Visual J# .NET Application
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. Click Visual J# Projects under Project Types, and then click Console Application under Templates. Type MyTestConsoleApplication in the Name box, and then click OK.</li> In Solution Explorer, right-click MyTestConsoleApplication, and then click Add Reference.</li> Follow the instructions in the Add Reference Wizard to add the COM component that was created in the &quot;Create a COM Component&quot; section of this article.</li>  Replace the existing code with the following code for Class1.jsl: import TESTCOMLIBRARYLib.*;

public class Class1 implements ITestInterface {   public Class1 {   }    public int TestMethod(int i, int j)    { return i+j; }   public static void main(String[] args) {       Class1 obj = new Class1; System.out.println(&quot; &quot;+obj.TestMethod(5, 6)); } } </li> On the Build menu, click Build Solution.</li></ol>

Generate a GUID and Test Application

 * 1) Open a Visual Studio .NET command prompt.
 * 2) Type guidgen at the command prompt, and then press ENTER.
 * 3) To generate a new GUID, click New GUID in the Create GUID dialog box. To copy the generated GUID to the Clipboard, click Copy.
 * 4) Make a note of this generated GUID.
 * 5) Replace the GUID value of the COM component with the GUID value that was generated in step 3 by editing the TestCOMLibrary.idl of the COM component that was created in the &quot;Create a COM Component&quot; section of this article.
 * 6) In Visual C++, click Rebuild All on the Build menu.
 * 7) In Visual Studio .NET, click Build Solution on the Build menu. You receive the error that is described in the &quot;Symptoms&quot; section of this article.

<div class="references_section">