Referring to the sample from the link - X509 Enrollment Group Guide Using Cert Chain
I am trying to create a restful service (.net7 web api) that does the following 3 things:
- Upload a root ca cert to the DPS instance – using the REST API : Upload Cert REST API
- Create enrollment group with X509 attestation (intermediate cert from the chain) using the C# SDK sample: SDK Sample EG
- Register the device using the C# SDK sample : Device Registration SDK C#
All the above steps are working fine from my local host (WSL - Ubuntu) instance where I am able to communicate to my DPS instance and perform all the above 3 actions.
But when I try to deploy my service to azure app service (Linux) instance, steps 1 and 2 work fine but step #3 fails with the following error – “CA Certificate not found” Error code: 401002. Snap below:
Here is the code snipped I am using, which is pretty much referred to, from the SDK samples:
using ProvisioningTransportHandler transport = CertificateHelper.GetTransportHandler(Microsoft.Azure.Devices.Client.TransportType.Mqtt_WebSocket_Only);
var deviceClient = ProvisioningDeviceClient.Create(globalDPSEndpoint, idScope, security, transport);
DeviceRegistrationResult regResult = await deviceClient.RegisterAsync();
if (regResult.Status != ProvisioningRegistrationStatusType.Assigned)
{
return (false, $"Registration status did not assign a hub, so exiting...");
}
else
{
return (true, $"Successfully registered Device:{regResult.DeviceId} to Hub: {regResult.AssignedHub}.");
}
The exception is generated from the line:
DeviceRegistrationResult regResult = await deviceClient.RegisterAsync();
After much googling, I found that for non-windows environments, the SDK ProvisioningDeviceClient class requires both the leaf cert with private key and the full certificate chain to perform the TLS handshake to register the device. Hence after passing both, it started working from my localhost environment but still failing when deployed to the app service instance.
But, If I try to register the device using the REST api as mentioned here, Device Registration REST API,
via a CURL command and pass the full chain .pfx certificate with the password, the registration is successful. It just doesn’t work from code from inside the app service (linux) environment.
Some additional things I have found and tried:
I am wondering if there is any additional configuration I need to perform in the app service instance for the TLS handshake to be done correctly as the client is not able to find the CA cert to validate the leaf cert from the chain. But again, the same thing works fine from local machine.
Any help on this is much appreciated!
Thanks.

The "CA Certificate not found" error in Azure IoT Device Provisioning Service (DPS) indicates a problem with the certificate and some differences in the environment causing this issue. The code below registers devices in an IoT scenario using Azure IoT Hub and Device Provisioning Service (DPS).place the certificate under wwwroot and change the path to wwwroot
Controller.cs
Service.cs