C
C#3mo ago
Rizell

MediatR - System.Text.Json.JsonException: 'S' is an invalid start of a value.

I have a project with Clean Architecture and MediatR. My API gets the request fine and the command is created with correct data. In this case my tests passes Email = "test@test.com"
var command = new CreateUserCommand(userReq.Email);
var createUserResult = await mediator.Send(command);

My command:
public record CreateUserCommand(string Email) : IRequest<ErrorOr<User>>;

My handler:
public async Task<ErrorOr<User>> Handle(CreateUserCommand command, CancellationToken cancellationToken)
{
var user = await _userRepository.CreateUser(new User(){Email = command.Email});
await _unitOfWork.CommitChangesAsync();
return user;
}

I Register my MediatR like this:
services.AddMediatR(options =>
{
// options.RegisterServicesFromAssemblyContaining(typeof(DependencyInjection));
options.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);
});
var command = new CreateUserCommand(userReq.Email);
var createUserResult = await mediator.Send(command);

My command:
public record CreateUserCommand(string Email) : IRequest<ErrorOr<User>>;

My handler:
public async Task<ErrorOr<User>> Handle(CreateUserCommand command, CancellationToken cancellationToken)
{
var user = await _userRepository.CreateUser(new User(){Email = command.Email});
await _unitOfWork.CommitChangesAsync();
return user;
}

I Register my MediatR like this:
services.AddMediatR(options =>
{
// options.RegisterServicesFromAssemblyContaining(typeof(DependencyInjection));
options.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);
});
However, my Handler is never invoked. Directly after
mediator.Send(command);
mediator.Send(command);
I get the following error System.Text.Json.JsonException 'S' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0. at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex) at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) Any pointers or ideas what the cause might be?
4 Replies
Rizell
Rizell3mo ago
Issue is solved. I had just forgotten to implement the : IRequestHandler<CreateUserCommand, ErrorOr<User>> on my Handler class
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts
Blazor, auto unsubscribe patternI have created website using blazor, and if some component subscribe to something then it implement ✅ Form1.resx file gives error on Internet or Restricted zoneForm1.resx file gives error on Internet or Restricted zone I can't fix it error (english):Severity LHelp with API structureI want to create modular API structure https://timdeschryver.dev/blog/maybe-its-time-to-rethink-our-✅ WPF - how to correctly call a method in the ViewModel when an event occurs in the View?I want to call a method in the ViewModel when an event happens in the View. That is, when the View Blazor help needed. How can i Validate datalist entries in a child componentI have written a Blazor testapp that has an EditForm with a child component in the parent component.Inlcude content after run a command (.csproj)Hey i wanna ask if it would possible to place this after the cmake building command? ```cs <IteOpinion on the code i've writtenHello, I have a discord bot im working on, the code i am about to show reads a JSON Config file. I w✅ Receiving Input While Minimized (WinForms C#)Pretty general question here. How would I go about receiving input from my user while they aren't tSlack app - Trigger ID expiredHi, so I'm testing out a Slack app from here https://github.com/soxtoby/SlackNet/blob/master/Examplecan someone help me ?, Im doing a arrow that points to a enemy position based on the player position```cs Vector3 FirstPoint = (Player.position - transform.position).normalized; // Direção inicial do