diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md
index 3c9a9afb9c4199..4b46d49f5813f0 100644
--- a/docs/project/list-of-diagnostics.md
+++ b/docs/project/list-of-diagnostics.md
@@ -208,7 +208,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1089`__ | _`SYSLIB1070`-`SYSLIB1089` reserved for System.Runtime.InteropServices.JavaScript.JSImportGenerator._ |
| __`SYSLIB1090`__ | Invalid 'GeneratedComInterfaceAttribute' usage |
| __`SYSLIB1091`__ | Method is declared in different partial declaration than the 'GeneratedComInterface' attribute. |
-| __`SYSLIB1092`__ | 'GenerateComInterfaceAttribute' usage not recommended. See aka.ms/GeneratedComInterfaceUsage for recommended usage. |
+| __`SYSLIB1092`__ | Usage of '[LibraryImport|GeneratedComInterface]' does not follow recommendation. See aka.ms/[LibraryImport|GeneratedComInterface]Usage for best practices. |
| __`SYSLIB1093`__ | Analysis for COM interface generation has failed |
| __`SYSLIB1094`__ | The base COM interface failed to generate source. Code will not be generated for this interface. |
| __`SYSLIB1095`__ | Invalid 'GeneratedComClassAttribute' usage |
diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs
index c676f27cb9f401..fab2d39182c8b7 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/DiagnosticDescriptorProvider.cs
@@ -26,6 +26,7 @@ internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvid
GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails,
GeneratorDiagnostic.UnnecessaryData { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.UnnecessaryParameterMarshallingInfo,
GeneratorDiagnostic.UnnecessaryData { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.UnnecessaryReturnMarshallingInfo,
+ GeneratorDiagnostic.NotRecommended => GeneratorDiagnostics.GeneratedComInterfaceUsageDoesNotFollowBestPractices,
{ IsFatal: false } => null,
{ TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported,
{ TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported,
diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
index b213e3a9704f29..1e1849592f7ba4 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs
@@ -485,6 +485,17 @@ public class Ids
DiagnosticSeverity.Info,
isEnabledByDefault: true);
+ ///
+ public static readonly DiagnosticDescriptor GeneratedComInterfaceUsageDoesNotFollowBestPractices =
+ new DiagnosticDescriptor(
+ Ids.NotRecommendedGeneratedComInterfaceUsage,
+ GetResourceString(nameof(SR.ComInterfaceUsageDoesNotFollowBestPracticesTitle)),
+ GetResourceString(nameof(SR.ComInterfaceUsageDoesNotFollowBestPracticesMessageWithDetails)),
+ Category,
+ DiagnosticSeverity.Info,
+ isEnabledByDefault: true,
+ helpLinkUri: "aka.ms/GeneratedComInterfaceUsage");
+
///
/// Report diagnostic for invalid configuration for string marshalling.
///
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx
index ebf0170e328752..2da298e8a7b0df 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx
@@ -875,7 +875,13 @@
[In] and [Out] attributes
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.The return value in the managed definition will be converted to an 'out' parameter when calling the unmanaged COM method. If the return value is intended to be the HRESULT code returned by the unmanaged COM method, use '[PreserveSig]' on the method.
@@ -889,4 +895,19 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
-
\ No newline at end of file
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.cs.xlf
index aba6380486a3b7..48a9bc03b73a63 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.cs.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.cs.xlf
@@ -147,6 +147,16 @@
Hostování .NET COM s EnableComHosting nepodporuje rozhraní s generatedComInterfaceAttribute
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Vrácená hodnota ve spravované definici se při volání nespravované metody COM převede na parametr out. Pokud má být návratovou hodnotou kód HRESULT vrácený nespravovanou metodou COM, použijte u metody [PreserveSig].
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ Atribut [In] není podporován, pokud není použit také atribut [Out]. Blittable arrays nelze zařadit pouze jako [In].
@@ -467,6 +482,11 @@
Poskytnuté atributy „[In]“ a „[Out]“ u tohoto parametru se na tomto parametru nepodporují.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ atributy [In] a [Out]
@@ -702,6 +722,16 @@
Neplatné použití atributu VirtualMethodIndexAttribute
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Typ prvku ReadOnlySpan vrácený GetManagedValuesSource musí být stejný, jako typ prvku vrácený GetManagedValuesDestination.
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
Typ {0}určuje, že podporuje zařazování ve směru „Out“, ale neposkytuje metodu ToManaged, která vrací spravovaný typ
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ GeneratedComInterfaceAttribute a GeneratedComClassAttribute vyžadují nebezpečný kód. Projekt se musí aktualizovat na <AllowUnsafeBlocks>true</AllowUnsafeBlocks>.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.de.xlf
index 6b978f9aff5a9f..3135aa3bbe7eaa 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.de.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.de.xlf
@@ -147,6 +147,16 @@
Das .NET COM-Hosting mit "EnableComHosting" unterstützt keine Schnittstellen mit "GeneratedComInterfaceAttribute".
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Der Rückgabewert in der verwalteten Definition wird beim Aufrufen der nicht verwalteten COM-Methode in einen out-Parameter konvertiert. Wenn als Rückgabewert der von der nicht verwalteten COM-Methode zurückgegebene HRESULT-Code eingesetzt werden soll, verwenden Sie "[PreserveSig]" für die Methode.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ Das [In]-Attribut wird nur unterstützt, wenn auch das [Out]-Attribut verwendet wird. Blittable-Arrays können nicht nur als "[In]" gemarshallt werden.
@@ -467,6 +482,11 @@
Die angegebenen Attribute \"[In]\" und \"[Out]\" für diesen Parameter werden für diesen Parameter nicht unterstützt.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ [In]- und [Out]-Attribute
@@ -702,6 +722,16 @@
Ungültige Verwendung von "VirtualMethodIndexAttribute"
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Der von \"GetManagedValuesSource\" zurückgegebene Elementtyp \"ReadOnlySpan\" muss mit dem Elementtyp identisch sein, der von \"GetManagedValuesDestination\" zurückgegeben wird.
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
Der Typ \"{0}\" gibt an, dass das Marshalling in der Out-Richtung unterstützt wird. Er stellt jedoch keine ToManaged-Methode bereit, die den verwalteten Typ zurückgibt.
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ 'GeneratedComInterfaceAttribute' und 'GeneratedComClassAttribute' erfordern unsicheren Code. Das Projekt muss mit '<AllowUnsafeBlocks>wahr</AllowUnsafeBlocks>' aktualisiert werden.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.es.xlf
index 077827dbf7ef9b..f0e4701f345ccf 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.es.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.es.xlf
@@ -147,6 +147,16 @@
El hospedaje COM de .NET con “EnableComHosting” no admite interfaces con “GeneratedComInterfaceAttribute”
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ El valor devuelto en la definición administrada se convertirá en un parámetro “out” al llamar al método COM no administrado. Si el valor devuelto debe ser el código HRESULT devuelto por el método COM no administrado, use “[PreserveSig]” en el método.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ El atributo '[In]' no se admite a menos que también se use el atributo '[Out]'. Las matrices que se pueden transferir en bloque de bits no se pueden serializar solo como '[In]'.
@@ -467,6 +482,11 @@
En este parámetro, los atributos “[In]” y “[Out]” proporcionados no se admiten.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Atributos [In] y [Out]
@@ -702,6 +722,16 @@
Uso de ”VirtualMethodIndexAttribute” no válido
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ El tipo de elemento del “ReadOnlySpan” devuelto por “GetManagedValuesSource” debe ser el mismo que el tipo de elemento devuelto por “GetManagedValuesDestination”.
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
El tipo “{0}” especifica que admite la serialización en la dirección “Out”, pero no proporciona un método “ToManaged” que devuelva el tipo administrado
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ "GeneratedComInterfaceAttribute" y "GeneratedComClassAttribute" requieren código no seguro. El proyecto debe actualizarse con "<AllowUnsafeBlocks>true</AllowUnsafeBlocks>".
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.fr.xlf
index 7b06fbb9966ce1..228abb0f43b9c8 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.fr.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.fr.xlf
@@ -147,6 +147,16 @@
L'hébergement .NET COM avec 'EnableComHosting' ne prend pas en charge les interfaces avec 'GeneratedComInterfaceAttribute'
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ La valeur de retour dans la définition managée est convertie en paramètre 'out' lors de l’appel de la méthode COM non managée. Si la valeur de retour doit être le code HRESULT retourné par la méthode COM non managée, utilisez '[PreserveSig]' sur la méthode.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ L’attribut '[In]' n’est pas pris en charge, sauf si l’attribut '[Out]' est également utilisé. Les tableaux blittables ne peuvent pas être marshalés en tant que « [In] » uniquement.
@@ -467,6 +482,11 @@
Les attributs « [In] » et « [Out] » fournis sur ce paramètre ne sont pas pris en charge sur ce paramètre.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Attributs [In] et [Out]
@@ -702,6 +722,16 @@
Utilisation de « VirtualMethodIndexAttribute » non valide
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Le type d’élément de « ReadOnlySpan » retourné par « GetManagedValuesSource » doit être identique au type d’élément retourné par « GetManagedValuesDestination ».
@@ -903,8 +933,8 @@
-
- L’attribut '[Out]' est uniquement pris en charge sur les paramètres de tableau. Envisagez d’utiliser des mots clés 'out' ou 'ref' pour rendre le paramètre mutable.
+
+ L’attribut '[Out]' est uniquement pris en charge sur les paramètres de tableau. Envisagez d’utiliser des mots clés 'out' ou 'ref' pour rendre le paramètre mutable.
@@ -917,6 +947,11 @@
Le type « {0} » spécifie qu’il prend en charge le marshaling dans la direction « Out », mais il ne fournit pas de méthode « ToManaged » qui retourne le type managé
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ « GeneratedComInterfaceAttribute » et « GeneratedComClassAttribute » nécessitent du code non sécurisé. Le projet doit être mis à jour avec « <AllowUnsafeBlocks>true</AllowUnsafeBlocks> ».
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.it.xlf
index ee4ead36b3e114..58c83094b063bc 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.it.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.it.xlf
@@ -147,6 +147,16 @@
L'hosting COM .NET con 'EnableComHosting' non supporta le interfacce con 'GeneratedComInterfaceAttribute'.
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Il valore restituito nella definizione gestita verrà convertito in un parametro 'out' quando si chiama il metodo COM non gestito. Se il valore restituito deve essere il codice HRESULT restituito dal metodo COM non gestito, utilizzare '[PreserveSig]' sul metodo.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ L'attributo '[In]' non è supportato a meno che non venga usato anche l'attributo '[Out]'. Le matrici copiabili da BLT non possono essere sottoposte a marshalling solo come '[In]'.
@@ -467,6 +482,11 @@
Gli attributi '[In]' e '[Out]' specificati per questo parametro non sono supportati in questo parametro.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Attributi [In] e [Out]
@@ -702,6 +722,16 @@
Utilizzo di 'VirtualMethodIndexAttribute' non valido
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Il tipo di elemento di 'ReadOnlySpan' restituito da 'GetManagedValuesSource' deve essere uguale al tipo di elemento restituito da 'GetManagedValuesDestination'.
@@ -903,8 +933,8 @@
-
- L'attributo '[Out]' è supportato solo nei parametri di matrice. Provare a usare le parole chiave 'out' o 'ref' per rendere modificabile il parametro.
+
+ L'attributo '[Out]' è supportato solo nei parametri di matrice. Provare a usare le parole chiave 'out' o 'ref' per rendere modificabile il parametro.
@@ -917,6 +947,11 @@
Il tipo '{0}' specifica che supporta il marshalling nella direzione 'Out', ma non fornisce un metodo 'ToManaged' che restituisce il tipo gestito
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ GeneratedComInterfaceAttribute e 'GeneratedComClassAttribute' richiedono codice non gestito. Il progetto deve essere aggiornato con '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ja.xlf
index 9c12755cb80b44..331eb28eaa414d 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ja.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ja.xlf
@@ -147,6 +147,16 @@
'EnableComHosting' を使用した .NET COM ホスティングでは、'GeneratedComInterfaceAttribute' のインターフェイスはサポートされていません
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ マネージド定義の戻り値は、アンマネージド COM メソッドを呼び出すときに 'out' パラメーターに変換されます。戻り値を、アンマネージド COM メソッドによって返される HRESULT コードにする場合は、メソッドで '[PreserveSig]' を使用してください。
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ '[In]'属性は、'[Out]'属性も使用しない限りサポートされません。Blittable 配列は、'[In]'としてのみマーシャリングできません。
@@ -467,6 +482,11 @@
このパラメーターに指定された '[In]' 属性と '[Out]' 属性は、このパラメーターではサポートされていません。
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ 属性の[In]と[Out]
@@ -702,6 +722,16 @@
'VirtualMethodIndexAttribute' の使用法が無効です
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ 'GetManagedValuesSource' によって返される 'ReadOnlySpan' の要素型は、'GetManagedValuesDestination' によって返される要素型と同じである必要があります。
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
型 '{0}' は、'Out' 方向のマーシャリングをサポートしますが、マネージド型を返す 'ToManaged' メソッドは指定されません
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ 'GeneratedComInterfaceAttribute' および 'GeneratedComClassAttribute' にはアンセーフ コードが必要です。プロジェクトは '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>' で更新する必要があります。
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ko.xlf
index 53b72d47f60fa3..aedf84c829c061 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ko.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ko.xlf
@@ -147,6 +147,16 @@
'EnableComHosting'을 사용한 .NET COM 호스팅은 'GeneratedComInterfaceAttribute'를 사용한 인터페이스를 지원하지 않습니다.
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ 관리 정의의 반환 값은 관리되지 않는 COM 메서드를 호출할 때 'out' 매개 변수로 변환됩니다. 반환 값이 관리되지 않는 COM 메서드에서 반환된 HRESULT 코드인 경우 메서드에서 '[PreserveSig]'를 사용하세요.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ '[Out]' 특성도 사용되지 않는 한 '[In]' 특성은 지원되지 않습니다. Blittable 배열은 '[In]'으로만 마샬링할 수 없습니다.
@@ -467,6 +482,11 @@
이 매개 변수에 제공된 '[In]' 및 '[Out]' 특성은 이 매개 변수에서 지원되지 않습니다.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ [In] 및 [Out] 속성
@@ -702,6 +722,16 @@
잘못된 'VirtualMethodIndexAttribute' 사용
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ 'GetManagedValuesSource'에서 반환된 'ReadOnlySpan'의 요소 형식은 'GetManagedValuesDestination'에서 반환된 요소 형식과 동일해야 합니다.
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
형식 '{0}'은(는) 'Out' 방향으로 마샬링을 지원하도록 지정하지만 관리 형식을 반환하는 'ToManaged' 메서드를 제공하지 않습니다.
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ 'GeneratedComInterfaceAttribute' 및 'GeneratedComClassAttribute'에는 안전하지 않은 코드가 필요합니다. 프로젝트를 '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'로 업데이트해야 합니다.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pl.xlf
index fb6cf9f172c21b..f051d95f3b9c9e 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pl.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pl.xlf
@@ -147,6 +147,16 @@
Hosting modelu COM platformy .NET z elementem „EnableComHosting” nie obsługuje interfejsów z atrybutem „GeneratedComInterfaceAttribute”
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Wartość zwracana w definicji zarządzanej zostanie przekonwertowana na parametr „out” podczas wywoływania niezarządzanej metody COM. Jeśli wartość zwracana ma być kodem HRESULT zwracanym przez niezarządzaną metodę COM, należy użyć „[PreserveSig]” w metodzie.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ Atrybut „[In]” nie jest obsługiwany, chyba że używany jest również atrybut „[Out]”. Tablice kopiowalne nie mogą być kierowane tylko jako „[In]”.
@@ -467,6 +482,11 @@
Podane atrybuty „[In]” i „[Out]” w tym parametrze nie są obsługiwane w tym parametrze.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Atrybuty [In] i [Out]
@@ -702,6 +722,16 @@
Nieprawidłowe użycie atrybutu „VirtualMethodIndexAttribute”
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Typ elementu „ReadOnlySpan” zwracany przez element „GetManagedValuesSource” musi być taki sam jak typ elementu zwracany przez element „GetManagedValuesDestination”.
@@ -903,8 +933,8 @@
-
- Atrybut „[Out]” jest obsługiwany tylko w przypadku parametrów tablicy. Rozważ użycie słów kluczowych „out” lub „ref”, aby umożliwić modyfikowanie parametru.
+
+ Atrybut „[Out]” jest obsługiwany tylko w przypadku parametrów tablicy. Rozważ użycie słów kluczowych „out” lub „ref”, aby umożliwić modyfikowanie parametru.
@@ -917,6 +947,11 @@
Typ „{0}” określa, że obsługuje skierowanie w kierunku „Out”, ale nie zapewnia metody „ToManaged”, która zwraca typ zarządzany
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ Atrybut „GeneratedComInterfaceAttribute” i „GeneratedComClassAttribute” wymagają niebezpiecznego kodu. Projekt musi zostać zaktualizowany za pomocą polecenia „<AllowUnsafeBlocks>true</AllowUnsafeBlocks>”.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pt-BR.xlf
index 8d2e606d2d0307..c1bc60315bc05c 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pt-BR.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.pt-BR.xlf
@@ -147,6 +147,16 @@
A hospedagem .NET COM com 'EnableComHosting' não dá suporte a interfaces com 'GeneratedComInterfaceAttribute'
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ O valor de retorno na definição gerenciada será convertido em um parâmetro 'out' ao chamar o método COM não gerenciado. Se o valor de retorno for o código HRESULT retornado pelo método COM não gerenciado, use '[PreserveSig]' no método.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ O atributo '[In]' não é suportado, a menos que o atributo '[Out]' também seja usado. Matrizes Blittable não podem ser empacotadas apenas como '[In]'.
@@ -467,6 +482,11 @@
Os atributos '[In]' e '[Out]' neste parâmetro não têm suporte neste parâmetro.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Atributos [In] e [Out]
@@ -702,6 +722,16 @@
Uso de 'VirtualMethodIndexAttribute' inválido
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ O tipo de elemento de 'ReadOnlySpan' retornado por 'GetManagedValuesSource' deve ser igual ao tipo de elemento retornado por 'GetManagedValuesDestination'.
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
O tipo '{0}' especifica que ele dá suporte a marshalling na direção 'Out', mas não fornece um método 'ToManaged' que retorna o tipo gerenciado
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ "GeneratedComInterfaceAttribute" e "GeneratedComClassAttribute" exigem código não seguro. O projeto deve ser atualizado com "<AllowUnsafeBlocks>true</AllowUnsafeBlocks>".
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ru.xlf
index fca13d2b25e7f6..891ef9d077eb61 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ru.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.ru.xlf
@@ -147,6 +147,16 @@
Размещение .NET COM с "EnableComHosting" не поддерживает интерфейсы с "GeneratedComInterfaceAttribute"
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Возвращаемое значение в управляемом определении будет преобразовано в параметр "out" при вызове неуправляемого метода COM. Если возвращаемое значение должно быть кодом HRESULT, возвращаемым неуправляемым COM-методом, используйте "[PreserveSig]" в методе.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ Атрибут "[In]" не поддерживается, если также не используется атрибут "[Out]". Преобразуемые массивы нельзя сортировать только как "[In]".
@@ -467,6 +482,11 @@
Указанные атрибуты \"[In]\" и \"[Out]\" для этого параметра не поддерживаются.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ Атрибуты [In] и [Out]
@@ -702,6 +722,16 @@
Недопустимое использование VirtualMethodIndexAttribute
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ Тип элемента \"ReadOnlySpan\", возвращенный методом \"GetManagedValuesSource\", должен совпадать с типом элемента, возвращаемым методом \"GetManagedValuesDestination\".
@@ -903,8 +933,8 @@
-
- Атрибут "[Out]" поддерживается только для параметров массива. Рассмотрите возможность использования ключевых слов "out" или "ref", чтобы сделать параметр изменяемым.
+
+ Атрибут "[Out]" поддерживается только для параметров массива. Рассмотрите возможность использования ключевых слов "out" или "ref", чтобы сделать параметр изменяемым.
@@ -917,6 +947,11 @@
Тип \"{0}\" указывает, что поддерживает маршализацию в направлении \"наружу\", но не предоставляет метод \"ToManaged\", который возвращает управляемый тип
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ Для "GeneratedComInterfaceAttribute" и "GeneratedComClassAttribute" требуется небезопасный код. Проект необходимо обновить с использованием значения "<AllowUnsafeBlocks>true</AllowUnsafeBlocks>".
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.tr.xlf
index 44d2a4a4cbadd3..6748b1305030b9 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.tr.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.tr.xlf
@@ -147,6 +147,16 @@
'EnableComHosting' ile barındırma .NET COM, 'GeneratedComInterfaceAttribute' ile arabirimleri desteklemez
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ Yönetilen tanımdaki dönüş değeri, yönetilmeyen COM yöntemi çağrılırken 'out' parametresine dönüştürülür. Dönüş değerinin yönetilmeyen COM yöntemi tarafından döndürülen HRESULT kodu olması amaçlanmışsa, yöntemde '[PreserveSig]' kullanın.
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ '[Out]' özniteliği de kullanılmadığı sürece '[In]' özniteliği desteklenmez. Blittable dizileri yalnızca '[In]' olarak hazırlanamaz.
@@ -467,6 +482,11 @@
Bu parametrede sağlanan '[In]' ve '[Out]' öznitelikleri bu parametrede desteklenmiyor.
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ [In] ve [Out] öznitelikleri
@@ -702,6 +722,16 @@
Geçersiz 'VirtualMethodIndexAttribute' kullanımı
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ 'GetManagedValuesSource' tarafından döndürülen 'ReadOnlySpan' öğe türü, 'GetManagedValuesDestination' tarafından döndürülen öğe türüyle aynı olmalıdır.
@@ -903,8 +933,8 @@
-
- '[Out]' özniteliği yalnızca dizi parametrelerinde desteklenir. Parametreyi değiştirilebilir yapmak için 'out' veya 'ref' anahtar sözcükleri kullanmayı düşünün.
+
+ '[Out]' özniteliği yalnızca dizi parametrelerinde desteklenir. Parametreyi değiştirilebilir yapmak için 'out' veya 'ref' anahtar sözcükleri kullanmayı düşünün.
@@ -917,6 +947,11 @@
'{0}' türü, 'Out' yönünde sıralamayı desteklediğini belirtiyor, ancak yönetilen türü döndüren bir 'ToManaged' metodu sağlamıyor
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ 'GeneratedComInterfaceAttribute' ve 'GeneratedComClassAttribute' güvenli olmayan kod gerektiriyor. Projenin '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>' ile güncelleştirilmiş olması gerekiyor.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hans.xlf
index e6fbf9115aec2d..de0d085a227a7e 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hans.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hans.xlf
@@ -147,6 +147,16 @@
具有“EnableComHosting”的 .NET COM 托管不支持具有“GeneratedComInterfaceAttribute”的接口
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ 调用非托管 COM 方法时,托管定义中的返回值将转换为 "out" 参数。如果返回值是非托管 COM 方法返回的 HRESULT 代码,请对方法使用 "[PreserveSig]"。
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ 不支持“[In]”属性,除非也使用“[Out]”属性。不能仅将 Blittable 数组封送为“[In]”。
@@ -467,6 +482,11 @@
此参数上提供的 “[In]” 和 “[Out]” 属性在此参数上不受支持。
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ [In] 和 [Out] 属性
@@ -702,6 +722,16 @@
“VirtualMethodIndexAttribute” 使用情况无效
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ “GetManagedValuesSource” 返回的 “ReadOnlySpan” 的元素类型必须与 “GetManagedValuesDestination” 返回的元素类型相同。
@@ -903,8 +933,8 @@
-
- The `[Out]` attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
+
+ The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
@@ -917,6 +947,11 @@
类型“{0}”指定它支持按 “Out” 方向进行封送,但不提供返回托管类型的 “ToManaged” 方法
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ “GeneratedComInterfaceAttribute”和“GeneratedComClassAttribute”需要不安全代码。必须将项目更新为“<AllowUnsafeBlocks>true</AllowUnsafeBlocks>”。
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hant.xlf
index 528339678cefdb..408df3131a3be5 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hant.xlf
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/xlf/Strings.zh-Hant.xlf
@@ -147,6 +147,16 @@
以 'EnableComHosting' 裝載的 .NET COM 不支援具有 'GeneratedComInterfaceAttribute' 的介面
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'GeneratedComInterfaceAttribute' does not follow recommendations.
+
+ 呼叫未受控 COM 方法時,受控定義中的傳回值將轉換為 'out' 參數。如果傳回值預期是未受控 COM 方法傳回的 HRESULT 代碼,請在方法上使用 '[PreserveSig]'。
@@ -447,6 +457,11 @@
This type will be treated as a struct in the native signature, not as a native HRESULT
+
+
+ The '[In]' attribute is only supported on array parameters. By-value parameters are considered read-only by default.
+
+ 除非也使用 '[Out]' 屬性,否則不支援 '[In]' 屬性。無法只將 Blittable 陣列整理為 '[In]'。
@@ -467,6 +482,11 @@
此參數不支援在此參數上提供的 '[In]' 和 '[Out]' 屬性。
+
+
+ The '[In]' and '[Out]' attributes are only supported on array parameters. Consider using the 'ref' keyword to make the parameter mutable.
+
+ [In] 與 [Out] 屬性
@@ -702,6 +722,16 @@
'VirtualMethodIndexAttribute' 使用方式無效
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations. {0}
+
+
+
+
+ The usage of 'LibraryImportAttribute' does not follow recommendations.
+
+ 'GetManagedValuesSource' 傳回的 'ReadOnlySpan' 元素類型必須與 'GetManagedValuesDestination' 傳回的元素類型相同。
@@ -903,8 +933,8 @@
-
- 只有陣列參數才支援 '[Out]' 屬性。請考慮使用 'out' 或 'ref' 關鍵字將參數設為可變。
+
+ 只有陣列參數才支援 '[Out]' 屬性。請考慮使用 'out' 或 'ref' 關鍵字將參數設為可變。
@@ -917,6 +947,11 @@
類型 '{0}' 指定它支援以 'Out' 方向排列,但未提供傳回受管理類型的 'ToManaged' 方法
+
+
+ It is recommended to use explicit '[In]' and '[Out]' attributes on array parameters.
+
+ 'GeneratedComInterfaceAttribute' 和 'GeneratedComClassAttribute' 需要不安全的程式碼。專案必須以 '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>' 更新。
diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs
index 2bef64490f9a4e..eb9a0237307bc3 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/DiagnosticDescriptorProvider.cs
@@ -24,6 +24,7 @@ internal sealed class DiagnosticDescriptorProvider : IDiagnosticDescriptorProvid
GeneratorDiagnostic.NotSupported { NotSupportedDetails: not null, TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails,
GeneratorDiagnostic.UnnecessaryData { TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.UnnecessaryParameterMarshallingInfo,
GeneratorDiagnostic.UnnecessaryData { TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.UnnecessaryReturnMarshallingInfo,
+ GeneratorDiagnostic.NotRecommended => GeneratorDiagnostics.LibraryImportUsageDoesNotFollowBestPractices,
{ IsFatal: false } => null,
{ TypePositionInfo.IsManagedReturnPosition: true } => GeneratorDiagnostics.ReturnTypeNotSupported,
{ TypePositionInfo.IsManagedReturnPosition: false } => GeneratorDiagnostics.ParameterTypeNotSupported,
diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs
index 2af2abadcdd607..f5fd78d48e587c 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/GeneratorDiagnostics.cs
@@ -254,6 +254,16 @@ public class Ids
DiagnosticSeverity.Warning,
isEnabledByDefault: true);
+ ///
+ public static readonly DiagnosticDescriptor LibraryImportUsageDoesNotFollowBestPractices =
+ new DiagnosticDescriptor(
+ Ids.NotRecommendedGeneratedComInterfaceUsage,
+ GetResourceString(nameof(SR.LibraryImportUsageDoesNotFollowBestPracticesTitle)),
+ GetResourceString(nameof(SR.LibraryImportUsageDoesNotFollowBestPracticesMessageWithDetails)),
+ Category,
+ DiagnosticSeverity.Info,
+ isEnabledByDefault: true);
+
///
/// Report diagnostic for invalid configuration for string marshalling.
///
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalValuesProviderExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalValuesProviderExtensions.cs
index 123d649c913cd5..5455510ac356c0 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalValuesProviderExtensions.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/IncrementalValuesProviderExtensions.cs
@@ -47,7 +47,7 @@ public static IncrementalValuesProvider SelectNormalized(this Incr
return provider.Select((node, ct) => node.NormalizeWhitespace());
}
- public static (IncrementalValuesProvider, IncrementalValuesProvider) Split(this IncrementalValuesProvider<(T, T2)> provider)
+ public static (IncrementalValuesProvider, IncrementalValuesProvider) Split(this IncrementalValuesProvider<(T, T2)> provider)
{
return (provider.Select(static (data, ct) => data.Item1), provider.Select(static (data, ct) => data.Item2));
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
index 73b8cd8eb901a9..69180eca11c190 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
@@ -431,17 +431,10 @@ private ResolvedGenerator CreateNativeCollectionMarshaller(
{
byValueMarshalKindSupport = ByValueMarshalKindSupportDescriptor.Default;
}
- else if (!elementIsBlittable || ElementTypeIsSometimesNonBlittable(elementInfo))
- {
- // If the type is not blittable or is sometimes not blittable, we will generate different code when the attributes are provided.
- byValueMarshalKindSupport = ByValueMarshalKindSupportDescriptor.ArrayParameter;
- }
else
{
- // If the type is always blittable, we'll generate the same code regardless of the attributes,
- // but we'll allow them to make it easier to transition to source-generated code and allow users to be clear about expectations
- // for values in pre-allocated buffers.
- byValueMarshalKindSupport = ByValueMarshalKindSupportDescriptor.PinnedParameter;
+ // If we have an array, we will use the Array [In, Out] support descriptor
+ byValueMarshalKindSupport = ByValueMarshalKindSupportDescriptor.ArrayParameter;
}
// Elements in the collection must be blittable to use the pinnable marshaller.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
index 5cc2a8f9a9b261..dd7a40fb8c90e2 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
@@ -27,7 +27,7 @@ public ResolvedGenerator Create(TypePositionInfo info, StubCodeContext context)
private static ResolvedGenerator ValidateByValueMarshalKind(TypePositionInfo info, StubCodeContext context, ResolvedGenerator generator)
{
- if (generator.Generator is Forwarder || info.ByValueContentsMarshalKind == ByValueContentsMarshalKind.Default)
+ if (generator.Generator is Forwarder)
{
// Forwarder allows everything since it just forwards to a P/Invoke.
// The Default marshal kind is always valid.
@@ -41,6 +41,7 @@ private static ResolvedGenerator ValidateByValueMarshalKind(TypePositionInfo inf
ByValueMarshalKindSupport.Supported => generator,
ByValueMarshalKindSupport.NotSupported => ResolvedGenerator.ResolvedWithDiagnostics(s_forwarder, generator.Diagnostics.Add(diagnostic!)),
ByValueMarshalKindSupport.Unnecessary => generator with { Diagnostics = generator.Diagnostics.Add(diagnostic!) },
+ ByValueMarshalKindSupport.NotRecommended => generator with { Diagnostics = generator.Diagnostics.Add(diagnostic!) },
_ => throw new UnreachableException()
};
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueMarshalKindSupportDescriptor.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueMarshalKindSupportDescriptor.cs
index 1f859d34ff919b..7754e177d66063 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueMarshalKindSupportDescriptor.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueMarshalKindSupportDescriptor.cs
@@ -3,127 +3,105 @@
using System;
using System.Collections.Immutable;
+using System.Diagnostics;
namespace Microsoft.Interop
{
+ public record struct ByValueMarshalKindSupportInfo(ByValueMarshalKindSupport Support, string? details)
+ {
+ public ByValueMarshalKindSupport GetSupport(TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
+ {
+ diagnostic = Support switch
+ {
+ ByValueMarshalKindSupport.Supported => null,
+ ByValueMarshalKindSupport.NotRecommended =>
+ new GeneratorDiagnostic.NotRecommended(info, context)
+ {
+ Details = details
+ },
+ ByValueMarshalKindSupport.Unnecessary =>
+ new GeneratorDiagnostic.UnnecessaryData(
+ info,
+ context,
+ ImmutableArray.Create(info.ByValueMarshalAttributeLocations.OutLocation))
+ {
+ UnnecessaryDataName = SR.InOutAttributes,
+ UnnecessaryDataDetails = details
+ },
+ ByValueMarshalKindSupport.NotSupported =>
+ new GeneratorDiagnostic.NotSupported(info, context)
+ {
+ NotSupportedDetails = details
+ },
+ _ => throw new UnreachableException()
+ };
+ return Support;
+ }
+ }
+
///
/// Provides an implementation of through
///
public record ByValueMarshalKindSupportDescriptor(
- ByValueMarshalKindSupport InSupport, string? InSupportDetails,
- ByValueMarshalKindSupport OutSupport, string? OutSupportDetails,
- ByValueMarshalKindSupport InOutSupport, string? InOutSupportDetails)
+ ByValueMarshalKindSupportInfo DefaultSupport,
+ ByValueMarshalKindSupportInfo InSupport,
+ ByValueMarshalKindSupportInfo OutSupport,
+ ByValueMarshalKindSupportInfo InOutSupport)
{
///
/// A default for by value parameters. [In] is allowed, but unnecessary. Out is not allowed.
///
public static readonly ByValueMarshalKindSupportDescriptor Default = new ByValueMarshalKindSupportDescriptor(
- InSupport: ByValueMarshalKindSupport.Unnecessary, InSupportDetails: SR.InAttributeOnlyIsDefault,
- OutSupport: ByValueMarshalKindSupport.NotSupported, OutSupportDetails: SR.OutAttributeNotSupportedOnByValueParameters,
- InOutSupport: ByValueMarshalKindSupport.NotSupported, InOutSupportDetails: SR.OutAttributeNotSupportedOnByValueParameters);
+ DefaultSupport: new(ByValueMarshalKindSupport.Supported, null),
+ InSupport: new(ByValueMarshalKindSupport.NotSupported, SR.InAttributeNotSupportedOnByValueParameters),
+ OutSupport: new(ByValueMarshalKindSupport.NotSupported, SR.OutAttributeNotSupportedOnByValueParameters),
+ InOutSupport: new(ByValueMarshalKindSupport.NotSupported, SR.InOutAttributeNotSupportedOnByValueParameters));
///
- /// A default for by value array parameters. [In] is allowed, but unnecessary. Out is allowed.
+ /// A default for by value array parameters. Default is allowed, but Not Recommended. [In], [Out], and [In, Out] are allowed
///
public static readonly ByValueMarshalKindSupportDescriptor ArrayParameter = new ByValueMarshalKindSupportDescriptor(
- InSupport: ByValueMarshalKindSupport.Unnecessary, InSupportDetails: SR.InAttributeOnlyIsDefault,
- OutSupport: ByValueMarshalKindSupport.Supported, OutSupportDetails: null,
- InOutSupport: ByValueMarshalKindSupport.Supported, InOutSupportDetails: null);
-
- ///
- /// A default for pinned parameters. [In] is allowed, but unnecessary. Out is allowed.
- ///
- public static readonly ByValueMarshalKindSupportDescriptor PinnedParameter = new ByValueMarshalKindSupportDescriptor(
- InSupport: ByValueMarshalKindSupport.Unnecessary, InSupportDetails: SR.InAttributeOnlyIsDefault,
- OutSupport: ByValueMarshalKindSupport.Supported, OutSupportDetails: null,
- InOutSupport: ByValueMarshalKindSupport.Supported, InOutSupportDetails: null);
+ DefaultSupport: new(ByValueMarshalKindSupport.NotRecommended, SR.PreferExplicitInOutAttributesOnArrays),
+ InSupport: new(ByValueMarshalKindSupport.Supported, null),
+ OutSupport: new(ByValueMarshalKindSupport.Supported, null),
+ InOutSupport: new(ByValueMarshalKindSupport.Supported, null));
///
/// Returns the support for the ByValueContentsMarshalKind, and if it is not , diagnostic is not null
///
public ByValueMarshalKindSupport GetSupport(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
{
- if (info.IsByRef && marshalKind != ByValueContentsMarshalKind.Default)
+ if (info.IsByRef)
{
- diagnostic = new GeneratorDiagnostic.NotSupported(info, context)
+ // ByRef with ByValue attributes is not allowed
+ if (marshalKind != ByValueContentsMarshalKind.Default)
{
- NotSupportedDetails = SR.InOutAttributeByRefNotSupported
- };
- return ByValueMarshalKindSupport.NotSupported;
- }
- switch (marshalKind)
- {
- case ByValueContentsMarshalKind.Default:
- diagnostic = null;
- return ByValueMarshalKindSupport.Supported;
- case ByValueContentsMarshalKind.Out:
- diagnostic = OutSupport switch
+ diagnostic = new GeneratorDiagnostic.NotSupported(info, context)
{
- ByValueMarshalKindSupport.Supported => null,
- ByValueMarshalKindSupport.Unnecessary
- => new GeneratorDiagnostic.UnnecessaryData(
- info,
- context,
- ImmutableArray.Create(info.ByValueMarshalAttributeLocations.OutLocation))
- {
- UnnecessaryDataName = SR.InOutAttributes,
- UnnecessaryDataDetails = OutSupportDetails
- },
- ByValueMarshalKindSupport.NotSupported
- => new GeneratorDiagnostic.NotSupported(
- info,
- context)
- { NotSupportedDetails = OutSupportDetails },
- _ => throw new UnreachableException($"Unexpected {nameof(ByValueMarshalKindSupport)} Variant: {InOutSupport}")
+ NotSupportedDetails = SR.InOutAttributeByRefNotSupported
};
- return OutSupport;
- case ByValueContentsMarshalKind.In:
- diagnostic = InSupport switch
- {
- ByValueMarshalKindSupport.Supported => null,
- ByValueMarshalKindSupport.Unnecessary
- => new GeneratorDiagnostic.UnnecessaryData(
- info,
- context,
- ImmutableArray.Create(info.ByValueMarshalAttributeLocations.InLocation))
- {
- UnnecessaryDataName = SR.InOutAttributes,
- UnnecessaryDataDetails = InSupportDetails
- },
- ByValueMarshalKindSupport.NotSupported
- => new GeneratorDiagnostic.NotSupported(
- info,
- context)
- { NotSupportedDetails = InSupportDetails },
- _ => throw new UnreachableException($"Unexpected {nameof(ByValueMarshalKindSupport)} Variant: {InOutSupport}")
- };
- return InSupport;
- case ByValueContentsMarshalKind.InOut:
- diagnostic = InOutSupport switch
- {
- ByValueMarshalKindSupport.Supported => null,
- ByValueMarshalKindSupport.Unnecessary
- => new GeneratorDiagnostic.UnnecessaryData(
- info,
- context,
- ImmutableArray.Create(
- info.ByValueMarshalAttributeLocations.InLocation,
- info.ByValueMarshalAttributeLocations.OutLocation))
- {
- UnnecessaryDataName = SR.InOutAttributes,
- UnnecessaryDataDetails = InOutSupportDetails
- },
- ByValueMarshalKindSupport.NotSupported
- => new GeneratorDiagnostic.NotSupported(
- info,
- context)
- { NotSupportedDetails = InOutSupportDetails },
- _ => throw new UnreachableException($"Unexpected {nameof(ByValueMarshalKindSupport)} Variant: {InOutSupport}")
- };
- return InOutSupport;
- default:
- throw new UnreachableException($"Unexpected {nameof(ByValueContentsMarshalKind)} variant: {marshalKind}");
+ return ByValueMarshalKindSupport.NotSupported;
+ }
+ // ByRef with no ByValue attributes is supported
+ diagnostic = null;
+ return ByValueMarshalKindSupport.Supported;
+ }
+ // Return can never have In or Out attributes, so can assume valid ByValue attributes
+ if (info.ManagedIndex < 0)
+ {
+ Debug.Assert(marshalKind is ByValueContentsMarshalKind.Default);
+ diagnostic = null;
+ return ByValueMarshalKindSupport.Supported;
}
+
+ return marshalKind switch
+ {
+ ByValueContentsMarshalKind.Default => DefaultSupport.GetSupport(info, context, out diagnostic),
+ ByValueContentsMarshalKind.In => InSupport.GetSupport(info, context, out diagnostic),
+ ByValueContentsMarshalKind.Out => OutSupport.GetSupport(info, context, out diagnostic),
+ ByValueContentsMarshalKind.InOut => InOutSupport.GetSupport(info, context, out diagnostic),
+ _ => throw new UnreachableException()
+ };
}
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs
index 22444e79824c9b..02820335ec176e 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/GeneratorDiagnostic.cs
@@ -62,5 +62,18 @@ public override DiagnosticInfo ToDiagnosticInfo(DiagnosticDescriptor descriptor,
UnnecessaryDataDetails ?? "");
}
}
+
+ public sealed record NotRecommended(TypePositionInfo TypePositionInfo, StubCodeContext StubCodeContext) : GeneratorDiagnostic(TypePositionInfo, StubCodeContext, isFatal: false)
+ {
+ public string? Details { get; init; }
+
+ public override DiagnosticInfo ToDiagnosticInfo(DiagnosticDescriptor descriptor, Location location, string elementName)
+ {
+ return DiagnosticInfo.Create(
+ descriptor,
+ location,
+ Details);
+ }
+ }
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs
index f5e8aacdaa3c15..598ba380028946 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs
@@ -83,6 +83,10 @@ public enum ByValueMarshalKindSupport
/// The provided is supported but does not change behavior from the default in this scenario.
///
Unnecessary,
+ ///
+ /// The provided is supported but does not follow best practices.
+ ///
+ NotRecommended,
}
///
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs
index 45ef61f85dbc58..039d78ed350068 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StaticPinnableManagedValueMarshaller.cs
@@ -105,7 +105,7 @@ private IEnumerable GeneratePinningPath(TypePositionInfo info,
public ByValueMarshalKindSupport SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, TypePositionInfo info, StubCodeContext context, out GeneratorDiagnostic? diagnostic)
{
- return ByValueMarshalKindSupportDescriptor.PinnedParameter.GetSupport(marshalKind, info, context, out diagnostic);
+ return _innerMarshallingGenerator.SupportsByValueMarshalKind(marshalKind, info, context, out diagnostic);
}
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ByValueContentsMarshalling.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ByValueContentsMarshalling.cs
new file mode 100644
index 00000000000000..fdd2d33d6e7d27
--- /dev/null
+++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ByValueContentsMarshalling.cs
@@ -0,0 +1,301 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Threading.Tasks;
+using Microsoft.CodeAnalysis.Testing;
+using Microsoft.Interop;
+using Xunit;
+using static Microsoft.Interop.UnitTests.TestUtils;
+using StringMarshalling = System.Runtime.InteropServices.StringMarshalling;
+using VerifyComInterfaceGenerator = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier;
+
+namespace ComInterfaceGenerator.Unit.Tests
+{
+ public class ByValueContentsMarshalling
+ {
+ private static IComInterfaceAttributeProvider GetAttributeProvider(GeneratorKind generator)
+ => generator switch
+ {
+ GeneratorKind.VTableIndexStubGenerator => new VirtualMethodIndexAttributeProvider(),
+ GeneratorKind.ComInterfaceGeneratorManagedObjectWrapper => new GeneratedComInterfaceAttributeProvider(System.Runtime.InteropServices.Marshalling.ComInterfaceOptions.ManagedObjectWrapper),
+ GeneratorKind.ComInterfaceGeneratorComObjectWrapper => new GeneratedComInterfaceAttributeProvider(System.Runtime.InteropServices.Marshalling.ComInterfaceOptions.ComObjectWrapper),
+ GeneratorKind.ComInterfaceGenerator => new GeneratedComInterfaceAttributeProvider(),
+ _ => throw new UnreachableException(),
+ };
+
+ public static IEnumerable