c#-8.0

Why don't I get a warning about possible dereference of a null in C# 8 with a class member of a struct?

本小妞迷上赌 提交于 2020-07-29 11:38:07
问题 In a C# 8 project with nullable reference types enabled, I have the following code which I think should give me a warning about a possible null dereference, but doesn't: public class ExampleClassMember { public int Value { get; } } public struct ExampleStruct { public ExampleClassMember Member { get; } } public class Program { public static void Main(string[] args) { var instance = new ExampleStruct(); Console.WriteLine(instance.Member.Value); // expected warning here about possible null

Why does Visual Studio Type a Newly Minted Array as Nullable?

感情迁移 提交于 2020-07-28 03:51:25
问题 I'm writing a function with a generic type TVal . I wrote this line: var zeroBased = new TVal[size]; And then in Visual Studio (VS) I used alt+enter to replace var with an explicit type. Here's what I got: TVal[]? zeroBased = new TVal[size]; I was surprised to find the ? operator, indicating that the type might be nullable. I thought that I'd be safe enough assuming the type is never null when created with new , and could have just done: TVal[] zeroBased = new TVal[size]; Is there a scenario

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'

这一生的挚爱 提交于 2020-07-21 07:58:10
问题 I am using asp.net core 3.1 docker enabled project template (VS2019) to develop a web API. There are no compilation errors. While running the project, in the output window of the VS2019 I see the following message: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'

我的梦境 提交于 2020-07-21 07:58:06
问题 I am using asp.net core 3.1 docker enabled project template (VS2019) to develop a web API. There are no compilation errors. While running the project, in the output window of the VS2019 I see the following message: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'

坚强是说给别人听的谎言 提交于 2020-07-21 07:57:58
问题 I am using asp.net core 3.1 docker enabled project template (VS2019) to develop a web API. There are no compilation errors. While running the project, in the output window of the VS2019 I see the following message: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'. Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.0/System.Collections.NonGeneric.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My

Avoid CS8618 warning when initializing mutable non nullable property with argument validation

耗尽温柔 提交于 2020-07-21 04:57:39
问题 I have a question regarding nullable reference type system available since C# 8. Suppose we have a C# domain model class with a mutable reference type property like below: public class Person { public string Name { get; set; } public Person(string name) { Name = name; } } So far no problem. But consider real world scenario, I often want to check the validity of the property as it's a public mutable property and I have to make sure the model invariant whenever property is changed. public class

Avoid CS8618 warning when initializing mutable non nullable property with argument validation

这一生的挚爱 提交于 2020-07-21 04:55:58
问题 I have a question regarding nullable reference type system available since C# 8. Suppose we have a C# domain model class with a mutable reference type property like below: public class Person { public string Name { get; set; } public Person(string name) { Name = name; } } So far no problem. But consider real world scenario, I often want to check the validity of the property as it's a public mutable property and I have to make sure the model invariant whenever property is changed. public class

The event can only appear on the left hand side of += or -= dotnetstandard 2.1 [duplicate]

牧云@^-^@ 提交于 2020-06-29 05:45:07
问题 This question already has an answer here : Event Inheritance with C#8 Default Interface Implementation/Traits (1 answer) Closed last month . I'm using dot net standard 2.1 and c# 8, I want to create an event for my class (interface), I follow this tutorial and I wrote an interface: using System; using Crawler.Paging; namespace Crawler { public interface ICrawler { public event EventHandler NextPage; protected virtual void OnNextPage(EventArgs e) { EventHandler handler = NextPage; handler?

In C# 8, how do I detect impossible null checks?

三世轮回 提交于 2020-06-27 08:45:52
问题 I've started using nullable reference types in C# 8. So far, I'm loving the improvement except for one small thing. I'm migrating an old code base, and it's filled with a lot of redundant or unreachable code, something like: void Blah(SomeClass a) { if (a == null) { // this should be unreachable, since a is not nullable } } Unfortunately, I don't see any warning settings that can flag this code for me! Was this an oversight by Microsoft, or am I missing something? I also use ReSharper, but

Event Inheritance with C#8 Default Interface Implementation/Traits

雨燕双飞 提交于 2020-06-22 04:12:31
问题 There is currently little documentation surrounding the limitations of events with the new C#8 default interface implementations (traits). I am particularly confused with the spec proposal. Not only is the example given invalid C# (the "override" event is missing an identifier), but implementing any of these in C#8 (VS2019, .NET Core 3.0) returns a host of compiler exceptions. In addition, the release notes for C#8 don't make any mention of events for interface traits. As I continued to try