1

I am getting below error while running my azure function app application:

[7/15/2020 8:26:08 AM] The listener for function 'NotificationChangeFeed' was unable to start. [7/15/2020 8:26:08 AM] The listener for function 'NotificationChangeFeed' was unable to start. Microsoft.Azure.DocumentDB.Core: Object reference not set to an instance of an object.

Error Screen shot: enter image description here

Here is my Change Feed Trigger Azure Function:

public static class NotificationChangeFeed
    {
        [FunctionName("NotificationChangeFeed")]
        public static async Task Run([CosmosDBTrigger(
            databaseName: "FleetHubNotifications",
            collectionName: "Notification",
            ConnectionStringSetting = "CosmosDBConnection",
            LeaseCollectionName = "leases", CreateLeaseCollectionIfNotExists = true)]IReadOnlyList<Document> input, 
            [Inject] ILoggingService loggingService,
            [Inject] IEmailProcessor emailProcessor)
        {
            var logger = new Logger(loggingService);

            try
            {
                if (input != null && input.Count > 0)
                {
                    foreach (Document document in input)
                    {
                        string requestBody = document.ToString();
                        var notification = requestBody.AsPoco<Notification>();
                        
                        var result = await emailProcessor.HandleEmailAsync(notification, logger);

                        if (result)
                        {
                            logger.Info($"Email Notification sent successfully for file name: {document.Id}");
                        }
                        else
                        {
                            logger.Warning($"Unable to process document for Email Notification for file with name: {document.Id}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Unable to process Documents for Email Notification for Files: {input.Count}", ex,
                    nameof(NotificationChangeFeed));
            }
        }
    }

local.settings.json:

{
  "IsEncrypted": "false",
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "CosmosDbId": "FleetHubNotifications",
    //Localhost
    "CosmoDbAuthKey": "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
    "CosmoDbEndpoint": "https://localhost:8081/",
    "CosmosDBConnection": "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
}
}
Rakesh Kumar
  • 2,701
  • 9
  • 38
  • 66

1 Answers1

0

Connecting String of local Storage Emulator is correct.

If your firewall restricts func from accessing the Storage Account, then this error may be reported. The firewall is one of the reasons that the listener cannot access the virtual Storage Emulator.

When running the function locally, all triggers except httptrigger need to use the Storage Emulator. If the firewall restricts the listener's access to virtual storage, problems can occur when performing functions.

Try disabling the firewall and see if that resolves the issue.

Of course, it is also possible that the Storage Emulator service is not open. Try typing

"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" status

in cmd to check the status.

If it returns false, enter the following command to start the Storage Emulator:

"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init
"%programfiles(x86)%\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start

To sum up:

This listener can not start is generally for three reasons.

1.Connection string error prevents connection,

2.firewall is set

3.some services are not turned on.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27