首页 > 解决方案 > 使用跨度在 C++/CLR 项目中

问题描述

我在 Visual Studio 2019 中有一个 C# 项目和一个 C++/CLR 项目。两者都针对 .NET 4.8。我正在尝试使用Span<byte>从 C# 项目传递到 C++/CLR 项目的一个。

由于这两个程序集都以 .NET 4.8 为目标,因此我使用的是System.Memory (4.5.2)NuGet 包及其依赖项 ( System.Buffers, System.Numerics.Vectors, System.Runtime.CompilerServices.Unsafe)。我在 C# 项目和 C++/CLR 项目中引用了相同的程序集。

在 C++/CLR 项目中,我试图像这样访问跨度:
System::Span<unsigned char> span = pixelBuffer->Span;

我在该行收到此错误:
Foo.cpp(1544): error C2079: 'System::Span<unsigned char>::Enumerator::_span' uses undefined class 'System::Span<unsigned char>'

这对我来说没有意义,因为我可以System.Span<T>在 System.Memory.dll 中看到 C++/CLR 项目正在引用。

我确实发现了一个未解决的问题,但他们只收到警告,而不是错误: https ://developercommunity.visualstudio.com/content/problem/1017965/systemreadonlyspan-deprecated-warning-using-ccli.html

标签: .netc++-clivisual-studio-2019

解决方案


推荐阅读