title: Exporting C++/CLI native class (C4679)
body: <p>I have a public ref class in a C++/CLI assembly (MyAssembly) containing a public static method that accepts native parameters.  </p>
  
  <pre><code>#pragma make_public(nativeTypeA)
  
  namespace namespaceA
  { 
      public ref class MyClass : namespaceB::MyClass
      {
      public:
          static managedTypeA ^ MethodA(nativeTypeA param);
          static managedTypeB ^ MethodB(nativeTypeB param);
      }
  }
  </code></pre>
  
  <p>I would like to expose this method to another C++/CLI assembly.  The managed assembly compiles fine but the assembly that references it (CallingAssembly) generates the following warning for MethodB:</p>
  
  <pre><code>warning C4679: 'namespaceA::MyClass::MethodB' : could not import member
  This diagnostic occurred while importing type 'namespaceA::MyClass ' from assembly 'MyAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. 
  </code></pre>
  
  <p>I cannot use make_public on nativeTypeB because it is a typedef of a templated class, however, I am using make_public for non-templated native types (e.g. nativeTypeA) and it works (i.e. no C4679 when compiling CallingAssembly).  Instead of using make_public, I have declared the native class public and used __declspec(dllexport) in the native header via preprocessor directives as suggested in <a href="https://stackoverflow.com/questions/4121422/type-visibilty-for-a-header-share-a-header-file-shared-between-native-and-manage">this</a> post.  It was also necessary to conditionally exclude the "public" modifier (via CLR_ACCESS_MODIFIER) as the class is also included in other native projects:</p>
  
  <pre><code>#ifdef MANAGED
  #define CLR_ACCESS_MODIFIER public 
  #ifdef MYASSEMBLY_DEF
      #define MYASSEMBLY_LINKAGE __declspec(dllexport)
  #else
      #define MYASSEMBLY_LINKAGE __declspec(dllimport)
  #endif
  #else
  #define MYASSEMBLY_LINKAGE
  #define CLR_ACCESS_MODIFIER
  #endif
  
  template&lt;&gt;
  CLR_ACCESS_MODIFIER class MYASSEMBLY_LINKAGE nativeTypeB&lt;TT&gt; : public nativeTypeB_base&lt;TT&gt; {
  ...
  }
  </code></pre>
  
  <p>I have also done this for the base class of nativeTypeB (necessary in order to compile), and its typedef:</p>
  
  <pre><code>typedef public nativeTypeB&lt;TT&gt; MYASSEMBLY_LINKAGE nativeTypeB;
  </code></pre>
  
  <p>I'm not sure whether the line above is necessary, but C4679 still occurs either way.</p>
  
  <p>I've done the usual checks: the MANAGED preprocessor directive is defined both projects; MYASSEMBLY_DEF is defined in MyAssembly; and I have added a reference to MyAssembly in CallingAssembly as well as MyAssembly.lib to its link line.  The project build order is correct and there are no missing dependencies but I am still getting C4679.</p>
  
  <p>I could change the interface to accept non-templated types but I don't really want to do this as it will lead to code bloat and is less elegant.  <a href="https://stackoverflow.com/questions/9198363/adding-pragma-make-publictype-not-removing-c3767-error/9213016#9213016">This</a> post mentions that the normal use of "public" in my native class should work.</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks in advance!</p>