1

I have nullable reference types turned on and I have the following block of code:

    ExpandoObject? e1 = null;

    ExpandoObject e2 = null;

    ExpandoObject e3 = new();

    var d1 = (IDictionary<string, object>)e1;

    var d2 = (IDictionary<string, object>)e2;

    var d3 = (IDictionary<string, object>)e3;

I'm trying to cast the expando object to a dictionary but each cast gives me the following warning:

Warning CS8619 Nullability of reference types in value of type 'ExpandoObject' doesn't match target type 'IDictionary<string, object>'.

How can I suppress this warning?

Sun
  • 4,458
  • 14
  • 66
  • 108
  • 2
    `ExpandoObject` implements `IDictionary`. Or you could use `#pragma warning disable CS8600` and `#pragma warning disable CS8619` – Lasse V. Karlsen Jan 31 '22 at 15:03
  • 1
    OK, I don't really want to add the exclusion but changing my cast to IDictionary fixes things. Simples. Thanks – Sun Jan 31 '22 at 15:41

0 Answers0