Exception throwed when calling RegisterAsync of ProvisioningDeviceClient

Kumpala, Deepak DEEKU 1 Reputation point
2023-04-24T04:55:44.06+00:00
I have a below method , written using `C#`

     public async Task<DeviceRegistrationResult> RegisterDevice(ProvisioningDeviceClient provClient)
        {
            DeviceRegistrationResult registrationResult = null;
            try
            {
                registrationResult = await provClient.RegisterAsync().ConfigureAwait(false);

                if (registrationResult.Status != ProvisioningRegistrationStatusType.Assigned) {                   

                }               
            }
            catch (Exception ex)
            {
               
            }
            return registrationResult;
        }


This method was called like this

       var deviceRegistrationResult = await _dpsDeviceClient.RegisterDevice(provClient);


I am getting below error

>System.MissingMethodException: 'Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Devices.Provisioning.Client.DeviceRegistrationResult> Microsoft.Azure.Devices.Provisioning.Client.ProvisioningDeviceClient.RegisterAsync()'.'


I am using version 1.5.2 of Microsoft.Azure.Devices.Provisioning.Client library.

I have also tried with upgrading Microsoft.Azure.Devices.Provisioning.Client to 1.19.2, this time it was not showing exception but my app is crashing. Strangely exception is not getting caught in `Catch` section.

The below code was used to create `ProvisioningDeviceClient`

     using (var transport = new ProvisioningTransportHandlerMqtt(TransportFallbackType.WebSocketOnly))
       {
       provClient = ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, "MyIdScope",
                         security, transport);
       }

Note: MyIdScope is have not mentioned in post for security purpose.


**.csproj file content**

     <Project Sdk="Microsoft.NET.Sdk">

     <PropertyGroup>
     <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.1</TargetFramework>
     </PropertyGroup>

     <ItemGroup>
     <PackageReference Include="Microsoft.Azure.Devices.Provisioning.Client" Version="1.19.2" />
      <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.1" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
      <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.1" />
      <PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
     <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
    </ItemGroup>

    <ItemGroup>
    <ProjectReference Include="..\ConnectivityLibrary\ConnectivityLibrary.csproj" />
    </ItemGroup>

    <ItemGroup>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    </ItemGroup>

    </Project>


I also see the below exception in `provClient` object.

>'((Microsoft.Azure.Devices.Shared.DefaultWebProxySettings)provClient._transport.Proxy).Credentials' threw an exception of type 'System.NotSupportedException'


dpsconnectionerror

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,157 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,966 Reputation points
    2023-04-24T15:26:20.0366667+00:00

    Hi @Kumpala, Deepak DEEKU Greetings! Welcome to Microsoft Q&A forum. Thank you for posting your question here. Please leverage the sample code provided in the GitHub repository to Azure IoT SDK Csharp to provision a device using Symmetric Keys. The GitHub repository has a SymmetricKeySample.cs file with the code to provision the device. The file can be found under the directory azure-iot-sdk-csharp-main\provisioning\device\samples\how to guides\SymmetricKeySample

    The code does not require any changes and you can execute the project through the command line by passing the DPS instance ID scope, Registration ID and the SAS key. Please refer the below image for reference

    User's image

    Upon execution of the command, you can see that the device gets provisioned on the IoT Hub. Find the below image for the reference.

    enter image description here

    Refer the instructions provided in the Quickstart: Provision a simulated symmetric key device to get more details on the steps needed to set up and execute the demo code.

    Please let us know if you run into any issues or need further assistance in the comments below.


    If the response helped, please do click Accept Answer and Yes. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    0 comments No comments