dotnet/roslyn

Improve CS8893 when CallConvX is not defined in corelib

Offen

#49.638 geöffnet am 26.11.2020

 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (4.257 Forks)batch import
Area-CompilersConcept-Diagnostic Clarityhelp wanted

Repository-Metriken

Stars
 (20.414 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)

Beschreibung

Version Used: .NET CORE SDK 5.0.100

Steps to Reproduce:

  1. Create a new library that targets netcoreapp3.1.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
</Project>
  1. Attempt to compile the following code:
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace MyNamespace
{
	public class Class1
	{
		[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
		public static void TestImpl() { }
	}
}

#if !NET5_0
namespace System.Runtime.InteropServices
{
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	public sealed class UnmanagedCallersOnlyAttribute : Attribute
	{
		public UnmanagedCallersOnlyAttribute() { }
		public Type[] CallConvs;
		public string EntryPoint;
	}
}
#endif

Expected Behavior:

Build succeeded. 0 Warning(s) 0 Error(s)

Actual Behavior:

error CS8893: 'CallConvStdcall' is not a valid calling convention type for 'UnmanagedCallersOnly'.

Notes: This code compiles fine for net45, netstandard2.0, netstandard2.1.

Contributor Guide