The Nullable object error message should be set to

I have a null error for my runtime DTO object:

enter image description here

I did not understand, because the column is NULL:

[DataContract] public class SearchParametersCompanyDTO { public SearchParametersCompanyDTO(); [DataMember] public CompanyColumnsEnumDTO? Column { get; set; } [DataMember] public int PageIndex { get; set; } [DataMember] public int PageSize { get; set; } [DataMember] public string Term { get; set; } } [DataContract] public enum CompanyColumnsEnumDTO { [EnumMember] CompanyName = 0, [EnumMember] City = 1, [EnumMember] PostCode = 2, } 

This should be a conversion problem, because null is accepted in the column:

  var dto = new SearchParametersCompanyDTO { PageIndex = pageIndex, PageSize = defaultPageSize, Term = term, Column = null }; 

Any idea?

+6
source share
3 answers

You are trying to apply a null value to an enumeration type (and not a null enumeration type). I assume that you really want to change your cast to:

 Column = (CompanyColumnsEnumDTO?) column 
+4
source

The problem is that you selected the column value to a non-zero value, CompanyColumnsEnumDTO . Based on this exception, it looks like column is null here, and casting to a non-zero exception throws an exception. Did you mean to drop on CompanyColumnsEnumDTO? instead of this?

+3
source

Do you need to send to (CompanyColumnsEnumDTO?) Instead of (CompanyColumnsEnumDTO)

+1
source

Source: https://habr.com/ru/post/913041/


All Articles