roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

False positive IDE0059 with anonymous types

Open vsfeedback opened this issue 2 years ago • 0 comments

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


[severity:It bothers me. A fix would be nice] Visual Studio incorrectly generates an IDE0059 (Unnecessary assignment of a value to 'foo') on the first line of this code. The assignment is required because there is no way to create an anonymous type without also creating an object of that type.

var foo = new { systemRunDate = default(DateTime) };
Bar(out foo);
Console.WriteLine(foo);

static void Bar<T>(out T? foo)
{
    foo = default; // In production code, deserialize from JSON.
}

Original Comments

Feedback Bot on 6/13/2023, 08:31 PM:

(private comment, text removed)


Original Solutions

(no solutions)

vsfeedback avatar Jun 14 '23 14:06 vsfeedback