来自 Azure 配置服务的格式错误的令牌异常

malformed token exception from azure provisioning service

我按照 https://docs.microsoft.com/en-us/azure/iot-dps/tutorial-net-provision-device-to-hub 中的确切步骤注册了设备。

我收到 "malformed token" 异常。

这是上面的代码link

    private const string SampleRegistrationId = "sample-individual-csharp";
    private const string SampleTpmEndorsementKey =
            "****"; //Key from Azure portal
    private const string OptionalDeviceId = "myCSharpDevice";
    private const ProvisioningStatus OptionalProvisioningStatus = ProvisioningStatus.Enabled;


   static async Task SetRegistrationDataAsync()
    {
        Console.WriteLine("Starting SetRegistrationData");

        Attestation attestation = new TpmAttestation(SampleTpmEndorsementKey);

        IndividualEnrollment individualEnrollment = new IndividualEnrollment(SampleRegistrationId, attestation);

        individualEnrollment.DeviceId = OptionalDeviceId;
        individualEnrollment.ProvisioningStatus = OptionalProvisioningStatus;

        Console.WriteLine("\nAdding new individualEnrollment...");
        var serviceClient = ProvisioningServiceClient.CreateFromConnectionString(ServiceConnectionString);

        IndividualEnrollment individualEnrollmentResult =
            await serviceClient.CreateOrUpdateIndividualEnrollmentAsync(individualEnrollment).ConfigureAwait(false);

        Console.WriteLine("\nIndividualEnrollment created with success.");
        Console.WriteLine(individualEnrollmentResult);
    }

我认为你使用的连接字符串不正确format.Please注意不要包含“;”在连接字符串的末尾。 也许从 Azure 门户复制连接字符串是避免使用不正确连接字符串的好方法。 如果错误仍然存​​在,请随时告诉我。