diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs
index b9d36ecacbf52a..ba2f234da4da42 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ComInterfaceGeneratorDiagnosticsAnalyzer.cs
@@ -185,11 +185,11 @@ private static void AnalyzeInterface(
if (srcCtx.VtableIndexData.Direction is MarshalDirection.ManagedToUnmanaged or MarshalDirection.Bidirectional)
{
- (_, managedToNativeDiags) = VirtualMethodPointerStubGenerator.GenerateManagedToNativeStub(srcCtx, ComInterfaceGeneratorHelpers.GetGeneratorResolver);
+ (_, managedToNativeDiags) = VirtualMethodPointerStubGenerator.GenerateManagedToNativeStub(srcCtx, static (env, dir) => new ByValueContentsMarshalKindValidator(ComInterfaceGeneratorHelpers.GetGeneratorResolver(env, dir)));
}
if (srcCtx.VtableIndexData.Direction is MarshalDirection.UnmanagedToManaged or MarshalDirection.Bidirectional)
{
- (_, nativeToManagedDiags) = VirtualMethodPointerStubGenerator.GenerateNativeToManagedStub(srcCtx, ComInterfaceGeneratorHelpers.GetGeneratorResolver);
+ (_, nativeToManagedDiags) = VirtualMethodPointerStubGenerator.GenerateNativeToManagedStub(srcCtx, static (env, dir) => new ByValueContentsMarshalKindValidator(ComInterfaceGeneratorHelpers.GetGeneratorResolver(env, dir)));
}
// Deduplicate diagnostics reported for both directions (matching original generator behavior)
diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs
index f9cbc736f5ff33..49796cfccb7e3d 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/ConvertComImportToGeneratedComInterfaceAnalyzer.cs
@@ -85,8 +85,8 @@ public override void Initialize(AnalysisContext context)
new CodeEmitOptions(SkipInit: true),
typeof(ConvertComImportToGeneratedComInterfaceAnalyzer).Assembly);
- var managedToUnmanagedFactory = ComInterfaceGeneratorHelpers.GetGeneratorResolver(env.EnvironmentFlags, MarshalDirection.ManagedToUnmanaged);
- var unmanagedToManagedFactory = ComInterfaceGeneratorHelpers.GetGeneratorResolver(env.EnvironmentFlags, MarshalDirection.UnmanagedToManaged);
+ var managedToUnmanagedFactory = new ByValueContentsMarshalKindValidator(ComInterfaceGeneratorHelpers.GetGeneratorResolver(env.EnvironmentFlags, MarshalDirection.ManagedToUnmanaged));
+ var unmanagedToManagedFactory = new ByValueContentsMarshalKindValidator(ComInterfaceGeneratorHelpers.GetGeneratorResolver(env.EnvironmentFlags, MarshalDirection.UnmanagedToManaged));
mayRequireAdditionalWork = diagnostics.Diagnostics.Any();
bool anyExplicitlyUnsupportedInfo = false;
diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/VtableIndexStubDiagnosticsAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/VtableIndexStubDiagnosticsAnalyzer.cs
index 01af871b46328e..f35561d8544cd2 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/VtableIndexStubDiagnosticsAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Analyzers/VtableIndexStubDiagnosticsAnalyzer.cs
@@ -91,14 +91,14 @@ private static void AnalyzeMethod(SymbolAnalysisContext context, MethodDeclarati
if (stubContext.VtableIndexData.Direction is MarshalDirection.ManagedToUnmanaged or MarshalDirection.Bidirectional)
{
- var (_, diagnostics) = VirtualMethodPointerStubGenerator.GenerateManagedToNativeStub(stubContext, VtableIndexStubGeneratorHelpers.GetGeneratorResolver);
+ var (_, diagnostics) = VirtualMethodPointerStubGenerator.GenerateManagedToNativeStub(stubContext, static (env, dir) => new ByValueContentsMarshalKindValidator(VtableIndexStubGeneratorHelpers.GetGeneratorResolver(env, dir)));
foreach (DiagnosticInfo diag in diagnostics)
context.ReportDiagnostic(diag.ToDiagnostic());
}
if (stubContext.VtableIndexData.Direction is MarshalDirection.UnmanagedToManaged or MarshalDirection.Bidirectional)
{
- var (_, diagnostics) = VirtualMethodPointerStubGenerator.GenerateNativeToManagedStub(stubContext, VtableIndexStubGeneratorHelpers.GetGeneratorResolver);
+ var (_, diagnostics) = VirtualMethodPointerStubGenerator.GenerateNativeToManagedStub(stubContext, static (env, dir) => new ByValueContentsMarshalKindValidator(VtableIndexStubGeneratorHelpers.GetGeneratorResolver(env, dir)));
foreach (DiagnosticInfo diag in diagnostics)
context.ReportDiagnostic(diag.ToDiagnostic());
}
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 944d182a65b0b7..1b8fbf1f23479c 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx
+++ b/src/libraries/System.Runtime.InteropServices/gen/Common/Resources/Strings.resx
@@ -868,9 +868,6 @@
The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1}{1} is a message containing additional details about what is not valid
-
- [In] and [Out] attributes
-
The '[Out]' attribute is only supported on array parameters. Consider using 'out' or 'ref' keywords to make the parameter mutable.
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 c2b34b5ad4c2eb..db0b87133013f9 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
@@ -507,11 +507,6 @@
Atributy „[In]“ a „[Out]“ jsou podporovány pouze u parametrů pole. Zvažte použití klíčového slova „ref“ k nastavení měnitelného parametru.
-
- [In] and [Out] attributes
- atributy [In] a [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Objekty zařazené z VARIANT jako parametry in ve voláních nespravovaných na spravované nebudou šířit zpět aktualizovaný výsledek, a to ani v případě, že VARIANT je varianta VT_BYREF. K šíření aktualizované hodnoty zpět k volajícímu použijte místo parametru in parametr ref.
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 bdfd8aee1ec7bf..53cb0d55460ae4 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
@@ -507,11 +507,6 @@
Die [In]- und [Out]-Attribute werden nur für Arrayparameter unterstützt. Erwägen Sie die Verwendung des Schlüsselworts "ref", damit der Parameter geändert werden kann.
-
- [In] and [Out] attributes
- [In]- und [Out]-Attribute
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Objekte, die aus VARIANTEN als in-Parameter in nicht verwalteten Aufrufen gemarshallt werden, werden nicht an das aktualisierte Ergebnis verteilt, auch wenn VARIANTE eine VT_BYREF-Variante ist. Verwenden Sie einen ref-Parameter anstelle eines in-Parameters, um den aktualisierten Wert wieder an den Aufrufer zu übergeben.
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 6949c57d1513fe..8713dc791cfa16 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
@@ -507,11 +507,6 @@
Los atributos "[In]" y "[Out]" solo se admiten en parámetros de matriz. Considere la posibilidad de usar la palabra clave "ref" para hacer que el parámetro sea mutable.
-
- [In] and [Out] attributes
- Atributos [In] y [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Los objetos serializados a partir de VARIANTES como parámetros 'in' en llamadas no administradas a administradas no propagarán el resultado actualizado, incluso si VARIANTE es una variante VT_BYREF. Use un parámetro 'ref' en lugar de un parámetro 'in' para volver a propagar el valor actualizado al llamador.
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 b4df96b4d24f6b..1165260548a782 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
@@ -507,11 +507,6 @@
Les attributs '[In]' et '[Out]' ne sont pris en charge que sur les paramètres de tableau. Pensez à utiliser le mot-clé 'ref' pour rendre le paramètre mutable.
-
- [In] and [Out] attributes
- Attributs [In] et [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Les objets marshallés à partir de VARIANT en tant que paramètres « in » dans les appels non gérés à gérés ne propageront pas le résultat mis à jour, même si le VARIANT est une variante de VT_BYREF. Utilisez un paramètre « ref » au lieu d’un paramètre « in » pour propager la valeur mise à jour à l’appelant.
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 eb201d34ef39ff..3f779609359b97 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
@@ -507,11 +507,6 @@
Gli attributi [In]' e '[Out]' sono supportati solo nei parametri di matrice. Provare a usare le parole chiave 'ref' per rendere modificabile il parametro.
-
- [In] and [Out] attributes
- Attributi [In] e [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Gli oggetti di cui è stato eseguito il marshalling da VARIANT come parametri 'in' nelle chiamate da non gestito a gestito non verranno propagati nuovamente al risultato aggiornato, anche se VARIANT è una variante VT_BYREF. Usare un parametro 'ref' invece di un parametro 'in' per propagare nuovamente il valore aggiornato al chiamante.
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 e36ce66ee7c9bc..f25a9d047b2a2a 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
@@ -507,11 +507,6 @@
'[In]' および '[Out]' 属性は、配列パラメーターでのみサポートされます。パラメーターを変更可能にするには、'ref' キーワードを使用することを検討してください。
-
- [In] and [Out] attributes
- 属性の[In]と[Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.アンマネージからマネージドへの呼び出しで VARIANT から 'in' パラメーターとしてマーシャリングされたオブジェクトは、VARIANT が VT_BYREF バリアントであっても、更新された結果に反映されません。更新された値を呼び出し元に反映するには、'in' パラメーターの代わりに 'ref' パラメーターを使用してください。
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 1699af9d6f5ac1..fc87773aa89cc8 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
@@ -507,11 +507,6 @@
'[In]' 및 '[Out]' 특성은 배열 매개 변수에서만 지원됩니다. 매개 변수를 변경 가능하게 만들려면 'ref' 키워드를 사용하는 것이 좋습니다.
-
- [In] and [Out] attributes
- [In] 및 [Out] 속성
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.관리되지 않는 호출에서 관리되는 호출로의 VARIANT에서 'in' 매개 변수로 마샬링된 개체는 VARIANT가 VT_BYREF 변형인 경우에도 업데이트된 결과를 다시 전파하지 않습니다. 'in' 매개 변수 대신 'ref' 매개 변수를 사용하여 업데이트된 값을 호출자에게 다시 전파합니다.
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 aeaf8022c4fe82..65deb350d9cc50 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
@@ -507,11 +507,6 @@
Atrybuty „[In]” i „[Out]” są obsługiwane tylko w przypadku parametrów tablicy. Rozważ użycie słowa kluczowego „ref”, aby umożliwić modyfikowanie parametru.
-
- [In] and [Out] attributes
- Atrybuty [In] i [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Obiekty przekazywane z obiektów VARIANT jako parametry „w” w wywołaniach niezarządzanych do zarządzanych nie będą propagować z powrotem zaktualizowanego wyniku, nawet jeśli parametr VARIANT jest wariantem VT_BYREF. Użyj parametru „ref” zamiast parametru „w”, aby propagować zaktualizowaną wartość z powrotem do obiektu wywołującego.
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 4d81c5beee2c1e..9231a0ab0ff454 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
@@ -507,11 +507,6 @@
Os atributos '[In]' e '[Out]' só têm suporte nos parâmetros de matriz. Considere usar a palavra-chave 'ref' para tornar o parâmetro mutável.
-
- [In] and [Out] attributes
- Atributos [In] e [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Objetos marshalled de VARIANTs como parâmetros "in" em chamadas não gerenciadas para gerenciadas não propagam de volta o resultado atualizado, mesmo que VARIANT seja uma variante VT_BYREF. Use um parâmetro "ref" em vez de um parâmetro "in" para propagar o valor atualizado de volta para o chamador.
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 8ff2566fb34986..b9dd1ec12ba5df 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
@@ -507,11 +507,6 @@
Атрибуты "[In]" и "[Out]" поддерживаются только для параметров массива. Рассмотрите возможность использования ключевого слова "ref", чтобы сделать параметр изменяемым.
-
- [In] and [Out] attributes
- Атрибуты [In] и [Out]
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Объекты, маршалированные из VARIANT в качестве параметров "in" в вызовах с переходом от неуправляемых к управляемым, не будут распространяться обратно на обновленный результат, даже если VARIANT является вариантом VT_BYREF. Используйте параметр "ref" вместо параметра "in", чтобы распространить обновленное значение обратно на вызывающую сторону.
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 49b5dce9f93459..29428f380d0340 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
@@ -507,11 +507,6 @@
'[In]' ve '[Out]' öznitelikleri yalnızca dizi parametrelerinde desteklenir. Parametreyi değiştirilebilir yapmak için 'ref' anahtar sözcüğünü kullanmayı düşünün.
-
- [In] and [Out] attributes
- [In] ve [Out] öznitelikleri
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.Yönetilmeyenden yönetilene yapılan çağrılarda 'in' parametresi olarak kullanılan VARIANT'lardan hazırlanma işlemiyle elde edilen nesneler, VARIANT çeşidi VT_BYREF olsa bile güncelleştirilmiş sonucu geri yaymaz. Güncelleştirilmiş değeri çağırana geri yayma için 'in' parametresi yerine bir 'ref' parametresi kullanın.
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 d88eb2fcf95f5e..b8a161ed2914e8 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
@@ -507,11 +507,6 @@
“[In]”和“[Out]”属性仅在数组参数上受支持。请考虑使用“ref”关键字使参数可变。
-
- [In] and [Out] attributes
- [In] 和 [Out] 属性
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.在非托管到托管调用中从 VARIANT 封送为“in”参数的对象不会传回更新后的结果,即使 VARIANT 是 VT_BYREF 变量也是如此。使用 "ref "参数代替 "in "参数,将更新后的值传回调用方。
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 be8453ca5e1396..a92d6a7aaa8979 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
@@ -507,11 +507,6 @@
只有在陣列參數上才支援 '[In]' 和 '[Out]' 屬性。請考慮使用 'ref' 關鍵字,讓參數成為可變動。
-
- [In] and [Out] attributes
- [In] 與 [Out] 屬性
-
- Objects marshalled from VARIANTs as 'in' parameters in unmanaged-to-managed calls will not propagate back the updated result, even if the VARIANT is a VT_BYREF variant. Use a 'ref' parameter instead of an 'in' parameter to propagate the updated value back to the caller.在未受控對受控呼叫中,從 VARIANT 封送處理為 'in' 參數的物件將不會傳播回更新的結果,即使 VARIANT 是 VT_BYREF 變數亦然。使用 'ref' 參數而非 'in' 參數,以將更新的值傳播回呼叫者。
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportDiagnosticsAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportDiagnosticsAnalyzer.cs
index b984252ea87f77..64cc64aaa57796 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportDiagnosticsAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportDiagnosticsAnalyzer.cs
@@ -216,7 +216,7 @@ private static ImmutableArray CalculateDiagnostics(
signatureContext.ElementTypeInformation,
LibraryImportData.From(libraryImportData).SetLastError,
generatorDiagnostics,
- DownlevelLibraryImportGeneratorHelpers.GeneratorResolver,
+ new ByValueContentsMarshalKindValidator(DownlevelLibraryImportGeneratorHelpers.GeneratorResolver),
new CodeEmitOptions(SkipInit: false));
// Check if a forwarder stub would be generated and if so, report CannotForwardToDllImport for invalid StringMarshalling
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportGeneratorHelpers.cs b/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportGeneratorHelpers.cs
index 3ae03a53e6ce08..e8834e6440b389 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportGeneratorHelpers.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DownlevelLibraryImportGenerator/DownlevelLibraryImportGeneratorHelpers.cs
@@ -45,13 +45,13 @@ public static MarshallingInfoParser CreateMarshallingInfoParser(StubEnvironment
new BlittableTypeMarshallingInfoProvider(env.Compilation)));
}
- public static IMarshallingGeneratorResolver GeneratorResolver { get; } = new ByValueContentsMarshalKindValidator(new CompositeMarshallingGeneratorResolver(
+ public static IMarshallingGeneratorResolver GeneratorResolver { get; } = new CompositeMarshallingGeneratorResolver(
[
new BlittableMarshallerResolver(runtimeMarshallingDisabled: false),
new MarshalAsMarshallingGeneratorResolver(new InteropGenerationOptions(UseMarshalType: true)),
new NoMarshallingInfoErrorResolver(TypeNames.LibraryImportAttribute_ShortName),
new CharMarshallingGeneratorResolver(useBlittableMarshallerForUtf16: false, TypeNames.LibraryImportAttribute_ShortName),
new ForwarderResolver()
- ]));
+ ]);
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs
index 9d0d19bab2bc68..b552d3621421c8 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/ConvertToLibraryImportAnalyzer.cs
@@ -147,7 +147,7 @@ private static bool IsEligibleDllImport(
new CodeEmitOptions(SkipInit: true),
typeof(ConvertToLibraryImportAnalyzer).Assembly);
- var factory = DefaultMarshallingGeneratorResolver.Create(env.EnvironmentFlags, MarshalDirection.ManagedToUnmanaged, TypeNames.LibraryImportAttribute_ShortName, []);
+ var factory = new ByValueContentsMarshalKindValidator(DefaultMarshallingGeneratorResolver.Create(env.EnvironmentFlags, MarshalDirection.ManagedToUnmanaged, TypeNames.LibraryImportAttribute_ShortName, []));
mayRequireAdditionalWork = diagnostics.Diagnostics.Any();
bool anyExplicitlyUnsupportedInfo = false;
diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
index 7ec8b43548414e..b1f751cf5935b2 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/Analyzers/LibraryImportDiagnosticsAnalyzer.cs
@@ -216,11 +216,11 @@ private static ImmutableArray CalculateDiagnostics(
// If forwarders are not being generated, we need to run stub generation logic to get those diagnostics too
if (!options.GenerateForwarders)
{
- IMarshallingGeneratorResolver resolver = DefaultMarshallingGeneratorResolver.Create(
+ IMarshallingGeneratorResolver resolver = new ByValueContentsMarshalKindValidator(DefaultMarshallingGeneratorResolver.Create(
environment.EnvironmentFlags,
MarshalDirection.ManagedToUnmanaged,
TypeNames.LibraryImportAttribute_ShortName,
- []);
+ []));
// Check marshalling generators - this collects diagnostics for marshalling issues
_ = new ManagedToNativeStubGenerator(
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 0f3b07fadf7d2e..26ca5b53962624 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
@@ -40,7 +40,6 @@ private static ResolvedGenerator ValidateByValueMarshalKind(ResolvedGenerator ge
{
ByValueMarshalKindSupport.Supported => generator,
ByValueMarshalKindSupport.NotSupported => ResolvedGenerator.ResolvedWithDiagnostics(s_forwarder.Bind(generator.Generator.TypeInfo, context), 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 d8aab60196a107..eaf485039a6fe6 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
@@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Collections.Immutable;
using System.Diagnostics;
namespace Microsoft.Interop
@@ -19,14 +18,6 @@ public ByValueMarshalKindSupport GetSupport(TypePositionInfo info, out Generator
{
Details = details
},
- ByValueMarshalKindSupport.Unnecessary =>
- new GeneratorDiagnostic.UnnecessaryData(
- info,
- ImmutableArray.Create(info.ByValueMarshalAttributeLocations.OutLocation))
- {
- UnnecessaryDataName = SR.InOutAttributes,
- UnnecessaryDataDetails = details
- },
ByValueMarshalKindSupport.NotSupported =>
new GeneratorDiagnostic.NotSupported(info)
{
@@ -48,7 +39,7 @@ public record ByValueMarshalKindSupportDescriptor(
ByValueMarshalKindSupportInfo InOutSupport)
{
///
- /// A default for by value parameters. [In] is allowed, but unnecessary. Out is not allowed.
+ /// A default for by value parameters. [In] and [Out] are not allowed.
///
public static readonly ByValueMarshalKindSupportDescriptor Default = new ByValueMarshalKindSupportDescriptor(
DefaultSupport: new(ByValueMarshalKindSupport.Supported, null),
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DefaultMarshallingGeneratorResolver.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DefaultMarshallingGeneratorResolver.cs
index 68efe7aaae7dbe..bb49ecb2d52086 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DefaultMarshallingGeneratorResolver.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/DefaultMarshallingGeneratorResolver.cs
@@ -51,30 +51,29 @@ public static IMarshallingGeneratorResolver Create(
MarshalMode.ElementOut,
ResolveElementsFromSelf: true));
- IMarshallingGeneratorResolver generatorResolver = new ByValueContentsMarshalKindValidator(
- new CompositeMarshallingGeneratorResolver(
- [
- .. coreResolvers,
- new AttributedMarshallingModelGeneratorResolver(
- new CompositeMarshallingGeneratorResolver(
- [elementFactory, .. coreResolvers, charElementMarshaller, fallbackResolver]),
- new AttributedMarshallingModelOptions(
- env.HasFlag(EnvironmentFlags.DisableRuntimeMarshalling),
- direction == MarshalDirection.ManagedToUnmanaged
- ? MarshalMode.ManagedToUnmanagedIn
- : MarshalMode.UnmanagedToManagedOut,
- direction == MarshalDirection.ManagedToUnmanaged
- ? MarshalMode.ManagedToUnmanagedRef
- : MarshalMode.UnmanagedToManagedRef,
- direction == MarshalDirection.ManagedToUnmanaged
- ? MarshalMode.ManagedToUnmanagedOut
- : MarshalMode.UnmanagedToManagedIn,
- ResolveElementsFromSelf: false)),
- // Since the char type can go into the P/Invoke signature here, we can only use it when
- // runtime marshalling is disabled.
- new CharMarshallingGeneratorResolver(useBlittableMarshallerForUtf16: env.HasFlag(EnvironmentFlags.DisableRuntimeMarshalling), stringMarshallingAttribute),
- fallbackResolver
- ]));
+ IMarshallingGeneratorResolver generatorResolver = new CompositeMarshallingGeneratorResolver(
+ [
+ .. coreResolvers,
+ new AttributedMarshallingModelGeneratorResolver(
+ new CompositeMarshallingGeneratorResolver(
+ [elementFactory, .. coreResolvers, charElementMarshaller, fallbackResolver]),
+ new AttributedMarshallingModelOptions(
+ env.HasFlag(EnvironmentFlags.DisableRuntimeMarshalling),
+ direction == MarshalDirection.ManagedToUnmanaged
+ ? MarshalMode.ManagedToUnmanagedIn
+ : MarshalMode.UnmanagedToManagedOut,
+ direction == MarshalDirection.ManagedToUnmanaged
+ ? MarshalMode.ManagedToUnmanagedRef
+ : MarshalMode.UnmanagedToManagedRef,
+ direction == MarshalDirection.ManagedToUnmanaged
+ ? MarshalMode.ManagedToUnmanagedOut
+ : MarshalMode.UnmanagedToManagedIn,
+ ResolveElementsFromSelf: false)),
+ // Since the char type can go into the P/Invoke signature here, we can only use it when
+ // runtime marshalling is disabled.
+ new CharMarshallingGeneratorResolver(useBlittableMarshallerForUtf16: env.HasFlag(EnvironmentFlags.DisableRuntimeMarshalling), stringMarshallingAttribute),
+ fallbackResolver
+ ]);
generatorResolver = new BreakingChangeDetector(generatorResolver);
return generatorResolver;
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 fad741c769ce48..bea30ef0949999 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
@@ -68,10 +68,6 @@ public enum ByValueMarshalKindSupport
///
NotSupported,
///
- /// 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/TypePositionInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs
index 14fa3a62d559ab..3e374ad827aefc 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs
@@ -70,8 +70,6 @@ public static int IncrementIndex(int index)
public ByValueContentsMarshalKind ByValueContentsMarshalKind { get; init; }
- public (Location? InLocation, Location? OutLocation) ByValueMarshalAttributeLocations { get; init; }
-
public bool IsManagedReturnPosition { get => ManagedIndex == ReturnIndex; }
public bool IsNativeReturnPosition { get => NativeIndex == ReturnIndex; }
public bool IsManagedExceptionPosition { get => ManagedIndex == ExceptionIndex; }
@@ -87,14 +85,11 @@ public bool PositionsEqual(TypePositionInfo other)
public static TypePositionInfo CreateForParameter(IParameterSymbol paramSymbol, MarshallingInfo marshallingInfo, Compilation compilation)
{
- var (byValueContentsMarshalKind, inLocation, outLocation) = GetByValueContentsMarshalKind(paramSymbol.GetAttributes(), compilation);
-
var typeInfo = new TypePositionInfo(ManagedTypeInfo.CreateTypeInfoForTypeSymbol(paramSymbol.Type), marshallingInfo)
{
InstanceIdentifier = ParseToken(paramSymbol.Name).IsReservedKeyword() ? $"@{paramSymbol.Name}" : paramSymbol.Name,
RefKind = paramSymbol.RefKind,
- ByValueContentsMarshalKind = byValueContentsMarshalKind,
- ByValueMarshalAttributeLocations = (inLocation, outLocation),
+ ByValueContentsMarshalKind = GetByValueContentsMarshalKind(paramSymbol.GetAttributes(), compilation),
ScopedKind = paramSymbol.ScopedKind,
IsExplicitThis = ((ParameterSyntax?)paramSymbol.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax())?.Modifiers.Any(SyntaxKind.ThisKeyword) ?? false
};
@@ -113,30 +108,26 @@ public static Location GetLocation(TypePositionInfo info, IMethodSymbol methodSy
return methodSymbol.Parameters[info.ManagedIndex].Locations[0];
}
- private static (ByValueContentsMarshalKind, Location? inAttribute, Location? outAttribute) GetByValueContentsMarshalKind(IEnumerable attributes, Compilation compilation)
+ private static ByValueContentsMarshalKind GetByValueContentsMarshalKind(IEnumerable attributes, Compilation compilation)
{
INamedTypeSymbol outAttributeType = compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_OutAttribute)!;
INamedTypeSymbol inAttributeType = compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_InAttribute)!;
ByValueContentsMarshalKind marshalKind = ByValueContentsMarshalKind.Default;
- Location? inAttributeLocation = null;
- Location? outAttributeLocation = null;
foreach (AttributeData attr in attributes)
{
if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, outAttributeType))
{
marshalKind |= ByValueContentsMarshalKind.Out;
- outAttributeLocation = attr.ApplicationSyntaxReference.SyntaxTree.GetLocation(attr.ApplicationSyntaxReference.Span);
}
else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, inAttributeType))
{
marshalKind |= ByValueContentsMarshalKind.In;
- inAttributeLocation = attr.ApplicationSyntaxReference.SyntaxTree.GetLocation(attr.ApplicationSyntaxReference.Span);
}
}
- return (marshalKind, inAttributeLocation, outAttributeLocation);
+ return marshalKind;
}
}
}