+2  A: 

In plain C++, templated class methods are only instantiated if they are actually used within the linkage scope. I suspect that the C++/CLI implementation may be doing the equivalent -- not generating code for Test() if it's not being used in the C++ assembly.

Steve Gilham
That's why I love stackoverflow :-) This is *exactly* what's happening. So obvious when you think about it. I can work around it now. Thanks for your swift answer.
Phil Nash
A: 

The answer to your question is actually very simple. When you compile your mixed assembly - C++/CLI there are some rules that the compiler follows to exporting native functions outside the assembly and outputting meta data for them.

One of them is that native methods don't get exposed out of the assembly unless explicitly specified. To explicitly specify a native method to be exposed via meta data, you use the #pragma make_public( Your Class Here ).

Other one is that template functions cannot be exposed out of the assembly. So in your case you can't expose the template class.

BUT in your case I am almost positive that you don't need template class, but a generic one which is absolutely OK to be exported.

Why do you need templates? Do you understand the difference between template<> and generic<>? One is compile time unit, the other is runtime.

Try using

generic<class T>
public ref class B
{
public:
  void Test(){}
};


public ref class A : public B<System::Int32>
{
};
Ivan Zlatanov
There are no native methods in his code. Both classes are `ref`, so all code is managed.
Pavel Minaev
Thanks for your comments, Ivan. Obviously the example is not representative of what I am trying to do with the templates. I am using a template here specifically to get compile time results. I can't achieve the same thing with generics. It seems the accepted answer was all I needed to get this working.
Phil Nash