Best way to use HTTPClient in ASP.Net Core as a DI Singleton

I am trying to figure out how to best use the HttpClient class in ASP.Net Core. According to the documentation and several articles, the class is best instantiated once for the lifetime of the applic...

10 Dec at 23:53

Confused about Directory.GetFiles

I've read the docs about the `Directory.GetPath` search pattern and how it is used, because I noticed that `*.dll` finds both `test.dll` and `test.dll_20170206`. That behavior is documented Now, I ha...

6 Feb at 09:35

How to add where clause to ThenInclude

I have 3 entities: `Questionnaire.cs`: ``` public class Questionnaire { public int Id { get; set; } public string Name { get; set; } public ICollection<Question> Questions { get; set; } ...

Nuget - Package restore failed. Rolling back package changes for 'WebApplication1'. 0

It's my own custom nuget package that I've not published yet and testing locally. The nuget package consists of a dll file and nuspec file is as follows. ``` <?xml version="1.0"?> <package > <meta...

Asp.Net Core: Use memory cache outside controller

In ASP.NET Core its very easy to access your memory cache from a controller In your startup you add: ``` public void ConfigureServices(IServiceCollection services) { services.Ad...

Capture shutdown command for graceful close in .NET Core

I'm porting to .NET core and the existing app has hooked the win32 call SetConsoleCtrlHandler to capture application close so that it can cleanly close off open database files and other orderly shutdo...

Regex for removing only specific special characters from string

I'd like to write a regex that would remove the special characters on following basis: - - `@``&``'``(``)``<``>``#` I have written this regex which removes whitespaces successfully: ``` string user...

ASP.NET Core JWT mapping role claims to ClaimsIdentity

I want to protect ASP.NET Core Web API using JWT. Additionally, I would like to have an option of using roles from tokens payload directly in controller actions attributes. Now, while I did find it o...

8 Mar at 22:33

PostgreSQL: 42883 Operator does not exist: timestamp without time zone = text

I am using Npgsql 3.0.3.0 and PetaPoco latest version. When I run this command: ``` var dateCreated = DateTime.Now; // just an example var sql = new Sql("WHERE date_created = @0", dateCreated.ToStr...

3 Feb at 22:16

Validation Using MVVM Light in a Universal Windows App

After done with setting up MVVM Light in a Universal Windows App application, I have the following structure, and I wonder what is the cleanest way to do validation in 2017 using UWP and mvvmlight to ...

ResourceType Document is unexpected at UpsertDocumentAsync()

I'm new to Azure DocumentDB, and I've immediately run into a problem while trying it out. On the first save in an empty collection, I get the following error: > ResourceType Document is unexpected.Act...

20 Jun at 09:12

Internal .Net Framework Data Provider error 6 in SQL Azure

I regularly experience the above error when creating connections to `Azure` SQL databases. I've implemented `ReliableSqlConnection` with retry logic in attempt to avoid this issue but it has been to n...

Garbage collection async methods

I just noticed something really strange with regards to garbage collection. The WeakRef method collects the object as expected while the async method reports that the object is still alive even thoug...

3 Feb at 11:30

How to access the servicestack request object

I have created a web service using ServiceStacks ServiceStack with Razor template. This service could be hosted in one of many locations. I want to be able to determine information about the uri of a ...

3 Feb at 10:42

Base64 image doesn't display on Render PDF from RDLC report

I'm trying to display image(base64 string) using parameter(`@CustomerSign`) in RDLC report I've configured image property as below: Select the image source : `Database` Use this field : ``` =C...

Change the focused border color of a Wpf textbox when it GotFocus()

What I want: to change the border color to yellow when any textbox has focus. What I tried: ``` <Window.Resources> <Style TargetType="TextBox"> <Style.Triggers> <Trigger Prop...

23 May at 12:32

When should I use ConcurrentDictionary and Dictionary?

I'm always confused on which one of these to pick. As I see it I use `Dictionary` over `List` if I want two data types as a `Key` and `Value` so I can easily find a value by its `key` but I am always ...

2 Feb at 22:15

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

I recently ran into a situation where I would like to use a tag helper within a tag helper. I looked around and couldn't find anyone else trying to do this, am I using a poor convention or am I missin...

How to use await in Xamarin Android activity callbacks

The title may be a bit misleading, my question is more about why it works in this weird way. So I have an activity with a layout that has a TextView and a ListView. I have a long running async method...

What is a ProfileService/When is a ProfileService executed?

I've been playing with IdentityServer4. Absolutely love it. I've been going through the tutorials on your site, specifically https://identityserver4.readthedocs.io/en/release/quickstarts/7_javascript_...

Unable to receive events from server in ServiceStack

i'm having problem using events in my servicestack application. I'm creating an SOA applicatin based on ServiceStack. I've had no problem creating a simple GET/POST manager within the host. Now i wou...

2 Feb at 20:26

Custom Configuration Binder for Property

I'm using Configuration Binding in an ASP.NET Core 1.1 solution. Basically, I have some simple code for the binding in my ConfigureServices Startup section that looks like this: ``` services.AddSingl...

2 Feb at 18:6

Disable Visual Studio 2015 comment alignment?

In Visual Studio 2015, if you have code like this: ``` var foo = that.Bar(); // Get the value //foo++; ``` selecting Edit -> Advanced -> Format Document results in formatting like this: ``` var fo...

AsNoTracking() and Include

I have a Linq query that fetches an entity and some of its navigation properties. ``` context.MyEntity .AsNoTracking() .Include(i=> i.Nav1) .Include(i=> i.Nav2) .Where(x=> x.Prop1==1)...

4 Feb at 09:49

How do I add assembly references in Visual Studio Code?

So I've come across a similar issue twice now while working on my first project in C#. When trying to add either `using System.Data;` or `using System.Timers;`, I get the following error: > The type...