2
votes
#r "System.Data"
#r "System.Threading"
#r "Microsoft.WindowsAzure.Storage"

using System.Net;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.DataMovement;




public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, 
TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");

// parse query parameter
string name = req.GetQueryNameValuePairs()
    .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
    .Value;

if (name == null)
{
    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();
    name = data?.name;
}

return name == null
    ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
    : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);

}

I am trying to use an Httptriggered azure function to run DataMovement between cloud blob containers. However I keep getting the following error:

2018-02-06T23:59:58.392 run.csx(12,38): error CS0234: The type or namespace name 'DataMovement' does not exist in the namespace 'Microsoft.WindowsAzure.Storage' (are you missing an assembly reference?) 2018-02-06T23:59:58.407 Exception while executing function: Functions. Microsoft.Azure.WebJobs.Script: Script compilation failed. 2018-02-06T23:59:58.407 Function completed (Failure, Id=72ab129f-706e-497c-ac70-fcebdd3b41ec, Duration=131ms)

Can I use more assemblys than the list provided here: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies

or not? IF so, how?

1
Consider switching to precompiled functions instead of csx scripts. Referencing libraries and NuGet packages is much more straightforward there.Mikhail Shilkov

1 Answers

0
votes

The type or namespace name 'DataMovement' does not exist in the namespace 'Microsoft.WindowsAzure.Storage'

According to your error, we know the DataMovement reference is not in Microsoft.WindowsAzure.Storage package.

It belongs to ‘Microsoft.Azure.Storage.DataMovement’ package. You could refer to my method to install it in Azure function in azure portal.

Click Azure function>View file>add a new file named 'project.json'(if it does not exist).Write the following code in this file then click run to install package:

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.Azure.Storage.DataMovement": "0.7.0"
      }
    }
   }
}

Then we could use the 'Microsoft.WindowsAzure.Storage.DataMovement' reference: enter image description here

Can I use more assemblys than the list provided here

Yes, you could add assemblys in project.json file and run it to install.