skip to Main Content

Steps to reproduce:

  1. Install a version of Visual Studio (I used VS Community 2022). Install OpenCASCADE 7.6.0.
  2. Create a C++ .NET CLR project using Visual Studio 2022 targeting .net6.0.
  3. Change settings to include OpenCASCADE header and library files.
  4. Edit the main header by replacing the code within it with below:
#pragma once

//for OCC graphic
#include <OpenGl_GraphicDriver.hxx>

//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>

namespace ClrClsLibDotNetCoreMwe {
    public ref class Class1
    {
        // TODO: Add your methods for this class here.
    };
}
  1. Attempt to build.

Issue: The build fails with the following complain:

1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): error C2872: 'HashCode': ambiguous symbol
1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): message : could be 'HashCode'
1>C:OpenCASCADE-7.6.0-vc14-64opencascade-7.6.0incNCollection_DefaultHasher.hxx(34,1): message : or       'System::HashCode'

What fixes the problem:

  1. Either Targeting .NET Framework instead of .NET Core (/clr instead of /clr:netcore).
  2. Or removing one of the headers.

Please see if there is a way where I can keep both the headers and target .NET Core?

I have looked around for a possible solution before posting this question here. A promising solution was to disable implicit usings. However, that didn’t pan out.

2

Answers


  1. Chosen as BEST ANSWER

    Actually, qualifying one of the namespaces with ::HashCode in the header file fixed the problem for me. I was having significant difficulties in preventing the auto use of the System namespace.


  2. I had the same problem.
    In my case, the "using namespace System;" included in the header file. The text caused the problem.

    Thanks!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search