[英]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.
触发器是ServiceBusQueue , blobName是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: 请尝试以下步骤:
Watch the logs progress. 观察日志进度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.