Microsoft KB Archive/818438

From BetaArchive Wiki

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 <COMLIBDLL> not found
The referenced component <COMLIBDLL> 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 "Symptoms" 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.

MORE INFORMATION

Steps to Reproduce the Behavior

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

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual J# Projects under Project Types, and then click Console Application under Templates.
  4. Type MyTestConsoleApplication in the Name box, and then click OK.
  5. In Solution Explorer, right-click MyTestConsoleApplication, and then click Add Reference.
  6. Follow the instructions in the Add Reference Wizard to add the COM component that was created in the "Create a COM Component" section of this article.
  7. 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(" "+obj.TestMethod(5, 6));
        
        }
    }
  8. On the Build menu, click Build Solution.

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 "Create a COM Component" 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 "Symptoms" section of this article.


REFERENCES

For more information about Visual J# .NET, visit the following MSDN Web site:

Keywords: kberrmsg kbcompiler kbjava kbcomservices kbcominterop kbprb KB818438