-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Description
When @@alternateType maps a property to Azure.Core.armResourceType (C# ResourceType), the generator emits WriteObjectValue(ResourceType, options) for serialization. But WriteObjectValue<T> has no case for ResourceType (which is a readonly struct wrapping a string), so it falls through to the default case and throws:
System.NotSupportedException: Not supported type Azure.Core.ResourceType
This also affects deserialization — the generator emits ResourceType.DeserializeResourceType() which doesn't exist as a public method.
Affected Model (Storage MPG Migration)
StorageAccountNameAvailabilityContent— spec hastype: "Microsoft.Storage/storageAccounts"(constant string), mapped via:
@@alternateType(StorageAccountCheckNameAvailabilityParameters.type, Azure.Core.armResourceType, "csharp");Impact
This blocks 230 out of 287 tests in the Storage SDK because nearly every test calls CheckStorageAccountNameAvailability during setup.
Current Workaround
Custom [CodeGenSerialization] hooks for both directions:
[CodeGenSerialization(nameof(ResourceType),
DeserializationValueHook = nameof(DeserializeResourceType),
SerializationValueHook = nameof(SerializeResourceType))]
public partial class StorageAccountNameAvailabilityContent
{
private static void SerializeResourceType(Utf8JsonWriter writer, ResourceType resourceType)
{
writer.WriteStringValue(resourceType.ToString());
}
private static void DeserializeResourceType(JsonProperty property, ref ResourceType resourceType)
{
resourceType = new ResourceType(property.Value.GetString());
}
}Note: The SerializationValueHook requires regeneration to take effect. The generated file still has WriteObjectValue until regenerated.
Comparison with Native Usage
When armResourceType is used as a native property type (not via @@alternateType), the generator correctly emits WriteStringValue(ResourceType). The bug is specific to the @@alternateType code path.
Works (native): testresourcetype.tsp
model ResourceTypeTestProperties {
optionalResourceType?: Azure.Core.armResourceType; // generates WriteStringValue ✓
}Broken (alternateType): client.tsp
@@alternateType(SomeModel.type, Azure.Core.armResourceType, "csharp"); // generates WriteObjectValue ✗