msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Missing Enumeration Members

Open jbh999 opened this issue 1 year ago • 4 comments

Describe the bug

Deserializing the JSON response from the getManagedDevice API endpoint (no issue here) and then casting it into a ManagedDevice object throws an exception.


The JSON response returned from the API includes:

"managementAgent": "intuneAosp"
"deviceEnrollmentType": "androidAOSPUserOwnedDeviceEnrollment"

Neither of these values have a member in the associated enumerations contained in the ManagedDevice class: • ManagementAgentType enumeration does not have an intuneAosp member • DeviceEnrollmentType enumeration does not have an androidAOSPUserOwnedDeviceEnrollment member

Casting the deserialized response from the getManagedDevice API results in the following exception:

Newtonsoft.Json.JsonSerializationException: Error converting value "intuneAosp" to type 'System.Nullable`1[Microsoft.Graph.ManagementAgentType]'. Path '[1].managementAgent'.
---> System.ArgumentException: Requested value 'intuneAosp' was not found.

Expected behavior

Ability to deserialize the JSON response from getManagedDevice API endpoint and cast it into a ManagedDevice object

How to reproduce

  1. Enroll a DigiLens (Set up Intune enrollment for Android (AOSP) corporate-owned user-associated devices)

  2. Call the getManagedDevice API

  3. Review the JSON (API returns success and a valid JSON response) "managementAgent": "intuneAosp" "deviceEnrollmentType": "androidAOSPUserOwnedDeviceEnrollment"

  4. Deserializing the JSON response and casting it into a ManagedDevice object results in the exception

SDK Version

No response

Latest version known to work for scenario above?

Never worked

Known Workarounds

None that I know of

Debug output

Click to expand log ```
</details>


### Configuration

Windows 11 x64

Not related to any specific configuration

### Other information

• [ManagementAgentType enumeration](https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/c75439214c6752d0dff406ab4b0905a4369a7b5d/src/Microsoft.Graph/Generated/Models/ManagementAgentType.cs) requires an `intuneAosp` member
• [DeviceEnrollmentType enumeration](https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/c75439214c6752d0dff406ab4b0905a4369a7b5d/src/Microsoft.Graph/Generated/Models/DeviceEnrollmentType.cs) requires an `androidAOSPUserOwnedDeviceEnrollment` member

jbh999 avatar Nov 07 '24 21:11 jbh999

Thanks for raising this @jbh999

Any chance you can share a code sample of how you are deserializing the response as well as the SDK version you are using? I believe without a relevant converter like this one, Newtonsoft.Json will not support dowcasting out of the box. https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/e7ab26c8863b9ab0ca450ca95959d231205fad6a/src/Microsoft.Graph.Core/Serialization/DerivedTypeConverter.cs#L59

andrueastman avatar Nov 08 '24 06:11 andrueastman

I am using Newtonsoft (as visible in the exception documented in Describe the bug section above).

The code (deserializing JSON and casting to a ManagedDevice object) has been working for the past couple of years for all of our other enrolled device types.

The basic code used to deserialize JSON and cast into a ManagedDevice object ...

var response = await httpClient.GetAsync(apiUrl);
var responseContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
JObject result = JsonConvert.DeserializeObject(responseContent) as JObject;
var completeContent = new StringContent(JsonConvert.SerializeObject((JArray)result["value"], Formatting.None));
var responseContentComplete = await completeContent.ReadAsStringAsync();
JArray? devices = JsonConvert.DeserializeObject(responseContentComplete) as JArray;
devicesToReturn = devices.ToObject<ManagedDevice[]>().ToList<ManagedDevice>();

The issue is that the SDK (any version) does not support the enumeration members in the API responseManagementAgentType enumeration does not have an intuneAosp member • DeviceEnrollmentType enumeration does not have an androidAOSPUserOwnedDeviceEnrollment member

jbh999 avatar Nov 09 '24 21:11 jbh999

I just noticed that these are listed in the documentation for the Beta MS Graph REST API

Are there currently any plans to have the beta enumeration members promoted to v1.0 and incorporated into the code?

jbh999 avatar Dec 03 '24 17:12 jbh999

Based on my experience: If you want to use the Graph API to do anything in case of device management, then switch to the beta endpoint. There is plenty of stuff that is simply not available or behaves differently in v1 on a HTTP level (so no blame for the SDK). Also if you look into the network tab when browsing https://intune.microsoft.com you'll see that they do everything at the beta endpoint.

olivermue avatar Dec 12 '24 11:12 olivermue