Can I make Json.net deserialize a C# 9 record type with the “primary” constructor, as if it had [JsonConstructor]?

Firstly, you only have to do this when you create your own constructors. This is due to the fact that on instantiation it won’t know which one to use. Secondly, note that (by default) the deserializer will use the property and constructor names and overwrite the ones you omit in the actual constructor type. Furthermore, … Read more

Can I use a Tag Helper in a custom Tag Helper that returns html?

No you cannot. TagHelpers are a Razor parse time feature. One alternative is creating a TagHelper and manually invoking its ProcessAsync/Process method. Aka: var anchorTagHelper = new AnchorTagHelper { Action = “Home”, }; var anchorOutput = new TagHelperOutput(“a”, new TagHelperAttributeList(), (useCachedResult, encoder) => new HtmlString()); var anchorContext = new TagHelperContext( new TagHelperAttributeList(new[] { new TagHelperAttribute(“asp-action”, … Read more

DataTestMethod vs TestMethod

ShreyasRmsft commented the following on GitHub: Hi @cactuaroid DataTestMethod is not needed. Go ahead and use TestMethod with DataRows to data drive your tests. For any more doubts follow the official docs at https://github.com/microsoft/testfx-docs https://github.com/microsoft/testfx/issues/614 https://github.com/microsoft/testfx-docs/issues/64 So, according to Microsoft, it is preferred to use TestMethod over DataTestMethod.

#if DEBUG vs if (env.IsDevelopment())

Preprocessor directives are conditionally compiled… Which means that something like this: #if DEBUG //Do something #endif Will only be compiled and checked if the DEBUG symbol is defined (it is defined when the build is set to DEBUG). Additionally, in the IDE the code between the preprocessor symbols will appear greyed out. This code: if … Read more

Why can’t we add a Web API as a “service reference” in Visual Studio the same way we can with WCF or ASMX?

Do you mean a Rest Web Service? With Rest, there is no service definition page, like with WCF or ASMX. Usually people want to use a Rest API with JSON.. however.. if you are just looking for a JSON output, and you want your clients to quickly be able to connect to your service, you … Read more

How should I set up my integration tests to use a test database with Entity Framework?

Thanks so much to @Justin and @Petro for your answers, which have helped me immensely. The solution I have come up with is a combination of the techniques you suggested. The solution described below provides a new database for each run of the tests, and a separate transaction for each test. I added a connection … Read more

.NET Core Cookie Authentication SignInAsync not working

as of .net 2.x, if you’re using cookie auth, ensure you include the authenticationScheme and specify name and role claim types, the identity and auth properties. //You should specify the ‘types’ of the claims which acts as ‘name’ and ‘role’, furthermore, you should have claims with those types in your claimsIdentity like that var identity … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)