Error message when you try to build a Visual Basic .NET or Visual Basic 2005 project: "The Dependency <DLL> in <ProjectName> cannot be copied to the run directory because it would overwrite the reference <DLL>" (814197)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

SYMPTOMS

In Microsoft Visual Studio .NET or Microsoft Visual Studio 2005, when you try to build a Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 project that has references to different versions of the same DLL, you may receive the following error message in the Task List window:
The dependency <DLL> in <ProjectName> cannot be copied to the run directory because it would overwrite the reference <DLL>.
Note In this error message, DLL is a placeholder for the DLL name, including the version information. Also, ProjectName is a placeholder for the Visual Basic .NET or Visual Basic 2005 project name.

CAUSE

When you try to build a Visual Basic .NET or Visual Basic 2005 project that has references to different versions of the same DLL, Visual Studio .NET or Visual Studio 2005 copies one version of the DLL to the run directory. When Visual Studio .NET or Visual Studio 2005 tries to copy another version of this DLL to the same directory, you receive the error message that is mentioned in the "Symptoms" section of this article.

RESOLUTION

To resolve this problem, complete one of the following procedures.

Set the Copy Local property to False

  1. Copy two different versions of the same DLL to subfolders of the Windows Application project output directory.
  2. Add references to the different versions of the same DLL in your Windows Application Project.
  3. Set the Copy Local property to False.

Install the DLLs in the Global Assembly Cache (GAC)

  1. Type the following commands at the Visual Studio .NET or Visual Studio 2005 command prompt to install two different versions of the same DLL in GAC:
    • gacutil -i DLLName

      Note DLLName is a placeholder for the name of the DLL that is generated when you reference the original version of your DLL.
    • gacutil -i DLLName

      Note You use the same name that you used to install the original version of your DLL. Run this command from the directory that contains the modified version of your DLL.
  2. Add references to the two different versions of the same DLL in your Windows Application project.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the behavior

  1. Create a class library file:
    1. Start Visual Studio .NET or Visual Studio 2005.
    2. Use Visual Basic .NET or Visual Basic 2005 to create a Class Library project. Name the project ClassA.

      By default, the AssemblyInfo.vb file is created.
  2. Create version 1.0.1.1 of the ClassA.dll file, as follows:
    1. In the AssemblyInfo.vb file, locate the following code:
      <Assembly: AssemblyVersion("1.0.*")>
    2. Replace the code that you located in the previous step with the following code:
      <Assembly: AssemblyVersion("1.0.1.1")>
      Note In Visual Studio 2005, locate the following
      <Assembly: AssemblyVersion("1.0.0.0")>
      and replace with the following:
      <Assembly: AssemblyVersion("1.0.1.1")>
    3. On the Build menu, click Build Solution to create version 1.0.1.1 of the ClassA.dll file.
    4. Create a folder in the root folder of drive C on your computer. Name the folder ReferenceA.
    5. Copy version 1.0.1.1 of ClassA.dll to the ReferenceA folder.
  3. Create version 1.0.1.2 of ClassA.dll, as follows:
    1. In the AssemblyInfo.vb file, locate the following code:
      <Assembly: AssemblyVersion("1.0.1.1")>
    2. Replace the code that you located in the previous step with the following code:
      <Assembly: AssemblyVersion("1.0.1.2")>
    3. On the Build menu, click Build Solution to create version 1.0.1.2 of ClassA.dll.
    4. Create a folder in the root folder of drive C on your computer. Name the folder ReferenceB.
    5. Copy version 1.0.1.2 of ClassA.dll to the ReferenceB folder.
  4. Reference version 1.0.1.1 of ClassA.dll in ClassB.dll, as follows:
    1. Start Visual Studio .NET or Visual Studio 2005.
    2. Use Visual Basic .NET or Visual Basic 2005 to create a Class Library project. Name the project ClassB.
    3. On the Project menu, click Add Reference.
    4. In the Add Reference dialog box, click Browse.
    5. In the Select Component dialog box, locate ClassA.dll version 1.0.1.1, and then click ClassA.dll version 1.0.1.1.

      Note This version of ClassA.dll is located in the ReferenceA folder.
    6. Click Open, and then click OK to close the Add Reference dialog box.

      Note In Visual Studio 2005, you do not have to click Open.
    7. On the Build menu, click Build Solution to create ClassB.dll.
  5. Add references to the Windows Application project, as follows:
    1. Use Visual Basic .NET or Visual Basic 2005 to create a Windows Application project. Name the project WindowsApp.
    2. On the Project menu, click Add Reference.
    3. In the Add Reference dialog box, click the Browse button.
    4. In the Select Component dialog box, locate ClassB.dll, and then click ClassB.dll.
    5. Click Open.
    6. In the Add Reference dialog box, click the Browse button.

      The Select Component dialog box appears.
    7. Locate ClassA.dll version 1.0.1.2, and then click ClassA.dll version 1.0.1.2.

      Note This version of ClassA.dll is located in the ReferenceB folder.
    8. Click Open, and then click OK to close the Add Reference dialog box.
    9. On the Build menu, click Build Solution.

      In the Task List window, you receive the error message that is mentioned in the "Symptoms" section of this article.

REFERENCES

For more information, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbProd2Web kbDLL kbprb KB814197 kbAudDeveloper