You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2017运行C#7.2 Span功能的.NET2.1 SDK获取及CS0305问题咨询

解决.NET Core 2.1 SDK获取与Span代码错误问题

Hey there, let's work through your issues step by step:

一、获取.NET Core 2.1 SDK并在VS2017中启用

First off, .NET Core 2.1 isn't included by default in all VS2017 installations. Here's how to get it set up:

  • Open Visual Studio 2017, go to the Tools menu, then select Get Tools and Features. This launches the VS Installer.
  • In the installer, locate the .NET Core cross-platform development workload. Check if .NET Core 2.1 SDK is listed under its components—if not, tick the corresponding option and click Modify to install it.
  • If you can't find it in the VS Installer, go to Microsoft's official .NET Core archive download area to grab the .NET Core 2.1 SDK installer directly. Run the installer, restart VS2017, and you'll be able to select .NET Core 2.1 as your project's target framework.
  • Also, ensure your VS2017 is updated to version 15.3 or later—this is the minimum version required to support .NET Core 2.1.

二、修复代码中的CS0305错误

The error you're hitting comes from a couple of small code issues:

  • You don't need using System.Memory;—both Span<T> and Memory<T> live in the System namespace in .NET Core 2.1, so just keep using System;.
  • The CS0305 error means you tried to use the generic Memory type without specifying its type parameter. While your posted code doesn't show this, double-check the omitted ... section of your code to make sure you aren't using Memory somewhere without adding a type (like Memory<byte> instead of just Memory).

Here's the corrected version of your code:

using System;

namespace sim
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = new byte[10];
            Span<byte> bytes = arr; // Implicit cast from T[] to Span<T>
            Span<byte> slicedBytes = bytes.Slice(start: 5, length: 2);
        }
    }
}

A critical reminder: Make sure your project is targeting .NET Core 2.1, not the traditional .NET Framework (like 2.0). Span is a .NET Core/.NET Standard feature and isn't available in older .NET Framework versions.

内容的提问来源于stack exchange,提问作者Mdev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:57:36