OpenCASCADE 7.6.0 not compiling with a .NET 6.0 class library with Visual Studio 2022 (Windows 10)

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

//wrapper of pure C++ classes to ref classes

namespace ClrClsLibDotNetCoreMwe {
public ref class Class1
// TODO: Add your methods for this class here.
5. Attempt to build.
Issue: The build fails with the following complain:
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): error C2872: 'HashCode': ambiguous symbol
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_DefaultHasher.hxx(34,1): message : could be 'HashCode'
1>C:\OpenCASCADE-7.6.0-vc14-64\opencascade-7.6.0\inc\NCollection_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.

Fantasy Memories's picture

I had the same problem. I think this problem arises due to the inclusion of the System::HashCode namespace in .NET Core, which conflicts with the namespace in the OCC source code.
My solution was to rewrite the source code directly:
Click on each error C2872: 'HashCode': ambiguous symbol and rewrite `return HashCode(...)' in the source code to return ::HashCode(...). ` to `return ::HashCode(...) ` to qualify the HashCode namespace.

Dmitrii Pasukhin's picture

Hello, thank you for the repost. We will anylize the issue on latest OCCT version. If you know that problem still actual(on 7.8), please share with us. That will increase the priority of that issue.

Best regards, Dmitrii,