简体   繁体   English

无法将Microsoft.Azure.Devices命名空间添加到Azure Function run.csx

[英]Unable to add Microsoft.Azure.Devices namespace to Azure Function run.csx

I have an Azure Function from which I need to send back messages to my devices through IoT Hub. 我有一个Azure函数,我需要从中通过IoT中心将消息发送回我的设备。 Every time I try to add the statement: 每当我尝试添加该语句时:

using Microsoft.Azure.Devices;

I get the below error: 我收到以下错误:

run.csx(11,23): error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.Azure' (are you missing an assembly reference?) run.csx(11,23):错误CS0234:类型或名称空间名称“设备”在名称空间“ Microsoft.Azure”中不存在(您是否缺少程序集引用?)

But strangely as the error suggests, if I just go for using Microsoft.Azure , there are no compilation errors. 但是奇怪的是,错误提示,如果我只是using Microsoft.Azure ,就不会有编译错误。

So I tried using Devices withing my code, like static Devices.ServiceClient client; 因此,我尝试将设备与代码一起使用,例如static Devices.ServiceClient client; , but again the same error. ,但同样是错误。

I have also tried using #r "Microsoft.Azure.Devices , but that didn't work either. 我也尝试使用#r "Microsoft.Azure.Devices ,但这也不起作用。

I tried creating a new Function App service altogether, but the same error just keeps poping up. 我尝试完全创建一个新的Function App服务,但是相同的错误不断弹出。

My project.json file looks something like this: 我的project.json文件看起来像这样:

{
  "frameworks": {
    "net47":{
      "dependencies": {
        "Microsoft.Azure.Devices": "1.4.1"
      }
    }
  }
}

I tried using net46 also. 我也尝试过使用net46

Small decription of my app: 我的应用程序的小描述:

So my function is supposed to be triggered by a ServiceBusTopic , has a BlobStorage as an Input. 因此,我的功能应该由ServiceBusTopic触发,具有BlobStorage作为输入。

No idea how am I going to send my data back to my device now that this namespace does not get added. 由于不添加此名称空间,所以不知道如何将数据发送回设备。

The following is a working sample using a Microsoft.Azure.Devices nuget package. 以下是使用Microsoft.Azure.Devices nuget包的工作示例。 The trigger is the ServiceBusQueue and the blobName is an application property of the BrokeredMessage. 触发器是ServiceBusQueueblobName是BrokeredMessage的应用程序属性。

run.csx: run.csx:

using System;
using System.Text;
using System.Configuration;
using System.Threading.Tasks;
using Microsoft.Azure.Devices;

public static async Task Run(string inputMessage, string inputBlob, TraceWriter log)
{
    log.Info($"C# ServiceBus queue trigger function processed message: {inputMessage}");
    log.Info($"Blob:\n{inputBlob}");


    string deviceId = "Device10";
    var c2dmsg = new Microsoft.Azure.Devices.Message(Encoding.ASCII.GetBytes(inputMessage));

    // create proxy
    string connectionString = ConfigurationManager.AppSettings["myIoTHub2"];
    var client = ServiceClient.CreateFromConnectionString(connectionString);

    // send AMQP message
    await client.SendAsync(deviceId, c2dmsg);

    await client.CloseAsync();
}

function.json: function.json:

    {
      "bindings": [
      {
        "name": "inputMessage",
        "type": "serviceBusTrigger",
        "direction": "in",
        "queueName": "function",
        "connection": "myServiceBus",
        "accessRights": "Manage"
      },
      {
        "type": "blob",
        "name": "inputBlob",
        "path": "afstates/{Properties.blobName}",
        "connection": "myStorage",
        "direction": "in"
      }
      ],
      "disabled": false
  }

project.json: project.json:

{
  "frameworks": {
  "net46":{
    "dependencies": {
      "Microsoft.Azure.Devices": "1.4.1"
      }
    }
  }
}

Try the following steps: 请尝试以下步骤:

  • delete the file project.lock.json 删除文件project.lock.json
  • use the net46 dependencies 使用net46依赖项
  • restore the nuget package pressing the save button. 按保存按钮恢复nuget包。

Watch the logs progress. 观察日志进度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为Unity安装Microsoft.Azure.Devices NuGet包? - How to install Microsoft.Azure.Devices NuGet package for Unity? 在 Azure Function csx 中使用 Microsoft.Azure.Storage - Use Microsoft.Azure.Storage in Azure Function csx 如何在 Azure 中将函数从一个 csx 文件调用到另一个 csx 文件? - How can I call function from one csx file to another csx file in Azure? 如何使用 ZD7EFA19FBE7D3972FD5ADB6074 脚本从 function 中获取 Azure Function 名称 - How to get Azure Function name from within a function using C# script (csx) Microsoft.Azure.Mobile命名空间问题[UWP] - Microsoft.Azure.Mobile Namespace Issue [UWP] Microsoft.Azure.Devices.Common.Exceptions.UnathorizedException - Microsoft.Azure.Devices.Common.Exceptions.UnathorizedException 命名空间“Microsoft”中不存在类型或命名空间名称“Azure” - The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' Microsoft.Azure.Devices.Device 和 Microsoft.Azure.Devices.Shared.Twin 之间有什么区别? - What is the difference between Microsoft.Azure.Devices.Device and Microsoft.Azure.Devices.Shared.Twin? Azure 内部版本 - 名称空间“Microsoft”中不存在类型或名称空间名称“OpenApi” - Azure Builds - The type or namespace name 'OpenApi' does not exist in the namespace 'Microsoft' “Microsoft.Azure.Devices.Client.Message”和“Microsoft.Azure.Devices.Message”之间的不明确引用 - Ambiguous reference between 'Microsoft.Azure.Devices.Client.Message' and 'Microsoft.Azure.Devices.Message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM