When setting up and Azure Function (C#) for Register Devices with IoT Hub I get the following error when running:
RegistryManager manager = RegistryManager.CreateFromConnectionString(connectionString);
Exception while executing function: Functions.registerdevice. Microsoft.Azure.Devices: Could not load file or assembly 'Microsoft.Azure.Amqp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
project.json:
{
"frameworks": {
"net46": {
"dependencies": {
"Microsoft.Azure.Devices": "1.2.3"
}
}
}
}
Hi @jsturtevant
That sounds like an issue with Functions...
I have tried the below on an older instance of Functions that I had deployed some time ago and had similar issues when running, error saying that it couldn't find Microsoft.Azure.Devices.Shared.
I created a brand new Function service instance and created a new csharp function and didn't have the issue anymore.
I have used the exactly same project.json as yours.
The code in my function looks like this:
var connectionString = "HostName=XXX.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=XXX=";
try {
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(connectionString);
registryManager.AddDeviceAsync(new Device("new_device"));
} catch (Exception e)
{
log.Info($"Exception thrown: {e.Message}");
}
Hope this helps
I believe it was Functions. I re-ran my function today with no changes and it worked. Thanks for the help.
Hi!
I have same issue. And previously it was helped to me adding new dependency:
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.Azure.Devices": "1.4.1",
"Microsoft.Azure.Amqp":"2.0.0.0"
}
}
}
}
But now everything works without Amqp in dependencies
Thanks for adding this @programmersommer !
I thought I've fixed the nuspec dependencies for the service SDK. Is the Amqp reference required?
@CIPop, Seems not anymore. Thank you for fixing