title: How to Use C++/CLI Within C# Application
body: <p>I am trying to call my C++ library from my C# application (via C++/CLI). I followed the example from <a href="https://stackoverflow.com/questions/2211867/how-do-i-call-native-c-from-c">this question</a> (for my specific application). The setup of my application is:</p>
  
  <ul>
  <li>Project1: C++ Project (I compile this to a DLL)</li>
  <li>Project2: C++ Project (my CLR wrapper; just the header file per the example above; references Project1)</li>
  <li>Project3: C# Project (references Project2)</li>
  </ul>
  
  <p>Unfortunately, when I actually go to access the CLR wrapper object in my C# application, I receive the following error:</p>
  
  <blockquote>
    <p>The type or namespace name 'YourClass'
    could not be found (are you missing a
    using directive or an assembly
    reference?)</p>
  </blockquote>
  
  <p>Do I have the project setup incorrectly, or is there something else I should be looking into? (Unfortunately, I cannot post the code for proprietary reasons, but it is a very simple bit of code and easily follows the above example.)</p>
  
  <p><strong>Update:</strong></p>
  
  <p>So I did exactly what Chris said to do (see answer below), but I am still receiving a message from my C# application that "The type or namespace name 'MyProgram' could not be found (are you missing a using directive or an assembly reference?). Here is a (mock-up) of my code.</p>
  
  <ul>
  <li>Project1 - This is my C++ application. It compiles/works. I have used it elsewhere. (I get a DLL out of this build.)</li>
  <li>Project2 - Here is my code for my wrapper.</li>
  </ul>
  
  <p><em>MyWrapper.h</em></p>
  
  <pre><code>#pragma once
  
  #include "myorigapp.h"
  
  using namespace System;
  
  namespace MyProgram
  {
      public ref class MyWrapper
      {
      private:
          myorigapp* NativePtr;
  
      public:
          MyWrapper() 
          {
              NativePtr = new myorigapp();
          }
  
          ~MyWrapper() 
          { 
              delete NativePtr;
              NativePtr = NULL;
          }
  
          void dostuff()
          { 
              NativePtr-&gt;dostuff(); 
          }
      }
  }
  </code></pre>
  
  <ul>
  <li>Project3 - This is my C# application.</li>
  </ul>
  
  <p><em>Program.cs</em></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  using MyProgram;
  
  namespace Testing
  {
      class Program
      {
          static void Main(string[] args)
          {
              MyWrapper p = new MyWrapper();
              p.dostuff();
          }
      }
  }
  </code></pre>
  
  <p>Project3 references Project2 which references Project1. Everything builds without errors (except the error I described above in the C# code on the <code>using MyProgram</code> line).</p>