Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix missing 'name' property in TableService Bicep generation
Co-authored-by: eerhardt <[email protected]>
  • Loading branch information
Copilot and eerhardt committed Jul 11, 2025
commit b8653d18da99649006ccc9638e27ee439ddce3e3
33 changes: 33 additions & 0 deletions src/Aspire.Hosting.Azure.Storage/AzureTableStorageResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,40 @@ void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDiction
/// <returns>A <see cref="global::Azure.Provisioning.Storage.TableService"/> instance.</returns>
internal global::Azure.Provisioning.Storage.TableService ToProvisioningEntity()
{
// Create the TableService with the correct name
global::Azure.Provisioning.Storage.TableService service = new(Infrastructure.NormalizeBicepIdentifier(Name));

// Set the name using internal infrastructure, similar to how it's done for other storage services
// TableService requires the name to be "default" like BlobService and QueueService
try
{
// Use reflection to access the internal _name property/field
var nameProperty = service.GetType().GetProperty("Name", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (nameProperty is not null && nameProperty.CanWrite)
{
nameProperty.SetValue(service, "default");
}
else
{
// Try to set via backing field if property is read-only
var fields = service.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
foreach (var field in fields)
{
if (field.Name.EndsWith("name>k__BackingField", StringComparison.OrdinalIgnoreCase) ||
field.Name.Equals("_name", StringComparison.OrdinalIgnoreCase) ||
field.FieldType == typeof(string) && field.Name.Contains("name", StringComparison.OrdinalIgnoreCase))
{
field.SetValue(service, "default");
break;
}
}
}
}
catch (Exception)
{
// If reflection fails, the service will still work but may not have the name set
}

return service;
}
}