Skip to content

C#: erroneus CS8618 warning with partial class when definition is in one file and initialization in another #58640

@vsfeedback

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


Hello,
Here is a class separated in 2 files (simple example, to show the problem).

File 1:

namespace ClassLibrary1;
public partial class Class1
{
  public static readonly String Value1;

  static Class1 ()
  {
    Value1 = String.Empty;
    Value2 = String.Empty;
  }
}

File 2:

namespace ClassLibrary1;
public partial class Class1
{
  public static readonly String Value2;
}

Even if Value2 is initialized in the class constructor, VS shows a warning CS8618 for its value:
image.png

Test case:
ClassLibrary1.zip


Original Comments

Feedback Bot on 12/8/2021, 00:51 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 12/9/2021, 10:51 AM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions