pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

Fail to read Item when TaxonomyFieldValue.TermGuid is null #1414

Closed czullu closed 4 months ago

czullu commented 4 months ago

Category

Describe the bug

Checking the TaxonomyFieldValue in CSOM i can see that TermGuid is defined as a string. [Remote] public string TermGuid { get { return m_termGuid; } set { m_termGuid = value; } }

The TermId in IFieldTaxonomyValue is defined as Guid

While CSOM is able to return List-Item with

26 26 PnP.Core will fail to parse TermGuid and throw an Error: Type = System.FormatException Message = One of the identified items was in an invalid format. Source = System.Text.Json.Rethrowable TargetSite = System.Guid GetGuid() HResult = -2146233033 StackTrace = at System.Text.Json.JsonElement.GetGuid() at PnP.Core.Model.SharePoint.FieldTaxonomyValue.FromJson(JsonElement json) at PnP.Core.Services.JsonMappingHelper.ProcessSpecialRestFieldTypeAsync(TransientObject pnpObject, String propertyName, JsonElement json) at PnP.Core.Services.JsonMappingHelper.FromJsonRest(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2 fromJsonCasting) at PnP.Core.Services.JsonMappingHelper.FromJson(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2 fromJsonCasting) at PnP.Core.Model.BaseDataModel`1.ProcessResponseAsync(ApiResponse apiResponse, Expression`1[] expressions) at PnP.Core.Services.JsonMappingHelper.FromJsonRest(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2 fromJsonCasting) at PnP.Core.Services.JsonMappingHelper.FromJson(TransientObject pnpObject, EntityInfo entity, ApiResponse apiResponse, Func`2 fromJsonCasting) at PnP.Core.Services.JsonMappingHelper.MapJsonToModel(BatchRequest batchRequest) at PnP.Core.Services.BatchClient.ProcessSharePointRestInteractiveResponse(BatchRequest restRequest, HttpStatusCode statusCode, Dictionary`2 responseHeaders, Stream responseContent) at PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch) at PnP.Core.Services.BatchClient.ExecuteSharePointRestBatchAsync(Batch batch) at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch) at PnP.Core.Model.BaseDataModel`1.RequestAsync(ApiCall apiCall, HttpMethod method, String operationName) at PnP.Core.QueryModel.BaseDataModelExtensions.BaseGetAsync[T](IQueryable`1 source, ApiCall apiCall, Expression`1[] selectors) at PnP.Core.Model.SharePoint.ListCollection.GetByServerRelativeUrlAsync(String serverRelativeUrl, Expression`1[] selectors) ## Steps to reproduce Unfortunately i could not find out how to get into this situation yet. First idea was that cloud happen when referred Term is deleted but test shows that Value of TermGuid remains to have the Guid as string. The List is created from a List Template but they not contain values... ## Expected behavior Return the Field as Null if TermGuid is Empty ## Environment details (*development & target environment*) current dev Branch
jansenbe commented 4 months ago

@czullu : I've made the TermId parsing more resilient and set Guid.Empty when the passed string is not a GUID, hope this fixes things for you. Closing this now, but please re-open when not working and share the new stacktrace