Nullable object must have a value?

后端 未结 8 2411
旧时难觅i
旧时难觅i 2020-12-09 14:54

On the line: bool travel = fill.travel.Value; I am getting the following error:

Nullable object must have a value

a

8条回答
  •  执念已碎
    2020-12-09 15:19

    I had this happen because there was code like this:

    bool? someVariable = (bool)someNullableBool;
    

    The someNullableBool was null and this error was thrown.

    The solution was to re-write it as:

    bool? someVariable = (bool?)someNullableBool;
    

提交回复
热议问题