.NET Core: UseUrls seems getting ignored error

If you are facing the issue, that the Host.CreateDefaultBuilder’s ConfigureWebHostDefaults’s UseUrls method is getting ignored, and all the environment variables and launchsettings.json completly getting ignored by the .NET core application, its always using the default port of http : 5000 and the https 5001, follow the instructions

Are you using configuration builder before calling the configurewebhostdefaults?

				ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
				IConfigurationRoot configuration = cfgBuilder.Build();

And are you passing the built configuration to ConfigureAppConfiguration ? Like that:

					.ConfigureAppConfiguration(builder =>

Then remove the ConfigureAppConfiguration call, and it will work..

No idea how to work around

Docker error: CTC1015 Docker command failed with exit code 125.

If the Visual Studio’s output of the build on windows says the following:

docker: Error response from daemon: failed to create endpoint <ProjectName> on network nat: failed during hnsCallRawResponse: hnsCall failed in Win32: The process cannot access the file because it is being used by another process. (0x20).
If the error persists, try restarting Docker Desktop.


Go to your Services administration panel (by running services.msc)

Stop the following services:
– HNS (Host Network Service)
– docker (Docker Engine)

Then restart them in the order of stopping.

Windows: Set Environment variables for users

For some cases you might need to set environment variables for your .NET application.
This is true to .NET core too, when you are storing your application settings in these variables.

How to set up a script for the job

It’s handy to create a windows command line script for creating these variables, because when you are on a new work environment, than you don’t need to look up the keys and values.

So bring up your most-loved text editor, make your environment_variable_creator.bat, and add the following code:

@echo on

If you are using .NET core’s configuration builder with a prefix like this:

				ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
				IConfigurationRoot configuration = cfgBuilder.Build();
				var value = configuration["VARIABLE2"];

Then you need to set your variables with prefix “PREFIX_” in the bat file. In this scenario, VARIABLE1 can not be read, because it does not contain the prefix.

The code sets the variables only for your user account, not for others. You can parameterize the SETX command to set the settings for a different user, but i recommend, to run the script with a command line for the targeted user, because its much easier.

To run your script under other users name, then open your command prompt with ‘Run as… different user’

.NET Core: Using AssemblyInfo shared between assemblies

There was a time when project.json has replaced the AssemblyInfo. But since .NET core uses .csproj, instead of the project.json, AssemblyInfo comes to the development again.

If you want to version your several different assemblies together, then follow this tutorial.

Add a shared AssemblyInfo.cs

Right click on your solution, and select Add > New Item..

In the following screen, select Visual C# class, and name it as ‘AssemblyInfo.cs’

Replace the file content with the example below:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyDescription("Insert your description here")]
[assembly: AssemblyCompany("YourAwesomeCompany")]
[assembly: AssemblyCopyright("Copyright © YourAwesomeCompany 2021")]

Set your projects to use the shared assembly info

Do this all of your projects where you want to use the shared assembly info file.

Edit your project file with a text editor (or right click on project > Edit project file)

Add the following tag to the PropertyGroup tag in order to diable automatic assemblyinfo.cs generation:


Add the shared assembly info to be used with inserting the following tags to between the project tags:

    <Compile Include="..\AssemblyInfo.cs" Link="Properties\AssemblyInfo.cs" />

If the project has no Properties folder, like .NET Standard projects basically do, then add the new folder also with this snippet:

    <Folder Include="Properties\" />

.NET Core: Type serialization denied

When trying to return with a complex object in .NET Core API, which has a Type property in it, the serializer gives the following exception :

System.NotSupportedException: Serialization and deserialization of 'System.Type' instances are not supported and should be avoided since they can lead to security issues.

Passing Type, DataSet, DataTable through the JSON or XML serializer gives possibility to remote code execution for attackers. More information available at https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/security-guidance

Declare an enumeration for your types (ex: enum { string, int, etc }) you can parse the value for the requested type explicitly.