How do I set a default User Agent on an HttpClient?

It's easy to [set a user agent](https://stackoverflow.com/questions/33659663/how-to-set-user-agent-with-system-net-webrequest-in-c-sharp) on an HttpRequest, but often I want to use a single HttpClient...

23 May at 12:18

`PrintQueue.AddJob` does not finish

I tried following code on some PCs. ``` using (var lps = new LocalPrintServer()) using(var pqueue = lps.GetPrintQueue("PRINTER-NAME")) { pqueue.AddJob("job-name", @"C:\example.xps", false, pticke...

19 May at 16:16

How to create MongoDB MultiKey index on attribute of items in an array .NET Driver

I have a MongoDB collection "foos" containing items which each have an array of "bars". That is, "foo" has the following schema: ``` { "id": UUID "name": string ... "bars": [ ...

Can the Virtual File System In Service Stack Be configured not not treat files with multiiple dots as directories?

I'm attempting to serve an angular spa from embedded resources using the ServiceStack Virtual file system. This appears to be mostly working, however many of my generated files include two dots in th...

19 May at 06:25

Why does SyntaxNode.ReplaceNode change the SyntaxTree options?

I'm trying to replace nodes within a syntax tree in Roslyn, and it's just about working, but with an annoyance which feels it be a problem. The syntax tree is generated from a script, and I want the...

19 May at 02:35

Embed Unity3D app inside WPF application

I want to develop a new CAD software in WPF and instead of using WPF 3D, is it possible to use Unity3D as my graphic engine that is capable of rotate, pan, zoom and view 3D graphic objects based on my...

19 May at 00:27

How can I detect unused imports in a Script (rather than a Document) with Roslyn?

I'm writing a system to process snippets written as unit tests for Noda Time, so I can include the snippets in the documentation. I've got a [first pass](https://github.com/nodatime/nodatime/commit/8e...

18 May at 21:54

Resolving Hangfire dependencies/HttpContext in .NET Core Startup

I've installed and configured Hangfire in my .NET Core web application's Startup class as follows (with a lot of the non-Hangfire code removed): ``` public class Startup { public void Configurati...

'Cannot find the requested object' exception while creating X509Certificate2 from string

I am trying to create `X509Certificate2` from string. Let me show an example: ``` string keyBase64String = Convert.ToBase64String(file.PKCS7); var cert = new X509Certificate2(Convert.FromBase64String...

Entity framework core: Cannot insert explicit value for identity column in table 'Relation' when IDENTITY_INSERT is set to OFF

I'm bulding an application and when I want to insert a form into my form table I get the following error: > Cannot insert explicit value for identity column in table 'Relation' when IDENTITY_INSER...

23 May at 06:47

ResolutionException - Getting "Required dependency of type *********** could not be resolved"

Following is the exact scenario in my application. I have used ServiceStack 3.9.48 and AutoFac 4.6.0 to develop a REST service. Following is the code of AppHost which is inherited from AppHostBase ...

Visual Studio Shows code errors that don't exist

I'm not sure if anyone else has encountered this but often, when I open this particular solution, I see a whole list of errors (see below). [](https://i.stack.imgur.com/DWV60.png) If I double click...

18 May at 10:30

Expression-bodied properties vs. {get; set;}

When I have Visual Studio 2017 generate properties for me, it will always use the new expression-bodied properties, for example: ``` private static string username; internal static string Username { ...

18 May at 10:35

ASP.NET: Check if run from migration

I have some code in my `ConfigureServices` that fails when running a migration: ``` dotnet ef migrations list ``` I'm trying to add a Certificate but it can't find the file (it works when starting ...

Is it possible to use the c# "interactive window" instead of the immediate window in VS2017

The C# " " is more fully featured than the " ". Is it possible to load the debug context into it during a debug session?

Automapper, Mapper Not initialized. Call initialize with proper configuration

When I try to submit data into database i get following error: > {"Success":false,"Error":true,"ErrorType":2,"Message":"System.InvalidOperationException: Mapper not initialized. Call Initialize with ...

18 May at 08:0

Servicestack ORM db.Close() does not terminate the connection process

I have a code which demonstrates simple mysql database connection with ServiceStack ORM ``` var dbFactory = new OrmLiteConnectionFactory(DB_CONNECTION_STRING, MySqlDialect.Provider); var db = dbFacto...

17 May at 22:3

How can I enable Server GC in .NET Core?

I have a .NET Core app () developed in running on the version of the . I have tried adding an `App.config` with the following entries: ``` <?xml version="1.0" encoding="utf-8" ?> <configuration> ...

17 May at 21:47

.NET Core: Finally block not called on unhandled exception on Linux

I have created the following C# program: ``` namespace dispose_test { class Program { static void Main(string[] args) { using (var disp = new MyDisposable()) ...

18 May at 16:16

ASP.NET Core WebAPI Security Considerations

My WebAPI is, just that, an API backend for my UI to consume. In fact, I will have perhaps 10's of WebAPI services that my UI will use. I'm having difficulty understanding what I need to consider in ...

Set Asp.Net Core MVC Json options

One of the classes that I have in my project called, say, `AC`, has a property `Address` that is of type `IPEndPoint`. This type, as well as `IPAddress`, are notorious for not being serializable to J...

How do I mock the FileInfo information for a file?

I have a scenario in which I need much of the information from the FileInfo structure -- creation time, last write time, file size, etc. I need to be able to get this information cleanly, but also be ...

16 Oct at 19:42

Why are so many simple types in the .Net framework not marked as serializable?

I find it a recurring inconvenience that a lot of simple types in the .Net framework are not marked as serializable. For example: `System.Drawing.Point` or `Rectangle`. Both those structs only consis...

17 May at 14:17

How to initialize default value to C# out variables?

I used `TryParse` to parse a string to number. I need a solution to initialize out variable with default value, So when TryParse fails to convert I get my default value. Here is the code : Error > CS1...

6 May at 20:46

Asp.Net Core - simplest possible forms authentication

I have this old MVC5 application that uses forms authentication in the simplest possible form. There is only one account stored in web.config, there are no roles etc. ``` <authentication mode="Forms"...