Microsoft KB Archive/313666

= PRB: &quot;Assembly Generation Failed&quot; Error Message When You Try to Build a Managed DLL Without a Strong Name =

Article ID: 313666

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q313666



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:  In Microsoft Visual Studio .NET, open the properties of the Visual Basic project in which you want to reference the COM component. Delete the existing reference to your COM component. 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

 Add a reference to the output file from Tlbimp.exe to your Visual Basic .NET project. 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 &quot;Microsoft Visual Basic .NET&quot; steps, modify the command line that is provided in step 3 as follows:

tlbimp.exe MyCOMDLL.dll /delaysign /publickey:PublicKeyFile.snk /out:MyCOMInterop.dll

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

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

Keywords: kbcominterop kberrmsg kbprb KB313666

-

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

© Microsoft Corporation. All rights reserved.