Microsoft KB Archive/814197

= Error message when you try to build a Visual Basic .NET or Visual Basic 2005 project: &quot;The Dependency  in  cannot be copied to the run directory because it would overwrite the reference &quot; =

Article ID: 814197

Article Last Modified on 11/13/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





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  in  cannot be copied to the run directory because it would overwrite the reference .

Note In this error message,  is a placeholder for the DLL name, including the version information. Also,  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 &quot;Symptoms&quot; 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:
 * 2) * gacutil -i

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

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.
 * 1) Add references to the two different versions of the same DLL in your Windows Application project.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Create a class library file:  Start Visual Studio .NET or Visual Studio 2005.</li> <li>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.</li></ol> </li> <li>Create version 1.0.1.1 of the ClassA.dll file, as follows: <ol style="list-style-type: lower-alpha;"> <li> In the AssemblyInfo.vb file, locate the following code: <Assembly: AssemblyVersion(&quot;1.0.*&quot;)> </li> <li> Replace the code that you located in the previous step with the following code: <Assembly: AssemblyVersion(&quot;1.0.1.1&quot;)> Note In Visual Studio 2005, locate the following <Assembly: AssemblyVersion(&quot;1.0.0.0&quot;)> and replace with the following: <Assembly: AssemblyVersion(&quot;1.0.1.1&quot;)> </li> <li>On the Build menu, click Build Solution to create version 1.0.1.1 of the ClassA.dll file.</li> <li>Create a folder in the root folder of drive C on your computer. Name the folder ReferenceA .</li> <li>Copy version 1.0.1.1 of ClassA.dll to the ReferenceA folder.</li></ol> </li> <li>Create version 1.0.1.2 of ClassA.dll, as follows: <ol style="list-style-type: lower-alpha;"> <li> In the AssemblyInfo.vb file, locate the following code: <Assembly: AssemblyVersion(&quot;1.0.1.1&quot;)> </li> <li> Replace the code that you located in the previous step with the following code: <Assembly: AssemblyVersion(&quot;1.0.1.2&quot;)> </li> <li>On the Build menu, click Build Solution to create version 1.0.1.2 of ClassA.dll.</li> <li>Create a folder in the root folder of drive C on your computer. Name the folder ReferenceB .</li> <li>Copy version 1.0.1.2 of ClassA.dll to the ReferenceB folder.</li></ol> </li> <li>Reference version 1.0.1.1 of ClassA.dll in ClassB.dll, as follows: <ol style="list-style-type: lower-alpha;"> <li>Start Visual Studio .NET or Visual Studio 2005.</li> <li>Use Visual Basic .NET or Visual Basic 2005 to create a Class Library project. Name the project ClassB .</li> <li>On the Project menu, click Add Reference.</li> <li>In the Add Reference dialog box, click Browse.</li> <li>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.</li> <li>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.</li> <li>On the Build menu, click Build Solution to create ClassB.dll.</li></ol> </li> <li>Add references to the Windows Application project, as follows: <ol style="list-style-type: lower-alpha;"> <li>Use Visual Basic .NET or Visual Basic 2005 to create a Windows Application project. Name the project WindowsApp .</li> <li>On the Project menu, click Add Reference.</li> <li>In the Add Reference dialog box, click the Browse button.</li> <li>In the Select Component dialog box, locate ClassB.dll, and then click ClassB.dll.</li> <li>Click Open.</li> <li>In the Add Reference dialog box, click the Browse button.

The Select Component dialog box appears.</li> <li>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.</li> <li>Click Open, and then click OK to close the Add Reference dialog box.</li> <li>On the Build menu, click Build Solution.

In the Task List window, you receive the error message that is mentioned in the &quot;Symptoms&quot; section of this article.</li></ol> </li></ol>

<div class="references_section">