Microsoft KB Archive/815636

From BetaArchive Wiki
Knowledge Base


DOC: "File or assembly name EventSrc, or one of its dependencies, was not found" Error When You Export the Assembly to a Type Library by Using TlbExp.exe

Article ID: 815636

Article Last Modified on 5/12/2007



APPLIES TO

  • Microsoft .NET Framework 1.0
  • Microsoft .NET Framework 1.1



SYMPTOMS



When you follow the steps in the "Raising Events Handled by a COM Sink" MSDN article, you receive the following error when you export the assembly to a Type Library by using Tlbexp.exe:

TlbExp error: File or assembly name EventSrc, or one of its dependencies, was not found.

For additional information, click the following link to view the "Raising Events Handled by a COM Sink" MSDN article:

CAUSE

You can specify the CustomInterfaceAttribute with a string parameter. The string argument must specify the event source interface. The string argument can also specify the strong name of the assembly. The strong name must be separated by a comma. In the "Raising Events Handled by a COM Sink" MSDN article, the EventSrc in the ComSourceInterfaces attribute string argument specifies the assembly that the event source is defined in. The default assembly name property for the example is set as ClassLibrary1 (the default name of your project). When the Type Library Exporter (TlbExp) Microsoft .NET Framework tool exports the event source interface from an assembly, it interprets the attributes associated with the class. TlbExp expects the event source interface that is defined by the ComSourceInterfaces attribute to be in an assembly named EventSrc.

RESOLUTION

To resolve the problem in the code, use one of the following four methods:

  1. Remove the reference for the assembly from the ComSourceInterfaces attribute. To do this, follow the steps for one of the following samples:
    • Microsoft Visual Basic Sample
      1. Make the following change to your code sample:

        Replace
        <ComSourceInterfaces("EventSource.ButtonEvents, EventSrc")> _

        with

        <ComSourceInterfaces("EventSource.ButtonEvents")> _
        Note You must make this change at line 25 of the Visual Basic sample for the Managed server (event source) code.
      2. Clear the Root namespace property for the project. To do this, follow these steps:
        1. In Solution Explorer, expand the Project node, and then click Properties.
        2. In the Project Property Pages dialog box, click to select General under Common Properties.
        3. Clear the contents of the Root namespace property. Click OK.
    • Microsoft Visual C# Sample Make the following changes to your code sample:

      Replace
      [ComSourceInterfaces("EventSource.ButtonEvents, EventSrc")]

      with

      [ComSourceInterfaces("EventSource.ButtonEvents")]
      Note You must make this change at line 21 of the Visual C# sample for the Managed server (event source) code.
  2. Instead of using the string argument for the ComSourceInterface attribute, use the type argument. To do this, use one of the following samples.
    • Visual Basic Sample
      1. Make the following change to your code sample:

        Replace
        <ComSourceInterfaces("EventSource.ButtonEvents, EventSrc")> _

        with

        <ComSourceInterfaces(GetType(EventSource.ButtonEvents))> _
      Note You must make this change at line 25 of the Visual Basic sample for the Managed server (event source) code.
    • Visual C# Sample Make the following changes to your code sample:

      Replace
      [ComSourceInterfaces("EventSource.ButtonEvents, EventSrc")]

      with

      [ComSourceInterfaces(typeof(EventSource.ButtonEvents))]
      Note You must make this change at line 21 of the Visual C# sample for the Managed server (event source) code.
  3. Change the assembly name to EventSrc in Visual Studio .NET. To do this, follow these steps to change the default value of the Assembly Name property:
    1. In Visual Studio .NET, expand the Project node in Solution Explorer, and then click Properties.
    2. In the Project Property Pages dialog box, click General under Common Properties.
    3. Change the default value of the Assembly Name to EventSrc in the right pane of the Project Property Pages dialog box. Click OK.
    4. For the Visual Basic sample, clear the contents of the Root namespace property. To do this, follow these steps:
      1. In Solution Explorer, expand the Project node, and then click Properties.
      2. In the Project Property Pages dialog box, click to select General under Common Properties.
      3. Clear the contents of the Root namespace property. Click OK.
  4. When you create the Visual Basic project or the Visual C# project in Visual Studio .NET to test the sample code, set the name of the project to EventSrc.

    For the Visual Basic sample, clear the contents of the Root namespace property. To do this, follow these steps:
    1. In Visual Studio .NET, expand the Project node in Solution Explorer, and then click Properties.
    2. In the Project Property Pages dialog box, click to select General under Common Properties.
    3. Clear the contents of the Root namespace property. Click OK.


MORE INFORMATION

The "Raising Events Handled by a COM Sink" MSDN article describes how to interoperate a .NET Framework event source with a COM event sink. The example in the article defines an event sink interface with a managed event source. The component that sources the events is associated with the event sink interface by using the ComSourceInterfaces attribute. The ComSourceInterfaces attribute discussed in the sample is stated as follows:

[ComSourceInterfaces("EventSource.ButtonEvents, EventSrc")]

The code is compiled and TlbExp is used to generate a Type Library. A COM client uses the Type Library to sink the events that are raised by the managed server. When this behavior occurs, you receive the error message that is described in the "Symptoms" section of this article.

Keywords: kbdocerr KB815636