Skip to content
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

compilation gives error SYSLIB1094 for a GeneratedComInterface interface deriving from an interface in another project #102602

Open
smourier opened this issue May 23, 2024 · 1 comment
Labels
area-System.Runtime.InteropServices untriaged New issue has not been triaged by the area owner

Comments

@smourier
Copy link

smourier commented May 23, 2024

Description

I have two projects, one console app project, referencing another class library project. One interface IMy is declared in the class library, and another interface IMy3 is declared in the console app and derives from IMy

Both projects are using ComWrappers source generation feature (GeneratedComInterface).

I cannot compile the console application.

Reproduction Steps

Here the class library project:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
		<PublishAot>true</PublishAot>
	</PropertyGroup>
</Project>

Contains only one file IMy.cs:

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace AotTest
{
    [GeneratedComInterface, Guid("68207504-314f-492a-b4f2-fbc1838e6ac3")]
    public partial interface IMy
    {
    }

    [GeneratedComInterface, Guid("80511349-dff5-4c5e-839b-af4735977ebf")]
    public partial interface IMy2 : IMy // this derived one works fine
    {
    }
}

Here's the console app project:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net8.0</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<PublishAot>true</PublishAot>
		<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
		<InvariantGlobalization>true</InvariantGlobalization>
	</PropertyGroup>

	<ItemGroup>
		<ProjectReference Include="..\AotTest\AotTest.csproj" />
	</ItemGroup>
</Project>

contains only one file Program.cs:

using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;

namespace AotTest.Cli
{
    internal class Program
    {
        static void Main()
        {
            Console.WriteLine("Hello, World!");
        }
    }

    [GeneratedComInterface, Guid("755293e8-fe80-4654-aee3-732fefaaf3e0")]
    public partial interface IMy3 : IMy
    {
    }
}

Expected behavior

I don't see why it shouldn't compile, I hope this simple scenario is supported.

Actual behavior

I get compilation error:

1>------ Build started: Project: AotTest, Configuration: Debug Any CPU ------
1>AotTest -> E:\smo\work\AotTest\AotTest\bin\Debug\net8.0\AotTest.dll
2>------ Build started: Project: AotTest.Cli, Configuration: Debug Any CPU ------
2>E:\smo\work\AotTest\AotTest.Cli\Program.cs(15,30,15,34): error SYSLIB1094: COM interface AotTest.Cli.IMy3 inherits from AotTest.IMy, which has errors. ComInterfaceGenerator will not generate source for AotTest.Cli.IMy3. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1094)
2>Done building project "AotTest.Cli.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Also, independently from the SYSLIB1094 error, Roslyn seems to crash (but not always, seems more a background thing) this is what I see (sometimes) in Visual Studio and it seems somehow related (I have a bigger project where these top error lines popup continuously):

image

Here is the stack trace from the first error line:

StreamJsonRpc.RemoteInvocationException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__154`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.ArgumentException: SyntaxTree is not part of the compilation (Parameter 'syntaxTree')
      at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.GetSemanticModel(SyntaxTree syntaxTree, SemanticModelOptions options)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.IsDiagnosticSuppressed(Diagnostic diagnostic, SuppressMessageInfo& info)
      at Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.ApplySourceSuppressions(Diagnostic diagnostic)
      at Microsoft.CodeAnalysis.GeneratorDriver.FilterDiagnostics(Compilation compilation, ImmutableArray`1 generatorDiagnostics, DiagnosticBag driverDiagnostics, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators(Compilation compilation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.ComputeNewGeneratorInfoInCurrentProcessAsync(ISourceGeneratorTelemetryCollectorWorkspaceService telemetryCollector, Compilation compilationWithoutGeneratedFiles, TextDocumentStates`1 oldGeneratedDocuments, GeneratorDriver generatorDriver, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.ComputeNewGeneratorInfoAsync(SolutionCompilationState compilationState, Compilation compilationWithoutGeneratedFiles, TextDocumentStates`1 oldGeneratedDocuments, GeneratorDriver oldGeneratorDriver, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.AddExistingOrComputeNewGeneratorInfoAsync(CreationPolicy creationPolicy, SolutionCompilationState compilationState, Compilation compilationWithoutGeneratedFiles, CompilationTrackerGeneratorInfo generatorInfo, Compilation compilationWithStaleGeneratedTrees, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.<>c__DisplayClass23_0.<<GetOrBuildFinalStateAsync>g__FinalizeCompilationWorkerAsync|4>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.<>c__DisplayClass23_0.<<GetOrBuildFinalStateAsync>g__FinalizeCompilationAsync|3>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.<>c__DisplayClass23_0.<<GetOrBuildFinalStateAsync>g__BuildFinalStateAsync|0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.GetOrBuildFinalStateAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.GetSourceGeneratedDocumentStatesAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteSourceGenerationService.<>c__DisplayClass2_0.<<GetSourceGenerationInfoAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass8_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Int32 workspaceVersion, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunServiceImplAsync[T](Func`2 implementation, CancellationToken cancellationToken)

Regression?

I don't tink so but I can't be sure.

Known Workarounds

I don't have any.

Configuration

.NET 8.0.5, Visual Studio 17.10.0 (latest), Windows 11 x64

Here's a reproducing solution
AotTest.zip

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 23, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 23, 2024
@jkotas jkotas added area-System.Runtime.InteropServices and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 23, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime.InteropServices untriaged New issue has not been triaged by the area owner
Projects
Status: No status
Development

No branches or pull requests

2 participants