I have a DLL A that provides a public class Foo, and a DLL B that provides a class Bar that uses Foo. The SWIG C# code relevant is:

// assembly A (from SWIG generated .cs file)
namespace MyNS {
public class Foo {
  internal Foo(IntPtr cPtr, bool cMemoryOwn) {...}
  internal static HandleRef getCPtr(Foo obj) {...}
  public Foo() {...}
}
}

// assembly B
namespace MyNS {
public class Bar {
  public Foo GetFoo() {
    IntPtr cPtr = test_kernelPINVOKE.Bar_GetFoo(swigCPtr);
    Foo ret = (cPtr == IntPtr.Zero) ? null : new Foo(cPtr, false);
    ...
  }
}
}

This is the same situation as described in http://old.nabble.com/C-:-error-CS0117:-'FooNS::FooArray'-does-not-contain-a-definition-for-'getCPtr'-td21574469.html. However, I don't agree with the two solutions proposed. Changing the typemap is surely a gross hack. And making assembly B a friend of A requires that A know about B, which doesn't make sense either. 

Surely I'm missing something obvious or there is a bug in SWIG generated C# code. Like perhaps SWIG should not make GetFoo in the above example call new Foo(cPtr, false) since it is internal to another assembly. Moreover, why is SWIG trying to create a Foo instance? If GetFoo doesn't return one, it should not be creating one. 

Any help greatly appreciated!