-
Notifications
You must be signed in to change notification settings - Fork 648
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
Saga analyzer throws exception when handlers implemented in partial classes #6370
Comments
Hi @nrsmp, thanks for the report! I included partial classes in the tests for the analyzer, as they present analyzers with very interesting edge and corner cases, but obviously I missed something. Could you the code that caused the analyzer to fail? A simplified form of the saga with method implementations removed and variable names completely obfuscated would be totally fine. |
Certainly. Here's simplified code that reproduces the analyzer errors. Each class lives in its own file, and all files live in the same parent folder. SagaImplementation.csusing System.Threading.Tasks;
using NServiceBus;
namespace Saga.Implementation;
public partial class SagaImplementation : Saga<SagaData>, IAmStartedByMessages<SagaStartMessage>
{
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<SagaData> mapper)
{
mapper.MapSaga(s => s.OrderId)
.ToMessage<SagaStartMessage>(b => b.OrderId)
.ToMessage<SagaStep1>(b => b.OrderId)
.ToMessage<SagaStep2>(s => s.OrderId)
.ToMessage<SagaStep3>(b => b.OrderId);
}
public async Task Handle(SagaStartMessage message, IMessageHandlerContext context)
{
var options = new SendOptions();
options.RouteToThisEndpoint();
await context.Send(new SagaStep1 {OrderId = Data.OrderId}, options);
await context.Send(new SagaStep2 {OrderId = Data.OrderId}, options);
await context.Send(new SagaStep3 {OrderId = Data.OrderId}, options);
}
private void CompleteSaga()
{
if(Data.Step1Complete && Data.Step2Complete && Data.Step3Complete)
{
MarkAsComplete();
}
}
} SagaStep1.csusing System.Threading.Tasks;
using NServiceBus;
namespace Saga.Implementation;
public partial class SagaImplementation : IHandleMessages<SagaStep1>
{
public Task Handle(SagaStep1 message, IMessageHandlerContext context)
{
Data.Step1Complete = true;
CompleteSaga();
return Task.CompletedTask;
}
} SagaStep2.csusing System.Threading.Tasks;
using NServiceBus;
namespace Saga.Implementation;
public partial class SagaImplementation : IHandleMessages<SagaStep2>
{
public Task Handle(SagaStep2 message, IMessageHandlerContext context)
{
Data.Step2Complete = true;
CompleteSaga();
return Task.CompletedTask;
}
} SagaStep3.csusing System.Threading.Tasks;
using NServiceBus;
using Shared.NServiceBus.Messages.Commands.Encompass;
namespace Saga.Implementation;
public partial class SagaImplementation : IHandleMessages<SagaStep3>
{
public Task Handle(SagaStep3 message, IMessageHandlerContext context)
{
Data.Step3Complete = true;
CompleteSaga();
return Task.CompletedTask;
}
} SagaModels.csusing NServiceBus;
namespace Saga.Implementation;
public class SagaData : ContainSagaData
{
public string OrderId { get; set; } = null!;
public bool Step1Complete { get; set; }
public bool Step2Complete { get; set; }
public bool Step3Complete { get; set; }
}
public class SagaStartMessage : ICommand
{
public string OrderId { get; set; } = null!;
}
public class SagaStep1 : SagaStartMessage
{
}
public class SagaStep2 : SagaStartMessage
{
}
public class SagaStep3 : SagaStartMessage
{
} |
Fixed in #6372. This will be released shortly in NServiceBus 7.7.3. |
@nrsmp NServiceBus 7.7.3 is now released. Thanks again for the report and repro code! |
Wow, that was fast! You're quite welcome. |
When implementing a Saga in a partial class and using library versions 7.7.0 and 7.7.2, the roslyn analyzer throws an error System.ArgumentException: 'Syntax node is not within syntax tree'
By downgrading to version 7.6.2, the analyzer issue goes away.
Stack trace:
The text was updated successfully, but these errors were encountered: