Class forward decalarations cause error in generated C# binding.
Brief Description
Compiling the attached binding for library headers with forward declarations will result in the following errors:
Error CS0579 Duplicate 'StructLayout' attribute Error CS0102 The type 'ClassA' already contains a definition for '__Instance' Error CS0102 The type 'ClassA' already contains a definition for '__PointerAdjustment' Error CS0102 The type 'ClassA' already contains a definition for 'NativeToManagedMap' Error CS0102 The type 'ClassA' already contains a definition for '__OriginalVTables' Error CS0102 The type 'ClassA' already contains a definition for '__ownsNativeInstance'
OS: Windows
Used headers
ClassA.h:
#pragma once
class ClassA
{
public:
int Foo;
};
ClassB.h
#pragma once
class ClassA;
class ClassB
{
public:
int DoSomethingWithA(ClassA a);
};
Used settings
Target: CSharp
Stack trace or incompilable generated code
Project1.zip (VS2015 Solution, C++ library)
CppSharpTestCase.zip (BindingGenerator, Generated binding in BindingGenerator\bin\Debug\Project1.cs)
@MEikermann the problem is that the forward declaration of ClassA is considered complete and the class is therefore generated twice. Unfortunately, this is all the help I can offer at this point as our free time is extremely limited. So would you mind building C++# from source code and debugging it? I can help with any questions. The same goes for your other bug report. As an alternative, you could use the priority support at [email protected] .
Below is what I used as a quick hack to deal with the problem.
// Find all duplicated classes
List<Class> allClasses = (from TranslationUnit cTransUnit in ctx.TranslationUnits from Class cClass in cTransUnit.Classes select cClass).ToList();
foreach (Class tClass in allClasses) {
if (tClass.LineNumberStart == tClass.LineNumberEnd) {
// Almost certainly a forward (empty) declaration, so ignore
tClass.ExplicitlyIgnore();
}
@fundthmcalculus Do you have a test case that reproes this? I thought we had it fixed.