postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
164 stars 4 forks source link

Bug: Eligibility constraint - "Operation is not valid due to the current state of the object" #191

Closed WhitWaldo closed 11 months ago

WhitWaldo commented 11 months ago

I've got an aspect that builds without any exception except the following from Metalama. Per the crash report:

 System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeExecutionContext.get_CompilationContext()
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeExecutionContext.ResolveCompileTimeTypeOf(String id, IReadOnlyDictionary`2 substitutions)
   at XYZ.MyDoodadAttribute.<>c.<BuildEligibility>b__0_0(IEligibilityBuilder`1 t) in C:\...\.netcoreapp7.0\0e5689bf1a31d3be\2023.1.10\MyDoodad_751cbbda.cs:line 33
   at XYZ.MyStoreAttribute.BuildEligibility(IEligibilityBuilder`1 builder) in C:\...\.netcoreapp7.0\0e5689bf1a31d3be\2023.1.10\MyDoodad_751cbbda.cs:line 33
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.<>c__DisplayClass5_0.<TryInvoke>b__0()
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.Invoke[TResult,TPayload](UserCodeFunc`2 func, TPayload& payload, UserCodeExecutionContext context)
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.Invoke[T](Func`1 func, UserCodeExecutionContext context)
   at Metalama.Framework.Engine.Utilities.UserCode.UserCodeInvoker.TryInvoke[T](Func`1 func, UserCodeExecutionContext context, T& result)

Here's what my BuildEligibility method looks like:

public override void BuildEligibility(IEligibilityBuilder<INamedType> builder)
    {
        builder.MustSatisfy(t => t.MustBeOfType(typeof(IMyInterface<,>)));
    }

The target type in question looks like:

[MyDoodad]
internal sealed partial class MyTest : IMyInterface<MyEntity, MyEntityId>
{
}

I enabled logging for the Compiler and RoslynCodeAnalysisService and got the following:

07/24/2023 21:59:40, ERROR, Thread 17, Compiler: The compilation failed at stage: 'CompileMethods' because of the error: I:...\MyDoodadAttribute.cs(30,34): error LAMA0042: 'MyDoodadAttribute.BuildEligibility' threw 'InvalidOperationException': Operation is not valid due to the current state of the object. Exception details are in 'C:\Users...\AppData\Local\Temp\Metalama\CrashReports\2023.1.10\exception-5c711356-b200-402d-a615-f74daac3a555.txt'. To attach a debugger to the compiler, use the '-p:MetalamaDebugCompiler=True' command-line option. @@Intrinsics.cs(2,7): hidden CS8933: The using directive for 'System' appeared previously as global using @@Intrinsics.cs(2,7): hidden CS8933: The using directive for 'System' appeared previously as global using

07/24/2023 21:59:40, ERROR, Thread 17, Compiler: The compilation failed at stage: 'BeforeEmitPe' because of the error: I:...\MyDoodadAttribute.cs(30,34): error LAMA0042: 'MyDoodadAttribute.BuildEligibility' threw 'InvalidOperationException': Operation is not valid due to the current state of the object. Exception details are in 'C:\Users...\AppData\Local\Temp\Metalama\CrashReports\2023.1.10\exception-5c711356-b200-402d-a615-f74daac3a555.txt'. To attach a debugger to the compiler, use the '-p:MetalamaDebugCompiler=True' command-line option. @@Intrinsics.cs(2,7): hidden CS8933: The using directive for 'System' appeared previously as global using @@Intrinsics.cs(2,7): hidden CS8933: The using directive for 'System' appeared previously as global using

Thanks!

PostSharpBot commented 11 months ago

Hello @WhitWaldo, thank you for submitting this issue. We will try to get back to you as soon as possible. Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-33582.

gfraiteur commented 11 months ago
WhitWaldo commented 11 months ago

Currently on 2023.1.10

Getting the same error after switching to:

builder.MustSatisfy(t => t.MustBe(typeof(IMyInterface<,>)));
gfraiteur commented 11 months ago

Then you should try with 2023.2.

gfraiteur commented 11 months ago

Closing this issue because I think it has been solved. Feel free to reopen if you experience it in 2023.2

WhitWaldo commented 11 months ago

I upgraded to 2023.2.2-rc and haven't seen this since.