An Azure service that provides an event-driven serverless compute platform.
I have found the issue: the InputModel struct should be serialized correctly.
public class Message
{
public InputModel Id { get; set; }
}
[JsonConverter(typeof(InputModelConverter))]
public struct InputModel
{
public Guid Id { get; }
public InputModel(Guid value) => Id = value;
public static InputModel FromString(string value) => new InputModel(Guid.Parse(value));
}
public class InputModelConverter : JsonConverter<InputModel>
{
public override InputModel Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
// Assuming the JSON value is a simple string that can be parsed as a Guid
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException("Expected a string value.");
}
string guidString = reader.GetString();
if (!Guid.TryParse(guidString, out Guid guidValue))
{
throw new JsonException("The string value is not a valid GUID.");
}
return InputModel.FromString(guidValue.ToString());
}
public override void Write(Utf8JsonWriter writer, InputModel value, JsonSerializerOptions options)
{
// Serialize the InputModel instance's Id as a string
writer.WriteStringValue(value.Id.ToString());
}
}
}
//this is how the orchestrator is called
await client.ScheduleNewOrchestrationInstanceAsync(
nameof(MyOrchestrator),
new Message
{
Id = InputModel.FromString(data)
},
new StartOrchestrationOptions { InstanceId = rowKey });
//in the orchestrator, trying to get the Message
var message = ctx.GetInput<Message>();
//the message contains the correct Guid now