-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ComInterfaceGenerator] Trailing trivia after GeneratedComInterfaceAttribute included in generated files #88798
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsConsider the following declaration of an interface designed to be multi-targeted against .NET 8 and earlier versions of .NET [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("7DAC8207-D3AE-4C75-9B67-92801A497D44")]
#if !GENERATED_MARSHALLING
[ComImport]
#else
[GeneratedComInterface]
#endif
public partial interface IFoo
{
void Foo();
} Attempting to compile this results in the following error:
In the generated source code, we can see the // MyProject.IFoo.cs
namespace MyProject
{
[System.Runtime.InteropServices.Marshalling.IUnknownDerivedAttribute<InterfaceInformation, InterfaceImplementation>]
#endif
public partial interface IFoo
{
}
}
namespace MyProject
{
#endif
public partial interface IFoo
{
}
} If we flip our #if GENERATED_MARSHALLING
[GeneratedComInterface]
#else
[ComImport]
#endif
public partial interface IFoo then the You can "work around" this by moving the interface header into the #if !GENERATED_MARSHALLING
[ComImport]
public partial interface IFoo
#else
[GeneratedComInterface]
public partial interface IFoo
#endif However I would present that users attempting to multi-target by applying an
|
Consider the following declaration of an interface designed to be multi-targeted against .NET 8 and earlier versions of .NET
Attempting to compile this results in the following error:
In the generated source code, we can see the
#ifdef
directive has erroneously been carried over to two locationsIf we flip our
#if
directive around to the followingthen the
#else
,[ComImport]
and#endif
lines are all copied over to the generated source file.You can "work around" this by moving the interface header into the
#if
statement, as followsHowever I would present that users attempting to multi-target by applying an
#if
around which attribute to use is a reasonable scenario; I would imagine upon reading theGeneratedComInterfaceAttribute
AttributeSyntax
the source generator should just trim all trailing triviaThe text was updated successfully, but these errors were encountered: