Skip to content

Commit 9342649

Browse files
authored
Use SYSLIB prefix for all LibraryImportGenerator diagnostics (dotnet#68613)
1 parent 763fd1a commit 9342649

File tree

20 files changed

+26
-279
lines changed

20 files changed

+26
-279
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,15 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
159159
| __`SYSLIB1050`__ | Invalid LibraryImportAttribute usage |
160160
| __`SYSLIB1051`__ | Specified type is not supported by source-generated P/Invokes |
161161
| __`SYSLIB1052`__ | Specified configuration is not supported by source-generated P/Invokes |
162-
| __`SYSLIB1053`__ | Current target framework is not supported by source-generated P/Invokes |
163-
| __`SYSLIB1054`__ | Specified LibraryImportAttribute arguments cannot be forwarded to DllImportAttribute |
164-
| __`SYSLIB1055`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
165-
| __`SYSLIB1056`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
166-
| __`SYSLIB1057`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
167-
| __`SYSLIB1058`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
168-
| __`SYSLIB1059`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
169-
| __`SYSLIB1060`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
170-
| __`SYSLIB1061`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
171-
| __`SYSLIB1062`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
172-
| __`SYSLIB1063`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
173-
| __`SYSLIB1064`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
174-
| __`SYSLIB1065`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
175-
| __`SYSLIB1066`__ | *_`SYSLIB1055`-`SYSLIB1066` reserved for Microsoft.Interop.LibraryImportGenerator._* |
162+
| __`SYSLIB1053`__ | Specified LibraryImportAttribute arguments cannot be forwarded to DllImportAttribute |
163+
| __`SYSLIB1054`__ | Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time |
164+
| __`SYSLIB1055`__ | Invalid CustomTypeMarshallerAttribute usage |
165+
| __`SYSLIB1056`__ | Specified native type is invalid |
166+
| __`SYSLIB1057`__ | Marshaller type does not have the required shape |
167+
| __`SYSLIB1058`__ | Marshaller type defines a well-known method without specifying support for the corresponding feature |
168+
| __`SYSLIB1059`__ | Marshaller type does not support allocating constructor |
169+
| __`SYSLIB1060`__ | BufferSize should be set on CustomTypeMarshallerAttribute |
170+
| __`SYSLIB1061`__ | Marshaller type has incompatible method signatures |
171+
| __`SYSLIB1062`__ | *_`SYSLIB1062`-`SYSLIB1064` reserved for Microsoft.Interop.LibraryImportGenerator._* |
172+
| __`SYSLIB1063`__ | *_`SYSLIB1062`-`SYSLIB1064` reserved for Microsoft.Interop.LibraryImportGenerator._* |
173+
| __`SYSLIB1064`__ | *_`SYSLIB1062`-`SYSLIB1064` reserved for Microsoft.Interop.LibraryImportGenerator._* |

src/libraries/Common/tests/TestUtilities/System/WindowsIdentityFixture.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,8 @@ private void CreateUser()
113113
[return: MarshalAs(UnmanagedType.Bool)]
114114
private static partial bool LogonUser(string userName, string domain, string password, int logonType, int logonProvider, out SafeAccessTokenHandle safeAccessTokenHandle);
115115

116-
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
117-
// TODO: [LibraryImportGenerator] Switch to use LibraryImport once we add support for non-blittable struct marshalling.
118-
[DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
119-
internal static extern uint NetUserAdd([MarshalAs(UnmanagedType.LPWStr)]string servername, uint level, ref USER_INFO_1 buf, out uint parm_err);
120-
#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
116+
[LibraryImport("netapi32.dll", SetLastError = true)]
117+
internal static partial uint NetUserAdd([MarshalAs(UnmanagedType.LPWStr)]string servername, uint level, ref USER_INFO_1 buf, out uint parm_err);
121118

122119
[LibraryImport("netapi32.dll")]
123120
internal static partial uint NetUserDel([MarshalAs(UnmanagedType.LPWStr)]string servername, [MarshalAs(UnmanagedType.LPWStr)]string username);

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/AnalyzerDiagnostics.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ internal static class AnalyzerDiagnostics
1313
/// </summary>
1414
public static class Ids
1515
{
16-
public const string Prefix = "DLLIMPORTGENANALYZER";
16+
public const string Prefix = "SYSLIB";
1717

1818
// Migration from DllImport to LibraryImport
19-
public const string ConvertToLibraryImport = Prefix + "001";
19+
public const string ConvertToLibraryImport = Prefix + "1054";
2020

2121
// CustomTypeMarshaller
22-
public const string InvalidCustomTypeMarshallerAttributeUsage = Prefix + "002";
23-
public const string InvalidNativeType = Prefix + "003";
24-
public const string CustomMarshallerTypeMustHaveRequiredShape = Prefix + "004";
25-
public const string ProvidedMethodsNotSpecifiedInFeatures = Prefix + "005";
26-
public const string MissingAllocatingMarshallingFallback = Prefix + "006";
27-
public const string CallerAllocConstructorMustHaveBufferSize = Prefix + "007";
28-
public const string InvalidSignaturesInMarshallerShape = Prefix + "008";
22+
public const string InvalidCustomTypeMarshallerAttributeUsage = Prefix + "1055";
23+
public const string InvalidNativeType = Prefix + "1056";
24+
public const string CustomMarshallerTypeMustHaveRequiredShape = Prefix + "1057";
25+
public const string ProvidedMethodsNotSpecifiedInFeatures = Prefix + "1058";
26+
public const string MissingAllocatingMarshallingFallback = Prefix + "1059";
27+
public const string CallerAllocConstructorMustHaveBufferSize = Prefix + "1060";
28+
public const string InvalidSignaturesInMarshallerShape = Prefix + "1061";
2929
}
3030

3131
internal static LocalizableResourceString GetResourceString(string resourceName)

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public class Ids
2222
public const string InvalidLibraryImportAttributeUsage = Prefix + "1050";
2323
public const string TypeNotSupported = Prefix + "1051";
2424
public const string ConfigurationNotSupported = Prefix + "1052";
25-
public const string TargetFrameworkNotSupported = Prefix + "1053";
26-
public const string CannotForwardToDllImport = Prefix + "1054";
25+
public const string CannotForwardToDllImport = Prefix + "1053";
2726
}
2827

2928
private const string Category = "LibraryImportGenerator";
@@ -148,16 +147,6 @@ public class Ids
148147
isEnabledByDefault: true,
149148
description: GetResourceString(nameof(SR.ConfigurationNotSupportedDescription)));
150149

151-
public static readonly DiagnosticDescriptor TargetFrameworkNotSupported =
152-
new DiagnosticDescriptor(
153-
Ids.TargetFrameworkNotSupported,
154-
GetResourceString(nameof(SR.TargetFrameworkNotSupportedTitle)),
155-
GetResourceString(nameof(SR.TargetFrameworkNotSupportedMessage)),
156-
Category,
157-
DiagnosticSeverity.Error,
158-
isEnabledByDefault: true,
159-
description: GetResourceString(nameof(SR.TargetFrameworkNotSupportedDescription)));
160-
161150
public static readonly DiagnosticDescriptor CannotForwardToDllImport =
162151
new DiagnosticDescriptor(
163152
Ids.CannotForwardToDllImport,
@@ -327,19 +316,6 @@ public void ReportInvalidMarshallingAttributeInfo(
327316
new LocalizableResourceString(reasonResourceName, SR.ResourceManager, typeof(FxResources.Microsoft.Interop.LibraryImportGenerator.SR), reasonArgs)));
328317
}
329318

330-
/// <summary>
331-
/// Report diagnostic for targeting a framework that is not supported
332-
/// </summary>
333-
/// <param name="minimumSupportedVersion">Minimum supported version of .NET</param>
334-
public void ReportTargetFrameworkNotSupported(Version minimumSupportedVersion)
335-
{
336-
_diagnostics.Add(
337-
Diagnostic.Create(
338-
TargetFrameworkNotSupported,
339-
Location.None,
340-
minimumSupportedVersion.ToString(2)));
341-
}
342-
343319
/// <summary>
344320
/// Report diagnostic for configuration that cannot be forwarded to <see cref="DllImportAttribute" />
345321
/// </summary>

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
9292
return (compilation, fmk, targetFrameworkVersion);
9393
});
9494

95-
context.RegisterSourceOutput(
96-
compilationAndTargetFramework
97-
.Combine(methodsToGenerate.Collect()),
98-
static (context, data) =>
99-
{
100-
if (data.Left.targetFramework is TargetFramework.Unknown && data.Right.Any())
101-
{
102-
// We don't block source generation when the TFM is unknown.
103-
// This allows a user to copy generated source and use it as a starting point
104-
// for manual marshalling if desired.
105-
context.ReportDiagnostic(
106-
Diagnostic.Create(
107-
GeneratorDiagnostics.TargetFrameworkNotSupported,
108-
Location.None,
109-
data.Left.targetFrameworkVersion));
110-
}
111-
});
112-
11395
IncrementalValueProvider<LibraryImportGeneratorOptions> stubOptions = context.AnalyzerConfigOptionsProvider
11496
.Select(static (options, ct) => new LibraryImportGeneratorOptions(options.GlobalOptions));
11597

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/Strings.resx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,6 @@
284284
<data name="SafeHandleByRefMustBeConcrete" xml:space="preserve">
285285
<value>An abstract type derived from 'SafeHandle' cannot be marshalled by reference. The provided type must be concrete.</value>
286286
</data>
287-
<data name="TargetFrameworkNotSupportedDescription" xml:space="preserve">
288-
<value>P/Invoke source generation is not supported on unknown target framework v{0}. The generated source will not be compatible with other frameworks.</value>
289-
<comment>{0} is a version number</comment>
290-
</data>
291-
<data name="TargetFrameworkNotSupportedMessage" xml:space="preserve">
292-
<value>'LibraryImportAttribute' cannot be used for source-generated P/Invokes on an unknown target framework v{0}.</value>
293-
<comment>{0} is a version number</comment>
294-
</data>
295-
<data name="TargetFrameworkNotSupportedTitle" xml:space="preserve">
296-
<value>Current target framework is not supported by source-generated P/Invokes</value>
297-
</data>
298287
<data name="TypeNotSupportedDescription" xml:space="preserve">
299288
<value>For types that are not supported by source-generated P/Invokes, the resulting P/Invoke will rely on the underlying runtime to marshal the specified type.</value>
300289
</data>

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.cs.xlf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,6 @@
462462
<target state="translated">Abstraktní typ odvozený ze SafeHandle nelze zařadit pomocí odkazu. Poskytnutý typ musí být konkrétní.</target>
463463
<note />
464464
</trans-unit>
465-
<trans-unit id="TargetFrameworkNotSupportedDescription">
466-
<source>P/Invoke source generation is not supported on unknown target framework v{0}. The generated source will not be compatible with other frameworks.</source>
467-
<target state="translated">Generování zdroje voláním P/Invoke se u neznámé cílové architektura v{0} nepodporuje. Generovaný zdroj nebude kompatibilní s ostatními architekturami.</target>
468-
<note>{0} is a version number</note>
469-
</trans-unit>
470-
<trans-unit id="TargetFrameworkNotSupportedMessage">
471-
<source>'LibraryImportAttribute' cannot be used for source-generated P/Invokes on an unknown target framework v{0}.</source>
472-
<target state="translated">LibraryImportAttribute nelze použít pro zdrojem generovaná volání P/Invokes v neznámé cílové architektuře v{0}.</target>
473-
<note>{0} is a version number</note>
474-
</trans-unit>
475-
<trans-unit id="TargetFrameworkNotSupportedTitle">
476-
<source>Current target framework is not supported by source-generated P/Invokes</source>
477-
<target state="translated">Současná cílová architektura není podporována zdrojem generovanými voláními P/Invokes</target>
478-
<note />
479-
</trans-unit>
480465
<trans-unit id="ToNativeValueMethodProvidedShouldSpecifyTwoStageMarshallingFeatureDescription">
481466
<source>A marshaller type that provides a 'ToNativeValue' method should specify that it supports the 'TwoStageMarshalling' feature.</source>
482467
<target state="translated">Typ zařazování, které poskytuje metodu ToNativeValue, by měl určovat, že podporuje funkci TwoStageMarshalling.</target>

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.de.xlf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,6 @@
462462
<target state="translated">Ein abstrakter Typ, der von \"SafeHandle\" abgeleitet wird, kann nicht als Verweis gemarshallt werden. Der angegebene Typ muss ein konkretes Element sein.</target>
463463
<note />
464464
</trans-unit>
465-
<trans-unit id="TargetFrameworkNotSupportedDescription">
466-
<source>P/Invoke source generation is not supported on unknown target framework v{0}. The generated source will not be compatible with other frameworks.</source>
467-
<target state="translated">Die P/Invoke-Quellgenerierung wird auf unbekanntem Zielframework v{0} nicht unterstützt. Die generierte Quelle ist nicht mit anderen Frameworks kompatibel.</target>
468-
<note>{0} is a version number</note>
469-
</trans-unit>
470-
<trans-unit id="TargetFrameworkNotSupportedMessage">
471-
<source>'LibraryImportAttribute' cannot be used for source-generated P/Invokes on an unknown target framework v{0}.</source>
472-
<target state="translated">\"LibraryImportAttribute\" kann nicht für von der Quelle generierte P/Invokes in einem unbekannten Zielframework v{0} verwendet werden.</target>
473-
<note>{0} is a version number</note>
474-
</trans-unit>
475-
<trans-unit id="TargetFrameworkNotSupportedTitle">
476-
<source>Current target framework is not supported by source-generated P/Invokes</source>
477-
<target state="translated">Das aktuelle Zielframework wird von quellgenerierten P/Invokes nicht unterstützt.</target>
478-
<note />
479-
</trans-unit>
480465
<trans-unit id="ToNativeValueMethodProvidedShouldSpecifyTwoStageMarshallingFeatureDescription">
481466
<source>A marshaller type that provides a 'ToNativeValue' method should specify that it supports the 'TwoStageMarshalling' feature.</source>
482467
<target state="translated">Ein Marshallertyp, der eine ToNativeValue-Methode bereitstellt, sollte angeben, dass er das Feature \"TwoStageMarshalling\" unterstützt.</target>

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.es.xlf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,6 @@
462462
<target state="translated">Un tipo abstracto derivado de “SafeHandle” no se puede serializar por referencia. El tipo proporcionado debe ser concreto.</target>
463463
<note />
464464
</trans-unit>
465-
<trans-unit id="TargetFrameworkNotSupportedDescription">
466-
<source>P/Invoke source generation is not supported on unknown target framework v{0}. The generated source will not be compatible with other frameworks.</source>
467-
<target state="translated">No se admite la generación de código fuente en la plataforma de destino v{0} desconocida. El código fuente generado no será compatible con otras plataformas.</target>
468-
<note>{0} is a version number</note>
469-
</trans-unit>
470-
<trans-unit id="TargetFrameworkNotSupportedMessage">
471-
<source>'LibraryImportAttribute' cannot be used for source-generated P/Invokes on an unknown target framework v{0}.</source>
472-
<target state="translated">“LibraryImportAttribute” no se puede usar para P/Invokes de un generador de código fuente en una plataforma de destino v{0} desconocida.</target>
473-
<note>{0} is a version number</note>
474-
</trans-unit>
475-
<trans-unit id="TargetFrameworkNotSupportedTitle">
476-
<source>Current target framework is not supported by source-generated P/Invokes</source>
477-
<target state="translated">La plataforma de destino actual no está admitida por P/Invokes de un generador de código fuente</target>
478-
<note />
479-
</trans-unit>
480465
<trans-unit id="ToNativeValueMethodProvidedShouldSpecifyTwoStageMarshallingFeatureDescription">
481466
<source>A marshaller type that provides a 'ToNativeValue' method should specify that it supports the 'TwoStageMarshalling' feature.</source>
482467
<target state="translated">Un tipo de serializador que proporciona un método “ToNativeValue” debe especificar que admite la característica “TwoStageMarshalling”.</target>

src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Resources/xlf/Strings.fr.xlf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -462,21 +462,6 @@
462462
<target state="translated">Un type abstrait dérivé de « SafeHandle » ne peut pas être marshalé par référence. Le type fourni doit être concret.</target>
463463
<note />
464464
</trans-unit>
465-
<trans-unit id="TargetFrameworkNotSupportedDescription">
466-
<source>P/Invoke source generation is not supported on unknown target framework v{0}. The generated source will not be compatible with other frameworks.</source>
467-
<target state="translated">La génération de source P/Invoke n’est pas prise en charge sur le framework cible inconnu v{0}. La source générée ne sera pas compatible avec d’autres frameworks.</target>
468-
<note>{0} is a version number</note>
469-
</trans-unit>
470-
<trans-unit id="TargetFrameworkNotSupportedMessage">
471-
<source>'LibraryImportAttribute' cannot be used for source-generated P/Invokes on an unknown target framework v{0}.</source>
472-
<target state="translated">« LibraryImportAttribute » ne peut pas être utilisé pour les P/Invok générés par la source sur un framework cible inconnu v{0}.</target>
473-
<note>{0} is a version number</note>
474-
</trans-unit>
475-
<trans-unit id="TargetFrameworkNotSupportedTitle">
476-
<source>Current target framework is not supported by source-generated P/Invokes</source>
477-
<target state="translated">Le framework cible actuel n’est pas pris en charge par les P/Invokes générés par la source</target>
478-
<note />
479-
</trans-unit>
480465
<trans-unit id="ToNativeValueMethodProvidedShouldSpecifyTwoStageMarshallingFeatureDescription">
481466
<source>A marshaller type that provides a 'ToNativeValue' method should specify that it supports the 'TwoStageMarshalling' feature.</source>
482467
<target state="translated">Un type marshaleur qui fournit une méthode « ToNativeValue » doit spécifier qu’il prend en charge la fonctionnalité « TwoStageMarsoboing ».</target>

0 commit comments

Comments
 (0)