Questions

In .NET Framework 4.6.2 the FormattedText() is Obsoleted, how can I fix it

When I try to build the WPF project with .net framework 4.6.2, I got an error, Because the FormattedText() is Obsoleted as below: The new override method is Q: How can I determine the pixelsPerD...

2 Apr at 10:26

How to set up Automapper in ASP.NET Core

I'm relatively new at .NET, and I decided to tackle .NET Core instead of learning the "old ways". I found a detailed article about [setting up AutoMapper for .NET Core here](https://lostechies.com/jim...

23 Jun at 14:28

How to ignore Foreign Key Constraints in Entity Framework Core SQLite database?

Foreign Key constraint failed use SQLite with Entity Framework Core I have relations in table ``` [Table("organizations")] public class Organizations { [Column("id")] public int Id { get; se...

27 Oct at 09:13

How to convert DateTime of type DateTimeKind.Unspecified to DateTime.Kind.Utc in C# (.NET)

I've inherited C# code that has an awful lot of DateTimes where the Kind property is DateTimeKind.Unspecified. These are fed into Datetime.ToUniversalTime() which gives back a UTC datetime (it adds 7...

26 Oct at 21:55

swagger - annotation for permissions?

Is there any way to document the permissions required for a Request? If I have annotations like ``` [Authenticate] [RequiredRole("Admin")] [RequiredPermission("CanAccess")] public object Delete(Dele...

26 Oct at 18:49

Add CSS Class to html element in a TagHelper

In an ASP.NET Core View I have the following: ``` <div class="message" message=""></div> ``` And I the a Tag Helper with the following TagHelper: ``` [HtmlTargetElement("div", Attributes = Message...

12 Aug at 03:49

Why does Roslyn have two versions of syntax per language?

I have been looking at the Roslyn code base and noticed that they have two versions of syntax(One internal and one public). Often these appear to be referred to as "Red" nodes and "Green" nodes. I am ...

11 Jan at 22:48

System.InvalidOperationException: Unable to resolve service for type

I'm working on a Web API with ASP.NET Core. When I'm executing my API with a post request, an exception is throwing before my break point in the Post method of . > Request starting HTTP/1.1 POST [h...

Azure Storage move blob to other container

I'm looking for an approach to move a blob in Azure from one container to another. The only solution I found is to use the Azure Storage Data Movement Library, but this seems to work between different...

27 Mar at 22:20

Azure Functions how to add application settings to bindings

I'm trying to add some custom binding using my app settings for my Azure Function. I need to receive only string a string from my settings. [](https://i.stack.imgur.com/0M7oP.png) I would like to ge...

JSON.NET Serialize DateTime.MinValue as null

I'd like `DateTime` fields that are set to `DateTime.MinValue` returned by my Web API to be serialized to `NULL` instead of `"0001-01-01T00:00:00"`. I understand there's a way to get JSON.NET to om...

26 Oct at 07:53

Generic function declaration in C#

I'm trying to create some stats about method call duration in a library. Instead of wrapping each method call to the library with lines to time and track it, I want to create a generic action and func...

26 Oct at 12:52

How can I retrieve Enum from char value?

I have the following enum ``` public enum MaritalStatus { Married = 'M', Widow = 'W', Widower = 'R', Single='S' } ``` In one function I have for exp: `'S'` , and I need to have `Mar...

10 Jan at 08:31

Create cookie with ASP.NET Core

In ASP.NET MVC 5 I had the following extension: ``` public static ActionResult Alert(this ActionResult result, String text) { HttpCookie cookie = new HttpCookie("alert") { Path = "/", Value = text...

9 Sep at 16:38

Ambiguity in parameter type inference for C# lambda expressions

My question is motivated by Eric Lippert's [this blog post](https://blogs.msdn.microsoft.com/ericlippert/2007/03/28/lambda-expressions-vs-anonymous-methods-part-five/). Consider the following code: `...

25 Oct at 21:7

Unable to connect to MongoDB (MongoLabs) via C# client

I have setup in MongoLabs (mLab - [https://mlab.com/](https://mlab.com/)) a database and have added a very simple Collection. I am using the MongoDB driver to attempt to connect and work with this c...

25 Oct at 19:51

Sharing a DLL between projects

Microsoft says it's platform neutral these days, so I'm trying to build on Mac and Linux only with VS Code and deploy to Azure. Why? It's mainly to prove that I can. Our project has several parts whi...

How to serialize a JObject the same way as an object with Json.NET?

How do I control the serialization of a JObject to string? I have some APIs that return a JObject and I usually apply some changes and persist or return them. I want to avoid persisting null properti...

25 Oct at 16:15

Dynamically calling method and class name

I have some cases where I have to call method names from class names. ``` string scenario1 = "MockScenario1"; string scenario2 = "MockScenario2"; MockScenario1.GetInfo(); MockScenario2.GetInfo(); ``...

17 Jan at 22:10

MSBuild conflict between mscorlib 4.x and mscorlib 2.x

I was investigating a build failure recently and saw a warning about conflicts between assemblies. I dug deeper and MSBuild told me this: > There was a conflict between "mscorlib, Version=4.0.0.0, C...

25 Oct at 14:46

PayPal in ASP.NET Core

How do I integrate with the `PayPal API` in an `ASP.NET Core` app? I have tried various libraries but none of them are compatible with `ASP.NET Core`... how do I do it?

25 Oct at 08:10

How to mock HttpContext.User

I am working on a Asp.net MVC 5 project and I am trying to setup a mock to return a custom principal within a controller. I have search and tried different approach suggested but none of them works. ...

.NET Core get connection string from appsettings.json

I develop a simple web app and, in the future, I want to do it as multi-tenancy. So I want to write the connection string straight into `OnConfiguring` method: ``` public class ApplicationContext : ...

24 Oct at 12:49

How do I insert data when the primary key column is not an identity column?

I'm trying to insert data using Dapper.Contrib, in a table where the primary key column is not an identity column. The database table is created with this script: ``` begin transaction create table...

24 Oct at 11:54

Redirect to login when unauthorized in ASP.NET Core

In the previous ASP.NET MVC, there was an option to redirect to the login action, if the user was not authenticated. I need the same thing with ASP.NET Core, so I: 1. created a ASP.NET Core project...