Wednesday 8 February 2017

Adding external references to Azure Functions: CS0009 "PE image doesn't contain managed metadata".

I had an Azure Function that referenced an external assembly:

#r "Orders.Contracts.dll"
#r "Newtonsoft.Json"

using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Orders.Contracts;

public static void Run(string myQueueItem, TraceWriter log)
    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");

    var orderCreated = JsonConvert.DeserializeObject(myQueueItem);

    log.Info($"orderCreated Reference: {orderCreated.OrderReference}");


External assemblies have to be added to the bin folder on the function's folder; e.g. D:\home\site\wwwroot\OnOrderCreated\bin.

Firstly I connected to the home site using FileZilla and created the bin and uploaded the DLL.
I got the error

CS0009 "PE image doesn't contain managed metadata".

I then tried a similar technique, but this time went to Function App Setting > Open Dev Console and created the bin folder and uploaded the DLL using FileZilla. That failed too.

In the end I found the best way was to use the Kudu console. I created the bin folder and drag-and-dropped the file from explorer into the Kudu file browser window. This then fixed the error.

Navigate to /site/wwwroot/
add folder bin
upload files to bin

No comments:

Post a Comment