You receive a "fatal error C1192" error message when you build a Visual C++ .NET 2003 application in Release mode (843407)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)

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 "Symptoms" 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

  1. In Solution Explorer, expand MyApp, and then expand References.
    Note MyApp is a placeholder for the name of your Visual C++ .NET 2003 application.
  2. Right-click MyDll under References, and then click Remove.
    Note MyDll is a placeholder for the name of your referenced assembly.
  3. In Solution Explorer, right-click MyApp, and then click Project Dependencies. The Project Dependencies dialog box appears.
  4. In the Project Dependencies dialog box, click MyApp in the Projects list, and then click to select the MyDll check box under Depends on.
  5. Click OK.
  6. In Solution Explorer, expand Source Files under MyApp.
  7. Right-click MyApp.cpp, and then click Open. The code view of the MyApp.cpp file opens.
  8. Locate the following code:
    #using <mscorlib.dll>
  9. Add the following code after the code that you located in step 8:
    #using "MyDll.dll"
  10. On the Build menu, click Build Solution.

Specify the assembly search path in the project properties

  1. In Solution Explorer, expand MyApp, and then expand References.
  2. Right-click MyDll under References, and then click Remove.
  3. In Solution Explorer, right-click MyApp, 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 MyDll.dll in the Force #using box.
  7. In the MyApp Property Pages dialog box, click OK.
  8. On the Build menu, click Build Solution.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the behavior

To reproduce this behavior:
  1. Create a Visual C++ .NET 2003 Console Application project:
    1. Start Microsoft Visual Studio .NET 2003.
    2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
    3. Under Project Types, click Visual C++ Projects.
    4. Under Templates, click Console Application (.NET).
    5. In the Name box, type MyApp.
    6. In the Location box, type C:\MyProject, and then click OK.
  2. Create an assembly, and then add a reference to the assembly:
    1. On the File menu, point to Add Project, and then click New Project. The Add New Project dialog box appears.
    2. Under Project Types, click Visual C++ Projects.
    3. Under Templates, click Class Library (.NET).
    4. In the Name box, type MyDll, and then click OK.
    5. In Solution Explorer, right-click MyDll.h, and then click Open. The code view of the MyDll.h file opens.
    6. Add the following code to the Class1 class:
      public: int add_nums(int a, int b)
      {
         int c;
         c=a+b;
         return c;
      }
    7. In Solution Explorer, right-click MyApp, and then click Add Reference. The Add Reference dialog box appears.
    8. In the Add Reference dialog box, click the Projects tab.
    9. In the Add Reference dialog box, click Select to add a reference to the MyDll project, and then click OK.
  3. Build your application in Release mode:
    1. In Solution Explorer, right-click MyApp.cpp, and then click Open. The code view of the MyApp.cpp file opens.
    2. 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;
    3. On the File menu, click Save All.
    4. On the File menu, click Exit to close the project.
    5. Double-click the MyProject folder in the C folder on the computer, and then double-click the MyApp folder.
    6. In the MyApp folder, right-click the MyApp.suo file, and then click Delete.
    7. In the Confirm File Delete dialog box, click Yes.
    8. Right-click the MyApp.sln file, and then click Open.
    9. In Solution Explorer, right-click MyApp, and then click Properties. The MyApp Property Pages dialog box appears.
    10. In the MyApp Property Pages dialog box, click Configuration Manager. The Configuration Manager dialog box appears.
    11. In the Configuration Manager dialog box, click Release in the Active Solution Configuration list, and then click Close.
    12. In the MyApp Property Pages dialog box, click OK.
    13. On the Build menu, click Build Solution.
You receive the error message that is mentioned in the "Symptoms" section.

REFERENCES

For more information about how to add references, click the following article number to view the article in the Microsoft Knowledge Base:

310674 How to add references to a Managed Visual C++ project


Modification Type:MinorLast Reviewed:1/5/2006
Keywords:kbtshoot kbDLL kberrmsg kbprb KB843407 kbAudDeveloper