Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Ids
public const string ConvertToGeneratedComInterface = Prefix + "1096";
public const string AddGeneratedComClassAttribute = Prefix + "1097";
public const string ComHostingDoesNotSupportGeneratedComInterface = Prefix + "1098";
public const string RuntimeComApisDoNotSupportSourceGeneratedCom = Prefix + "1099";
public const string RuntimeComAndGeneratedComDoNotMix = Prefix + "1099";
}

public static class Metadata
Expand Down Expand Up @@ -61,12 +61,22 @@ private static LocalizableResourceString GetResourceString(string resourceName)

public static readonly DiagnosticDescriptor RuntimeComApisDoNotSupportSourceGeneratedCom =
new DiagnosticDescriptor(
Ids.RuntimeComApisDoNotSupportSourceGeneratedCom,
Ids.RuntimeComAndGeneratedComDoNotMix,
GetResourceString(nameof(SR.RuntimeComApisDoNotSupportSourceGeneratedComTitle)),
GetResourceString(nameof(SR.RuntimeComApisDoNotSupportSourceGeneratedComMessage)),
Category,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.RuntimeComApisDoNotSupportSourceGeneratedComDescription)));

public static readonly DiagnosticDescriptor CastsBetweenRuntimeComAndSourceGeneratedComNotSupported =
new DiagnosticDescriptor(
Ids.RuntimeComAndGeneratedComDoNotMix,
GetResourceString(nameof(SR.CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle)),
GetResourceString(nameof(SR.CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage)),
Category,
DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: GetResourceString(nameof(SR.CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Microsoft.Interop.Analyzers
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class RuntimeComApiUsageWithSourceGeneratedComAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(RuntimeComApisDoNotSupportSourceGeneratedCom);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(RuntimeComApisDoNotSupportSourceGeneratedCom, CastsBetweenRuntimeComAndSourceGeneratedComNotSupported);

public override void Initialize(AnalysisContext context)
{
Expand Down Expand Up @@ -130,6 +130,60 @@ public override void Initialize(AnalysisContext context)
}
}, OperationKind.Invocation);

var getObjectForIUnknown = marshalType.GetMembers("GetObjectForIUnknown")[0];

context.RegisterOperationAction(context =>
{
var operation = (IConversionOperation)context.Operation;
if (operation.Type is INamedTypeSymbol { IsComImport: true })
{
IOperation operand = operation.Operand;
if (operand is IConversionOperation { Type.SpecialType: SpecialType.System_Object } objConversion)
{
operand = objConversion.Operand;
}
foreach (var recognizer in sourceGeneratedComRecognizers)
{
if (recognizer(operand.Type))
{
context.ReportDiagnostic(
Diagnostic.Create(
CastsBetweenRuntimeComAndSourceGeneratedComNotSupported,
operation.Syntax.GetLocation()));
break;
}
}
}

foreach (var recognizer in sourceGeneratedComRecognizers)
{
if (recognizer(operation.Type))
{
IOperation operand = operation.Operand;
if (operand is IConversionOperation { Type.SpecialType: SpecialType.System_Object } objConversion)
{
operand = objConversion.Operand;
}
if (operand.Type is INamedTypeSymbol { IsComImport: true })
{
context.ReportDiagnostic(
Diagnostic.Create(
CastsBetweenRuntimeComAndSourceGeneratedComNotSupported,
operation.Syntax.GetLocation()));
break;
}
else if (operand is IInvocationOperation invocation && invocation.TargetMethod.Equals(getObjectForIUnknown, SymbolEqualityComparer.Default))
{
context.ReportDiagnostic(
Diagnostic.Create(
CastsBetweenRuntimeComAndSourceGeneratedComNotSupported,
operation.Syntax.GetLocation()));
break;
}
}
}
}, OperationKind.Conversion);

static Func<IInvocationOperation, (ITypeSymbol Type, Location location)?> CreateArgumentTypeLookup(int ordinal) => invocation => invocation.GetArgumentByOrdinal(ordinal).Value switch
{
IConversionOperation conversion => (conversion.Operand.Type, conversion.Operand.Syntax.GetLocation()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -327,4 +327,13 @@
<data name="ConvertComInterfaceMayProduceInvalidCode" xml:space="preserve">
<value>Converting this interface to use 'GeneratedComInterfaceAttribute' may produce invalid code and may require additional work</value>
</data>
</root>
<data name="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription" xml:space="preserve">
<value>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</value>
</data>
<data name="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage" xml:space="preserve">
<value>Casting between a 'ComImport' type and a source-generated COM type is not supported</value>
</data>
<data name="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle" xml:space="preserve">
<value>Casting between a 'ComImport' type and a source-generated COM type is not supported</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<target state="needs-review-translation">Základnímu rozhraní COM se nepodařilo vygenerovat zdroj. ComInterfaceGenerator nevygeneruje zdroj pro toto rozhraní.</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<target state="needs-review-translation">Die Basis-COM-Schnittstelle konnte die Quelle nicht generieren. ComInterfaceGenerator generiert keine Quelle für diese Schnittstelle.</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<target state="needs-review-translation">La interfaz COM base no pudo generar el origen. ComInterfaceGenerator no generará el origen para esta interfaz.</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<target state="needs-review-translation">L’interface COM de base n’a pas pu générer la source. ComInterfaceGenerator ne génère pas de source pour cette interface.</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@
<target state="needs-review-translation">L'interfaccia COM di base non è riuscita a generare l'origine. ComInterfaceGenerator non genererà l'origine per questa interfaccia.</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedDescription">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported and will fail at runtime</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedMessage">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="CastsBetweenRuntimeComAndSourceGeneratedComNotSupportedTitle">
<source>Casting between a 'ComImport' type and a source-generated COM type is not supported</source>
<target state="new">Casting between a 'ComImport' type and a source-generated COM type is not supported</target>
<note />
</trans-unit>
<trans-unit id="ComHostingDoesNotSupportGeneratedComInterfaceDescription">
<source>.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</source>
<target state="new">.NET COM hosting with 'EnableComHosting' only supports built-in COM interop. It does not support source-generated COM interop with 'GeneratedComInterfaceAttribute'.</target>
Expand Down
Loading