Skip to content

c++/cli compile error 3611 if System::IntPtr is used #94723

Closed

Description

@panxn

Description

I'm using the latest .NET8 and VS 17.8

It's a compile error for c++/cli:

1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): error C3611: 'System::Numerics::INumberBase::System::IUtf8SpanFormattable.TryFormat': a sealed function cannot have a pure-specifier
1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): message : This diagnostic occurred while importing type 'System::Numerics::INumberBase' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): message : This diagnostic occurred while importing type 'System::Numerics::INumber' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): message : This diagnostic occurred while importing type 'System::Numerics::IBinaryNumber' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): message : This diagnostic occurred while importing type 'System::Numerics::IBinaryInteger' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1>C:\Users\admin\source\repos\Project1\Project1\Source.cpp(5,1): message : This diagnostic occurred while importing type 'System::IntPtr' from assembly 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
1

It happens as long as System::IntPtr is used. For example, add a function in c++/cli project:

void test(System::IntPtr) {}

These code can compile with .NET8 preview versions (preview, rc1, rc2), but fails with today's .NET8 official version 8.0.100

This problem is pretty urgent for us because our product is very close to the release date (we were waiting for .NET8 official release). Could you please take a look right now? Is there any workaround that we can use to make build pass?

I have encountered this problem in one .NET8 daily build months ago (#88840 (comment)), then it was gone. I don't understand why it comes back in today's official version.

Just FYI, I also reported a similar bug dotnet/winforms#9644, it's not urgent.

Reproduction Steps

create c++/cli project in VS.

add function:

void test(System::IntPtr) {}

build fails

Expected behavior

build should pass

Actual behavior

build fails

Regression?

Yes, it's good in .NET8 preview versions.

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Nov 14, 2023
  2. ghost added
    untriaged
    on Nov 14, 2023
  3. removed
    needs-area-label
    on Nov 14, 2023
  4. tannergooding commented on Nov 14, 2023

    @tannergooding
    Member

    Could you clarify what version of the C++/CLI build tools you have installed?

    I am not able to repro this using the following in VS 17.9 Preview 1:

    1. Open VS
    2. Create New project
    3. CLR Class Library (.NET)
    4. Add void test(System::IntPtr) {} to ClassLibrary1::Class1 in ClassLibrary1.h

    This was also validated to be resolved in the last preview of VS 17.8. I am currently installing VS 17.8 RTM to see if something broke between the last preview and actual release.

  5. panxn commented on Nov 14, 2023

    @panxn
    Author

    @tannergooding Thanks for your reply! I just found it can build with VC toolset 14.38.
    I have 14.36, 14.37 and 14.38 installed. 14.36 is the default one. The code can only compile with 14.38.

    But the code can compile with 14.36 in previous net8 preview versions. What is changed? Could I go back to the old compiler behavior? I ask this question because it's almost impossible for us to use 17.8 immediately because time is very limited.

  6. tannergooding commented on Nov 14, 2023

    @tannergooding
    Member

    Visual Studio 2022 17.8 is the minimum version required to work with .NET 8

    C++/CLI had to update to support a particular feature of static virtuals in interfaces that they did not previously support as we needed to take advantage of it in .NET 8.

    This lack of support in C++/CLI was found back around .NET 8 Preview 4-5, at which point we temporarily removed the neded API. This was added back for RTM once the C++/CLI fix landed (which was only in the last preview of VS 2022 17.8).

  7. panxn commented on Nov 14, 2023

    @panxn
    Author

    Is there any workaround that I can use? Is it possible for me to "temporarily removed the needed API" like you did? We have no enough time.

  8. tannergooding commented on Nov 14, 2023

    @tannergooding
    Member

    There is not.

    If you are targeting .NET 8 and using C++/CLI, then you need C++/CLI 14.38. This necessitates using VS 2022 17.8.

  9. panxn commented on Nov 14, 2023

    @panxn
    Author

    I see. Thanks for your help!

  10. ghost removed
    untriaged
    on Nov 20, 2023
  11. locked and limited conversation to collaborators on Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions