Skip to content

Ignore nullable property does warning CS8603 #520

Description

@heggi

.Net 7.0 with nullable enabled

public struct Dest
{
    public string Name { get; set; }
    public string? NullableString { get; set; }
}

public struct Source
{
    public string Name { get; set; }
}

public class Mapping : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<Source, Dest>()
            .Ignore(d => d.NullableString); // this string a got a warning message CS8603: Possible null reference return
    }
}

image

I think that signature of Ignore method need to be
public TypeAdapterSetter<TSource, TDestination> Ignore(params Expression<Func<TDestination, object?>>[] members);

Activity

  1. nwoolls commented on Nov 29, 2024

    @nwoolls

    Any fix for this? How do you ignore a property that is nullable?

  2. DocSvartz commented on Jan 23, 2025

    @DocSvartz
    Contributor

    @andrerav As far as I understand, this is used to get the Name of the Property.
    The value itself is not extracted there.

    Ignore(d=> d.NullableString) == Ignore("NullableString").

    The proposed solution @nwoolls removes the warning.
    Perhaps the original idea using Ignore was something more?

  3. vzalamea commented on Jun 23, 2026

    @vzalamea

    getting same issue.

    .Ignore(dest => dest.AccountNumber) //fails/warns with CS8603 when property is nullable.

    .Ignore("AccountNumber") //works fine. How expensive is this? Does this not use reflection?

  4. DocSvartz commented on Jun 24, 2026

    @DocSvartz
    Contributor

    Hi @vzalamea
    .Ignore(dest => dest.AccountNumber) == .Ignore("AccountNumber")

    .Ignore(dest => dest.AccountNumber)
    This is a helper that gets the Name of the property from the Expression, not the value of that Expression and is more resistant to refactoring in IDE.

  5. vzalamea commented on Jun 24, 2026

    @vzalamea

    Hi @vzalamea .Ignore(dest => dest.AccountNumber) == .Ignore("AccountNumber")

    .Ignore(dest => dest.AccountNumber) This is a helper that gets the Name of the property from the Expression, not the value of that Expression and is more resistant to refactoring in IDE.

    the problem is when I have <TreatWarningsAsErrors>true</TreatWarningsAsErrors>

    Image
  6. vzalamea commented on Jun 24, 2026

    @vzalamea

    If I treat it as just a warning, the code compiles fine and behaves as expected. So I'm not sure why "d.AccountNumber" is being evaluated and not just used to get the property name.

    Image
  7. DocSvartz commented on Jun 24, 2026

    @DocSvartz
    Contributor

    If I treat it as just a warning, the code compiles fine and behaves as expected. So I'm not sure why "d.AccountNumber" is being evaluated and not just used to get the property name.

    It occurs because Expressions usually using to obtain the Values ​​of property.
    This is precisely what the compiler warns you about. If you try to get the value of this property, you might get null instead of a string.

    The fix for this case should be simple, I'll see what I can do.

  8. ramiabughazaleh commented on Sep 4, 2026

    @ramiabughazaleh

    Thank you, @DocSvartz .

    It seems this made it into the v10.0.10 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions