SenseNet / sensenet

Open Source Content Services Platform written in .NET
https://sensenet.com
GNU General Public License v2.0
173 stars 112 forks source link

NullReferenceException when saving VersioningMode #1906

Closed kavics closed 8 months ago

kavics commented 1 year ago

The VersioningMode cannot be string, because the saving causes a server error. See this model:

public class File : Content
    ...
    public string VersioningMode { get; set; }

When saving the model the request is something like this:

models=[{...,"VersioningMode":"3",...}]

and the response:

ODataException: Object reference not set to an instance of an object.
---- Inner Exception:
NullReferenceException: Object reference not set to an instance of an object.
   at SenseNet.ContentRepository.Fields.VersioningModeField.ConvertFromControlInner(Object value) in D:\dev\github\sensenet\src\ContentRepository\Fields\VersioningModeField.cs:line 50
   at SenseNet.ContentRepository.Fields.VersioningModeField.ConvertFrom(Object value) in D:\dev\github\sensenet\src\ContentRepository\Fields\VersioningModeField.cs:line 45
   at SenseNet.ContentRepository.Field.WriteProperties(Object value) in D:\dev\github\sensenet\src\ContentRepository\Field.cs:line 214
   at SenseNet.ContentRepository.Field.Save(Boolean validOnly) in D:\dev\github\sensenet\src\ContentRepository\Field.cs:line 321
   at SenseNet.ContentRepository.Content.SaveFields(Boolean validOnly) in D:\dev\github\sensenet\src\ContentRepository\Content.cs:line 1078
   at SenseNet.ContentRepository.Content.SaveAsync(Boolean validOnly, SavingMode mode, CancellationToken cancel) in D:\dev\github\sensenet\src\ContentRepository\Content.cs:line 1222
   at SenseNet.ContentRepository.Content.SaveAsync(Boolean validOnly, CancellationToken cancel) in D:\dev\github\sensenet\src\ContentRepository\Content.cs:line 1152
   at SenseNet.OData.ODataMiddleware.CreateNewContentAsync(String parentPath, String contentTypeName, String templateName, String contentName, String displayName, Boolean isMultiStepSave, JObject model, Boolean skipBrokenReferences, CancellationToken cancel) in D:\dev\github\sensenet\src\OData\ODataMiddleware.cs:line 597
   at SenseNet.OData.ODataMiddleware.CreateNewContentAsync(JObject model, ODataRequest odataRequest, CancellationToken cancel) in D:\dev\github\sensenet\src\OData\ODataMiddleware.cs:line 542
   at SenseNet.OData.ODataMiddleware.ProcessRequestAsync(HttpContext httpContext, ODataRequest odataRequest) in D:\dev\github\sensenet\src\OData\ODataMiddleware.cs:line 278
=====================

Workaround: use a string array instead of a simple string:

public class File : Content
    ...
    public string[] VersioningMode { get; set; }