PRB: "Assembly Generation Failed" Error Message When You Try to Build a Managed DLL Without a Strong Name

Article translations Article translations
Article ID: 313666 - View products that this article applies to.
This article was previously published under Q313666
Expand all | Collapse all

On This Page

SYMPTOMS

When you try to compile a managed assembly that references a COM Interop assembly or any another managed assembly that does not have a strong name, you may receive the following error message:
Assembly generation failed -- Referenced assembly 'Interop.Project1' does not have a strong name

CAUSE

When you compile an assembly with a strong name, any referenced assemblies must also have strong names.

RESOLUTION

To resolve the issue when you reference a COM Interop assembly, follow these steps:

NOTE: To resolve the issue when you reference a managed assembly that does not have a strong name, you must rebuild the assembly with a strong name.

Microsoft Visual C# .NET

If a Visual C# .NET project references the COM Interop assembly, the COM Interop assembly is generated for you when you reference the COM dynamic-link library (DLL). You can specify the wrapper assembly key file in the Visual C# project properties as follows:
  1. In Microsoft Visual Studio .NET, open the properties of the Visual C# project in which you want to reference the COM component.
  2. In the tree, click Common Properties, and then click General.
  3. In the Wrapper Assembly Key File field, add the key file.
  4. Rebuild the project.

Microsoft Visual Basic .NET

If a Visual Basic .NET project references the COM Interop assembly, you must manually generate the COM Interop assembly with Tlbimp.exe, as follows:
  1. In Microsoft Visual Studio .NET, open the properties of the Visual Basic project in which you want to reference the COM component.
  2. Delete the existing reference to your COM component.
  3. Run Tlbimp.exe from a command prompt on your COM DLL to generate an Interop assembly that has a strong name, as follows:
    tlbimp.exe MyCOMDLL.dll /keyfile:KeyFile.snk /out:MyCOMInterop.dll
  4. Add a reference to the output file from Tlbimp.exe to your Visual Basic .NET project.
  5. Rebuild the project.

If the assembly is delay signed instead of fully signed, the wrapper assembly must be delay signed. To create an assembly that is delay signed, generate the wrapper by using the TlbImp.exe tool. To do this, follow the previous steps. If you use the "Microsoft Visual Basic .NET" steps, modify the command line that is provided in step 3 as follows:
tlbimp.exe MyCOMDLL.dll /delaysign /publickey:PublicKeyFile.snk /out:MyCOMInterop.dll

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Visual Studio .NET, create a new unmanaged Active Template Library (ATL) project named Project1.
  2. Add an ATL simple object named Class1.
  3. Add a method without parameters named Test to the IClass1 interface.
  4. Build the solution.
  5. Add a Visual C# .NET Class Library project named Project2 to the solution.
  6. Add a reference to Project1 in Project2.
  7. At the top of your class1 Visual C# file, add the following:
    using Project1;
    					
  8. Derive Class1 from IClass1, as follows:
    public class Class1:IClass1
    					
  9. Implement the Test method in your Visual C# class:
    public void Test()
    {
    }
    					
  10. Give your assembly a strong name. To do this, generate a .snk file with Sn.exe, and then add the file to AssemblyKeyFile.
  11. Build Project2. You receive an error message.

Properties

Article ID: 313666 - Last Review: February 23, 2007 - Revision: 5.4
APPLIES TO
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
Keywords: 
kbcominterop kberrmsg kbprb KB313666

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com