Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:55:55+00:00 2026-06-11T17:55:55+00:00

I have got following message: Warning: Field is never assigned to, and will always

  • 0

I have got following message:

Warning: Field is never assigned to, and will always have its default value null.

My code looks like (it is simplified, so useless):

public class MyEntity
{
    // ...
    public string MyProp { get; set; }
}

public class MyClass
{
    string dbMyProp;

    public string MyProp { get { return dbMyProp.Replace("a", "b"); } }

    public static readonly Expression<Func<MyEntity, MyClass>> FromMyEntity = e => new MyClass
    {
        dbMyProp = e.MyProp // ...
    };
}

I think that the message is not true.

Is it a bug in C# compiler or I have missed something?

UPDATE The field is dbMyProp. It is simplified but it still produces this warning.

UPDATE2 The following code does not produce such warning:

public class MyClass2
{
    string dbMyProp;

    public string MyProp { get { return dbMyProp.Replace("a", "b"); } }

    public static MyClass2 FromMyEntity(MyEntity e)
    {
        return new MyClass2 
        {
            dbMyProp = e.MyProp // ...
        };
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:55:56+00:00Added an answer on June 11, 2026 at 5:55 pm

    Yes, it seems a shortcoming of the compiler. It apparently cannot see through (does not include) the Expression.
    The following prints “bbc” as expected:

    var exp = MyClass.FromMyEntity.Compile();
    var mc = exp(new MyEntity { MyProp = "abc"});
    Console.WriteLine(mc.MyProp);
    

    I tried a few tricks like a private constructor on MyClass but the warning remains.

    It seems the compiler applies a more conservative algorithm, only checking if any (normal) member assigns to dbMyProp .



    You are confusing things by having 2 different elements with the name dbMyProp but MyEntity.MyProp is never written to here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Always, I have got the following message: name 'byteProivder_LengthChanged' does not match 'Methods, properities
I have got the following very simple code: function init() { var articleTabs =
I have got the following issue, my function appends code to a string $string
I have got the following code that produce an image. But I'm getting the
I have got mail message with following subject in my Gmail accout: 400, значение,
I have got the following soap message and would like to know how to
I have the following code and when I compiled and went, I got following
When I try to commit changes to local repo, I have got following message:
I have got the following problem with F# code recently: almost the complete code
I have got the following IF condition code: if ((depth <= min_depth ) &&

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.