diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs index b8824c7d073a54..9a5f2354bb0661 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComClassGenerator.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.Interop { @@ -18,15 +18,34 @@ public class ComClassGenerator : IIncrementalGenerator private sealed record ComClassInfo(string ClassName, ContainingSyntaxContext ContainingSyntaxContext, ContainingSyntax ClassSyntax, SequenceEqualImmutableArray ImplementedInterfacesNames); public void Initialize(IncrementalGeneratorInitializationContext context) { + var unsafeCodeIsEnabled = context.CompilationProvider.Select((comp, ct) => comp.Options is CSharpCompilationOptions { AllowUnsafe: true }); // Unsafe code enabled // Get all types with the [GeneratedComClassAttribute] attribute. - var attributedClasses = context.SyntaxProvider + var attributedClassesOrDiagnostics = context.SyntaxProvider .ForAttributeWithMetadataName( TypeNames.GeneratedComClassAttribute, static (node, ct) => node is ClassDeclarationSyntax, - static (context, ct) => + static (context, ct) => context) + .Combine(unsafeCodeIsEnabled) + .Select((data, ct) => { + var context = data.Left; + var unsafeCodeIsEnabled = data.Right; var type = (INamedTypeSymbol)context.TargetSymbol; var syntax = (ClassDeclarationSyntax)context.TargetNode; + if (!unsafeCodeIsEnabled) + { + return DiagnosticOr.From(DiagnosticInfo.Create(GeneratorDiagnostics.RequiresAllowUnsafeBlocks, syntax.Identifier.GetLocation())); + } + + if (!syntax.IsInPartialContext(out _)) + { + return DiagnosticOr.From( + DiagnosticInfo.Create( + GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier, + syntax.Identifier.GetLocation(), + type.ToDisplayString())); + } + ImmutableArray.Builder names = ImmutableArray.CreateBuilder(); foreach (INamedTypeSymbol iface in type.AllInterfaces) { @@ -35,13 +54,25 @@ public void Initialize(IncrementalGeneratorInitializationContext context) names.Add(iface.ToDisplayString()); } } - return new ComClassInfo( - type.ToDisplayString(), - new ContainingSyntaxContext(syntax), - new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList), - new(names.ToImmutable())); + + if (names.Count == 0) + { + return DiagnosticOr.From(DiagnosticInfo.Create(GeneratorDiagnostics.ClassDoesNotImplementAnyGeneratedComInterface, + syntax.Identifier.GetLocation(), + type.ToDisplayString())); + } + + + return DiagnosticOr.From( + new ComClassInfo( + type.ToDisplayString(), + new ContainingSyntaxContext(syntax), + new ContainingSyntax(syntax.Modifiers, syntax.Kind(), syntax.Identifier, syntax.TypeParameterList), + new(names.ToImmutable()))); }); + var attributedClasses = context.FilterAndReportDiagnostics(attributedClassesOrDiagnostics); + var className = attributedClasses.Select(static (info, ct) => info.ClassName); var classInfoType = attributedClasses diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs index b7314b78ccd467..3d475114ae4008 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/ComInterfaceInfo.cs @@ -3,7 +3,6 @@ using System; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -68,17 +67,14 @@ public static DiagnosticOrInterfaceInfo From(INamedTypeSymbol symbol, InterfaceD private static bool IsInPartialContext(INamedTypeSymbol symbol, InterfaceDeclarationSyntax syntax, [NotNullWhen(false)] out DiagnosticInfo? diagnostic) { // Verify that the types the interface is declared in are marked partial. - for (SyntaxNode? parentNode = syntax; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent) + if (!syntax.IsInPartialContext(out var nonPartialIdentifier)) { - if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword)) - { - diagnostic = DiagnosticInfo.Create( - GeneratorDiagnostics.InvalidAttributedInterfaceMissingPartialModifiers, - syntax.Identifier.GetLocation(), - symbol.Name, - typeDecl.Identifier); - return false; - } + diagnostic = DiagnosticInfo.Create( + GeneratorDiagnostics.InvalidAttributedInterfaceMissingPartialModifiers, + syntax.Identifier.GetLocation(), + symbol.Name, + nonPartialIdentifier); + return false; } diagnostic = null; return true; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs index d40f7a2bd24f61..fcf3fc4366360a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/GeneratorDiagnostics.cs @@ -31,6 +31,7 @@ public class Ids private const string Category = "ComInterfaceGenerator"; + /// public static readonly DiagnosticDescriptor RequiresAllowUnsafeBlocks = new DiagnosticDescriptor( Ids.RequiresAllowUnsafeBlocks, @@ -327,6 +328,18 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(SR.InterfaceTypeNotSupportedMessage))); + /// + public static readonly DiagnosticDescriptor ClassDoesNotImplementAnyGeneratedComInterface = + new DiagnosticDescriptor( + Ids.InvalidGeneratedComClassAttributeUsage, + GetResourceString(nameof(SR.InvalidGeneratedComClassAttributeUsageTitle)), + GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesMessage)), + Category, + DiagnosticSeverity.Warning, + isEnabledByDefault: true, + description: GetResourceString(nameof(SR.ClassDoesNotImplementAnyGeneratedComInterfacesDescription))); + + private readonly List _diagnostics = new List(); public IEnumerable Diagnostics => _diagnostics; diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx index 46df1163425b45..9dd5a808d359b1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/Strings.resx @@ -1,17 +1,17 @@  - @@ -268,13 +268,13 @@ The configuration of 'StringMarshalling' and 'StringMarshallingCustomType' on interface '{0}' is invalid. {1} - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. The interface '{0}' or one of its containing types is missing the 'partial' keyword. Code will not be generated for '{0}'. @@ -283,7 +283,7 @@ Classes with 'GeneratedComClassAttribute' must implement one or more interfaces with 'GeneratedComInterfaceAttribute', be marked partial, and be non-generic. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. Invalid 'GeneratedComClassAttribute' usage @@ -336,6 +336,12 @@ Converting this interface to use 'GeneratedComInterfaceAttribute' may produce invalid code and may require additional work + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime @@ -345,4 +351,4 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported - \ No newline at end of file + diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf index c38a0fc3436e48..bee983c300c659 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.cs.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf index 39f481a34a716c..7d38c2e51d2771 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.de.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf index a93456771d42f3..199af8fe579c7c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.es.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf index a51c404a3fbffd..b4e97ca8b8f7d1 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.fr.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf index 2470a2d7e33932..acd2ab2a7cf851 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.it.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf index 94a2cb0b1949d0..589ddd3d4601e6 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ja.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf index 76d63efdd02a57..d2d0ca06f64a5d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ko.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf index f36f6b3d5925b6..1812e5c9a2016c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pl.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf index 7225bb3e58c7a6..09b6638c905dca 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.pt-BR.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf index 8c98a4e369e225..8d54b20b21ad3f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.ru.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf index 27f831df4f5438..b34d9e6681902f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.tr.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf index 8cd7d5a4f9e72e..01827c255c3cba 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hans.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf index 7ccf2a31055df9..2ed579cfef9e34 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/libraries/System.Runtime.InteropServices/gen/ComInterfaceGenerator/Resources/xlf/Strings.zh-Hant.xlf @@ -72,6 +72,16 @@ Casting between a 'ComImport' type and a source-generated COM type is not supported + + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + A class with 'GeneratedComClassAttribute' must implement at least one interface with 'GeneratedComInterfaceAttribute' or else the generated code with not have an effect. + + + + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + Class '{0}' with 'GeneratedComClassAttribute' does not implement any interfaces with 'GeneratedComInterfaceAttribute'. Source will not be generated for '{0}'. + + .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. .NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'. @@ -218,8 +228,8 @@ - Class '{0}' or one of its containing types is not marked 'partial'. - Class '{0}' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. + Class '{0}' with 'GeneratedComClassAttribute' or one of its containing types is not marked 'partial'. @@ -313,18 +323,18 @@ - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. Project must be updated with '<AllowUnsafeBlocks>true</AllowUnsafeBlocks>'. - GeneratedComInterfaceAttribute requires unsafe code. - GeneratedComInterfaceAttribute requires unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. + 'GeneratedComInterfaceAttribute' and 'GeneratedComClassAttribute' require unsafe code. diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs index 2da767bb0d3968..0018d92e7f532c 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs @@ -528,12 +528,9 @@ static ExpressionSyntax CreateEnumExpressionSyntax(T value) where T : Enum } // Verify that the types the method is declared in are marked partial. - for (SyntaxNode? parentNode = methodSyntax.Parent; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent) + if (methodSyntax.Parent is TypeDeclarationSyntax typeDecl && !typeDecl.IsInPartialContext(out var nonPartialIdentifier)) { - if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword)) - { - return DiagnosticInfo.Create(GeneratorDiagnostics.InvalidAttributedMethodContainingTypeMissingModifiers, methodSyntax.Identifier.GetLocation(), method.Name, typeDecl.Identifier); - } + return DiagnosticInfo.Create(GeneratorDiagnostics.InvalidAttributedMethodContainingTypeMissingModifiers, methodSyntax.Identifier.GetLocation(), method.Name, nonPartialIdentifier); } // Verify the method does not have a ref return diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SyntaxExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SyntaxExtensions.cs index c314a635179822..1955c84ceae156 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SyntaxExtensions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/SyntaxExtensions.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Text; +using System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -83,7 +83,7 @@ public static SyntaxTokenList StripTriviaFromTokens(this SyntaxTokenList tokenLi public static SyntaxTokenList StripAccessibilityModifiers(this SyntaxTokenList tokenList) { - List strippedTokens = new (); + List strippedTokens = new(); for (int i = 0; i < tokenList.Count; i++) { if (tokenList[i].Kind() is SyntaxKind.PublicKeyword or SyntaxKind.InternalKeyword or SyntaxKind.ProtectedKeyword or SyntaxKind.PrivateKeyword) @@ -105,5 +105,19 @@ public static SyntaxTokenList AddToModifiers(this SyntaxTokenList modifiers, Syn ? modifiers.Insert(idx, SyntaxFactory.Token(modifierToAdd)) : modifiers.Add(SyntaxFactory.Token(modifierToAdd)); } + + public static bool IsInPartialContext(this TypeDeclarationSyntax syntax, [NotNullWhen(false)] out SyntaxToken? nonPartialIdentifier) + { + for (SyntaxNode? parentNode = syntax; parentNode is TypeDeclarationSyntax typeDecl; parentNode = parentNode.Parent) + { + if (!typeDecl.Modifiers.Any(SyntaxKind.PartialKeyword)) + { + nonPartialIdentifier = typeDecl.Identifier; + return false; + } + } + nonPartialIdentifier = null; + return true; + } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/IDerivedTests.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/IDerivedTests.cs index 68c7420d0b3cbc..e457a287748bc3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/IDerivedTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Tests/IDerivedTests.cs @@ -2,13 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; -using System.Text; -using System.Threading.Tasks; using SharedTypes.ComInterfaces; using Xunit; diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorDiagnostics.cs new file mode 100644 index 00000000000000..13d63a83333e2d --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComClassGeneratorDiagnostics.cs @@ -0,0 +1,129 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Testing; +using Microsoft.Interop; +using Xunit; +using VerifyCS = Microsoft.Interop.UnitTests.Verifiers.CSharpSourceGeneratorVerifier; + +namespace ComInterfaceGenerator.Unit.Tests +{ + public class ComClassGeneratorDiagnostics + { + [Fact] + public async Task NonPartialClassWarns() + { + string source = """ + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + [GeneratedComInterface] + partial interface INativeAPI + { + } + + [GeneratedComClass] + internal class {|#0:C|} : INativeAPI {} + + """; + + await VerifyCS.VerifySourceGeneratorAsync( + source, + new DiagnosticResult(GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier) + .WithLocation(0) + .WithArguments("C")); + } + + [Fact] + public async Task NonPartialContainingTypeWarns() + { + string source = """ + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + public class Test + { + [GeneratedComInterface] + partial interface INativeAPI + { + } + + [GeneratedComClass] + internal partial class {|#0:C|} : INativeAPI {} + } + + """; + + await VerifyCS.VerifySourceGeneratorAsync( + source, + new DiagnosticResult(GeneratorDiagnostics.InvalidAttributedClassMissingPartialModifier) + .WithLocation(0) + .WithArguments("Test.C")); + } + + internal class UnsafeBlocksNotAllowedTest : VerifyCS.Test + { + internal UnsafeBlocksNotAllowedTest(bool referenceAncillaryInterop) : base(referenceAncillaryInterop) { } + protected override CompilationOptions CreateCompilationOptions() + => new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: false); + } + + [Fact] + public async Task UnsafeCodeNotEnabledWarns() + { + string source = """ + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + public partial class Test + { + [GeneratedComInterface] + internal partial interface INativeAPI + { + } + + [GeneratedComClass] + internal partial class {|#0:C|} : INativeAPI {} + } + + """; + + var test = new UnsafeBlocksNotAllowedTest(false); + test.TestState.Sources.Add(source); + test.ExpectedDiagnostics.Add( + new DiagnosticResult(GeneratorDiagnostics.RequiresAllowUnsafeBlocks) + .WithLocation(0) + .WithArguments("Test.C")); + + await test.RunAsync(); + } + + [Fact] + public async Task ClassThatDoesNotInheritFromGeneratedInterfaceWarns() + { + string source = """ + using System.Runtime.InteropServices; + using System.Runtime.InteropServices.Marshalling; + + public partial class Test{ + internal interface INativeAPI + { + } + + [GeneratedComClass] + internal partial class {|#0:C|} : INativeAPI {} + } + + """; + + await VerifyCS.VerifySourceGeneratorAsync( + source, + new DiagnosticResult(GeneratorDiagnostics.ClassDoesNotImplementAnyGeneratedComInterface) + .WithLocation(0) + .WithArguments("Test.C")); + } + } +} diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IPointProvider.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IPointProvider.cs index 00fa753715ca27..a3d91318e5d146 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IPointProvider.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/ComInterfaces/IPointProvider.cs @@ -2,13 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.Drawing; -using System.Linq; using System.Runtime.InteropServices; using System.Runtime.InteropServices.Marshalling; -using System.Text; -using System.Threading.Tasks; namespace SharedTypes.ComInterfaces {