Share via

C2D message error: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.Azure'

Haris Papageorge 251 Reputation points
2021-11-21T13:15:30.893+00:00

Hi,

I'm trying to send a C2D message on arrival of an IoTHub event (through this tutorial).
I've created an Azure function through the portal with .NET and I successfully receive the device to cloud message.
I want to do all this through the portal if possible but I get this error when I add this line to the code:
using Microsoft.Azure.Devices;.
the error is the following:
"The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.Azure'"

I've seen this error come up frequently but i haven't managed to solve it. Again, I want to do all this through the portal.

Any tips?

thanks

Azure IoT Hub
Azure IoT Hub

An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.

0 comments No comments

Answer accepted by question author

Sander van de Velde | MVP 37,066 Reputation points MVP
2021-11-21T20:52:41.697+00:00

Hello @Haris Papageorge ,

adding an Azure Function using the azure portal editor can b a challenge.

When possible, use the template projects using either Visual Studio or VS Code.

It seems you are missing the much needed Nuget package references.

There are normally part of the project file. In the Azure Function portal, this file is omitted.

Still, you can add it by hand...

I added this 'function.csproj' file by uploaded it from disk:

151189-image.png

<Project Sdk="Microsoft.NET.Sdk">  
  <PropertyGroup>  
    <TargetFramework>netstandard2.0</TargetFramework>  
  </PropertyGroup>   
  <ItemGroup>  
    <PackageReference Include="Microsoft.Azure.Devices" Version="1.36.0" />  
  </ItemGroup>  
</Project>  

Note: make sure the file actually has this text.

See, the Nuget package for IoT devices is added.

Try to recompile your function again:

151258-image.png

If compilation does not complete successfully, consider again to work with the more mature project templates.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.