Microsoft KB Archive/843407

= You receive a &quot;fatal error C1192&quot; error message when you build a Visual C++ .NET 2003 application in Release mode =

Article ID: 843407

Article Last Modified on 1/5/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition

-





SYMPTOMS
When you add a reference to an assembly by using the Add Reference dialog box in a Microsoft Visual C++ .NET 2003 application, and then you build the application in Release mode, you receive an error message that is similar to the following:

fatal error C1192: #using failed on 'c:\myproject\myapp\debug\MyDll.dll'



CAUSE
The compiler searches for the referenced assembly in the Debug folder. However, the assembly is located in the Release folder when you are working in Release mode. Therefore, the behavior that is mentioned in the &quot;Symptoms&quot; section occurs.



WORKAROUND
To work around this behavior, use one of the following methods:
 * Use the #using statement to add the reference to the assembly.
 * Specify the assembly search path in the project properties.

Use the #using statement to add the reference to the assembly
 In Solution Explorer, expand  , and then expand References.

Note  is a placeholder for the name of your Visual C++ .NET 2003 application. Right-click   under References, and then click Remove.

Note  is a placeholder for the name of your referenced assembly. In Solution Explorer, right-click  , and then click Project Dependencies. The Project Dependencies dialog box appears. In the Project Dependencies dialog box, click   in the Projects list, and then click to select the   check box under Depends on. Click OK. In Solution Explorer, expand Source Files under  .</li> Right-click  .cpp, and then click Open. The code view of the .cpp file opens.</li>  Locate the following code:  Add the following code after the code that you located in step 8: On the Build menu, click Build Solution.</li></ol>
 * 1) using <mscorlib.dll> </li>
 * 1) using &quot;MyDll.dll&quot; </li>

Specify the assembly search path in the project properties

 * 1) In Solution Explorer, expand  , and then expand References.
 * 2) Right-click   under References, and then click Remove.
 * 3) In Solution Explorer, right-click  , and then click Properties. The MyApp Property Pages dialog box appears.
 * 4) In the left pane, click C/C++, and then click General.
 * 5) In the Resolve #using References box, type C:\MyProject\MyApp\Release.
 * 6) Under C/C++, click Advanced, and then type  .dll in the Force #using box.
 * 7) In the   Property Pages dialog box, click OK.
 * 8) On the Build menu, click Build Solution.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to reproduce the behavior
To reproduce this behavior: <ol> Create a Visual C++ .NET 2003 Console Application project: <ol style="list-style-type: lower-alpha;"> Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project. The New Project dialog box appears.</li> Under Project Types, click Visual C++ Projects.</li> Under Templates, click Console Application (.NET).</li> In the Name box, type MyApp .</li> In the Location box, type C:\MyProject, and then click OK.</li></ol> </li> Create an assembly, and then add a reference to the assembly: <ol style="list-style-type: lower-alpha;"> On the File menu, point to Add Project, and then click New Project. The Add New Project dialog box appears.</li> Under Project Types, click Visual C++ Projects.</li> Under Templates, click Class Library (.NET).</li> In the Name box, type MyDll, and then click OK.</li> <li>In Solution Explorer, right-click MyDll.h, and then click Open. The code view of the MyDll.h file opens.</li> <li> Add the following code to the Class1 class: public: int add_nums(int a, int b) { int c;  c=a+b; return c; } </li> <li>In Solution Explorer, right-click MyApp, and then click Add Reference. The Add Reference dialog box appears.</li> <li>In the Add Reference dialog box, click the Projects tab.</li> <li>In the Add Reference dialog box, click Select to add a reference to the MyDll project, and then click OK.</li></ol> </li> <li>Build your application in Release mode: <ol style="list-style-type: lower-alpha;"> <li>In Solution Explorer, right-click MyApp.cpp, and then click Open. The code view of the MyApp.cpp file opens.</li> <li> Replace the existing code in the _tmain procedure with the following code: //Create an instance of the Class1 class in the MyDll.dll file. MyDll::Class1 *obj= new MyDll::Class1; int result; result=(*obj).add_nums(2,3); Console::WriteLine(result); Console::ReadLine; return 0; </li> <li>On the File menu, click Save All.</li> <li>On the File menu, click Exit to close the project.</li> <li>Double-click the MyProject folder in the C folder on the computer, and then double-click the MyApp folder.</li> <li>In the MyApp folder, right-click the MyApp.suo file, and then click Delete.</li> <li>In the Confirm File Delete dialog box, click Yes.</li> <li>Right-click the MyApp.sln file, and then click Open.</li> <li>In Solution Explorer, right-click MyApp, and then click Properties. The MyApp Property Pages dialog box appears.</li> <li>In the MyApp Property Pages dialog box, click Configuration Manager. The Configuration Manager dialog box appears.</li> <li>In the Configuration Manager dialog box, click Release in the Active Solution Configuration list, and then click Close.</li> <li>In the MyApp Property Pages dialog box, click OK.</li> <li>On the Build menu, click Build Solution.</li></ol> </li></ol>

You receive the error message that is mentioned in the &quot;Symptoms&quot; section.

<div class="references_section">