0

I am attempting to create an Azure Function. Locally I want to be able to test my function before I deploy it. I am developing on a MacOS 11.2.3 using VS Code. I am using Azurite as my local storage emulator running in Docker. I can connect to the local emulator and see my Queues and Storage. My Functions app is using netcoreapp3.1 and is a Functions v3 app.

My trigger is a new payload received by a queue. My trigger works just fine and when I write my data to the Azure storage table, I can see the RowKey, PartitionKey and Timestamp. I cannot see any of the data I have created. Here is my code:

public static class MyFunction
{
    [FunctionName("MyFunction")]
    [return: Table("mytable")]
    public static MyObject Run([QueueTrigger("myqueue")]string queueItem, ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed");
        var myObject = JsonConvert.DeserializeObject<MyObject>(queueItem);
        log.LogInformation(JsonConvert.SerializeObject(myObject));
        return myObject;
    }
}

Here is MyObject.cs

using System;
using Microsoft.WindowsAzure.Storage.Table;

namespace MyProject.models
{
    public sealed class MyObject : TableEntity
    {
        public MyObject(string myProperty)
        {
            string PartitionMonth = DateTime.Now.ToMonthName();
            string PartitionYear = DateTime.Now.Year.ToString();
            PartitionKey = $"{PartitionMonth}-{PartitionYear}";

            RowKey = Guid.NewGuid().ToString();
            MyProperty = myProperty;

        }
        public string MyProperty { get; }
    }
}

The problem is that I am not seeing the MyProperty Column being made. My JSON Payload that is given to the queue has it, I can see it logged to the logger, I just don't see the column in Azure Storage Explorer. I do see a Row made each time I trigger my function. Please help me understand why I cannot see my data.

1 Answer 1

2

I believe you are running into this issue is because you have no public setter for your MyProperty.

Please try by changing this line of code:

public string MyProperty { get; }

to

public string MyProperty { get; set; }

And your code should run just fine.

Reference: https://github.com/Azure/azure-storage-net/blob/933836a01432da169966017f0848d7d6b05fc624/Lib/Common/Table/TableEntity.cs#L406 (See "Enforce public getter / setter" in the code).

internal static bool ShouldSkipProperty(PropertyInfo property, OperationContext operationContext)
{
    // reserved properties
    string propName = property.Name;
    if (propName == TableConstants.PartitionKey ||
        propName == TableConstants.RowKey ||
        propName == TableConstants.Timestamp ||
        propName == TableConstants.Etag)
    {
        return true;
    }

    MethodInfo setter = property.FindSetProp();
    MethodInfo getter = property.FindGetProp();

    // Enforce public getter / setter
    if (setter == null || !setter.IsPublic || getter == null || !getter.IsPublic)
    {
        Logger.LogInformational(operationContext, SR.TraceNonPublicGetSet, property.Name);
        return true;
    }

    // Skip static properties
    if (setter.IsStatic)
    {
        return true;
    }

    // properties with [IgnoreAttribute]
#if WINDOWS_RT || NETCORE 
    if (property.GetCustomAttribute(typeof(IgnorePropertyAttribute)) != null)
#else
    if (Attribute.IsDefined(property, typeof(IgnorePropertyAttribute)))
#endif
    {
        Logger.LogInformational(operationContext, SR.TraceIgnoreAttribute, property.Name);
        return true;
    }

    return false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This did work. I also tried using a private set, and that didn't work either. Is there a good pattern to use an immutable object AND Azure Tables?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.