Warning: curl_exec() has been disabled for security reasons in E:\Websites\zerobased\zero-based.net\wwwroot\wp-content\plugins\wordfence\vendor\wordfence\wf-waf\src\lib\http.php on line 360

Warning: curl_exec() has been disabled for security reasons in E:\Websites\zerobased\zero-based.net\wwwroot\wp-content\plugins\wordfence\vendor\wordfence\wf-waf\src\lib\http.php on line 360

Changing Windows Service Start parameters

You have created or installed service that uses Start parameters and now want to change them you would expect to be able to change them in Services (services.msc), but unfortunately changes made to „Start parameters“ cannot be applied from that application. But there are few approaches that can help you quickly to fix this issue. In following examples we will be changing Solr 6.6.2 service that was installed by using NSSM (the Non-Sucking Service Manager)



If you have just installed your service you can try removing service and adding it again with correct parameters using Command prompt by running following commands (without brackets):

nssm remove {ServiceName}

nssm install {ServiceName} {ServiceLocation} {ServiceParameters}



If removing and adding service is not an option for you there is also an NSSM „set“ command designed for updating your Services by typing:

nssm set solr662new “AppParameters” “start -f -p 8984”



Another approach would be using Registry. All services from services.msc are being read from one Registry location: „Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{Service Name}“, and if your service has sub key/folder „Parameters“, expand it and there you can find AppParameters, where you can visually change your „Start parameters“





In following code we are accessing Registry key „Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services“ and looking for service named „solr662new“, after it is found we are updating DisplayName and AppParameters values. If you need to update values other than AppParameters try checking out  ServiceRegistryDtoModel and ParametersDtoModel models and UpdateRegistryKey method and update it to suit your needs.





Sitecore Commerce XC 9.2 installation: RebuildIndexes_RebuildIndex-Core : WebRequest Request failed: The operation has timed out

Congrats on almost finishing Sitecore XC 9.2 installation. Only few installation steps before it is finished, but this error keeps pooping up.

Screenshot of RebuildIndexes_RebuildIndex-Core error







Json file Common.RebuildIndexes.json that is located in SIF->Configuration->Commerce->Comon, has a few RequestTimeout properties that define how long will install script wait before trying to start step again. Importunately if you have slow PC or Virtual Machine, default values are not giving your PC enough time to finish rebuilding indexes. By increasing these values, your PC will have time to complete this steps and installation will finish successfully.

My example of Common.RebuildIndexes.json








Successful installation after increasing timeouts


How to open Console Window in another screen

At some point in time you got frustrated that Windows console app opens on monitor that is not ideal for you or you just want to move it to another screen. Unfortunately Console does not offer out of the box solution to fix this problem so we need to find solution out of the box.


My solution is based upon consuming Windows API’s and Windows Forms to easily create maintainable solution.


SetWindowPos function seems to be a good start. By using it we can set Windows starting X and Y axis, as well as its width, height and window position. To use this function there are 2 challenges:

Getting monitors starting X point and getting the console Windows handle.

Monitors X axis point can be easily acquired by using WinForms  System.Windows.Forms.Screen.AllScreens property, which stores all connected monitors ant their information.

Getting Console Window handle is a bit trickier. First we need to use  GetConsoleWindow function assign it to the pointer and then pass it to the SetWindowPos.


SetWindowPos has a limitation thou. If we want to maximize screen, we cannot do it (we can extend it to monitors max width and height but its state would still not be maximized). Here we can use ShowWindow function where we pass our Console window and it’s desired state.


That would be all for this short tutorial, code sample is bellow.


Happy coding!



Sitecore – How to add standard values

It is easy to sometimes forget how to add Standard values item for your templates and in this short tutorial we will demonstrate how to do it.


Go to the template for which you want to create Standards values, open Options tab and click on Standard values button in Template section:






After clicking on Standard values button you can notice that new Item has been created under our template item:






Now you can set default values for your fields or set presentation details defaults.



Package ‘Microsoft.PortableLibrary.TargetingPack.Msi.Resources,version=15.0.26621.2,language=en-US’ failed to install

While updating and later uninstalling Visual Studio 2017 i got error: Package ‘Microsoft.PortableLibrary.TargetingPack.Msi.Resources,version=15.0.26621.2,language=en-US’ failed to install


log file:


After few hours of fruitless search of solutions i was able to correct problem by removing package “Microsoft Portable Library Multi-Targeting Pack – enu”

Removing “Microsoft Portable Library Multi-Targeting Pack Language Pack – enu” package using Windows Installer Clean Up








To remove it from Windows 10 i used Windows Installer Clean Up Utility that can be downloaded from:





Then next set of errors appeared:

It appears that “Windows Phone SDK 8.0 Assemblies for Visual Studio 2017” and “IIS 10.0 Express” are producing problems.

So back to Windows Installer Clean Up Utility











Another error pops up:

So next thing I tried is to remove both Web deploy packages.








Unfortunately that did not work 🙁


So i went to the Microsoft site:


and downloaded x64 version of WebDeploy 3.6 and installed it

That did not help either

new log file:

This one lead me to fixing registry. Here is a list of Guids that my account seem to have lost permission for:

Remember to add permission to Administrators group!






Few of them are missing but it will take you a few installation restarts to find them.






Parameterizing Unit Tests using xUnit

xUnit allows our unit test to use parameters, which allows us to test our code for multiple scenarios without needing to write multiple methods with same content.

Let’s look at example from previous lesson

Here we test if 3 + 9 equals 12.

But what if we wanted to test our Add method for multiple scenarios?


We could use InlineData Attribute.

InlineData Attribute allows us to run our test with input parameters, and passes those parameters to test method using params object[] data.

We are not done yet.

Compiler is not happy and we are getting error : Fact methods cannot have parameters.

Simple solution is to replace Fact Attribute with Theory Attribute

Now, when we run our unit test we can see that same test method ran 3 times an all test have passed  🙂

Also note that we can also see input parameters!

Beginners guide to xUnit

To add xUnit to your project open up NuGet package manager

(Tools -> NuGet Package manager -> Manage Nuget packages for Solution


Right-click References of your project and chose Manage Nuget packages)

xUnit Nuget installation





And find xUnit package by  James Newkirk and Brad Wilson and press install.

To use xUnit in your project you do not have to decorate your class with TestClass attribute!

You must only decorate your methods with Fact Attribute.

Also be sure to reference Xunit assembly in your class file because xUnit’s Assert class is from that namespace.

If tests you write do not show in Test explorer, open NuGet  packet manager and add xunit.runner.visualstudio package (do not be confused if you see Visual Studio 2012+ in description, it is just saying that this is for version from VS 2012 an onwards).

There is also neat trick to modify name of your tests. By default Test explorer is showing xUnit’s test names in format Class.Method, but you can only display test Method names. Add new json file to root of project and name it “xunit.runner.json” and open properties of that file and under “Copy to Output Directory”  option chose “Copy if newer”.













Open under xunit.runner.json file and under Schema input “https://xunit.github.io/schema/v2.2/xunit.runner.schema.json”, then inside brackets type “methodDisplay”: “method”.





Happy unit testing 🙂

How to create Unit Test with VisualStudio 2017

This brief tutorial will show you how to create Unit Test with VisualStudio 2017.

There are a few ways to create unit test using VS 2017.

1) Create unit test From the class

Create new Console Application

And in a Program class add public method.

Right click on a method and chose “Create Unit Tests”.

How to add an Unit test project from a class.







Be sure to add a public method because without it you will get an error:

Create Unit Tests is supported only within a public class or a public method

An error is pretty straight forward 🙂

"Create Unit Tests is supported only within a public class or a public method" error.

Error you get when adding Unit test project from an empty class or class that has only static members.





Then you can chose additional options or additional Testing frameworks

Unit test options






2) Manually adding a test project

Create new method that returns string with value test.

Right click solution and add Unit Testing project

Choosing unit test project







Then add an reference to project you wish to unit test

And create a new class ProgramTests

Decorate class with a [TestClass] Attribute

Also add a ShouldReturnTestString void method decorated with a [TestMethod] Attribute

Be sure to add those Attributes because without them you will not be able to run unit test. Give it a shot.


DataContractSerializer made its first appearance with release of WCF but can operate outside WCF.

DataContractSerializer can serialize types decorated with DataContract, MessageContract, Serializable attributes, types that implement IXmlSerialisable and all public types without Attributes.

During serialization Reference integrity is by default not preserved. You can preserve it by setting “IsReference = true” to DataContract attribute. Note that this approach my cause problems if DataContractSerializer is not serializer who will deserialize data.


You can also use OnSerializing, OnSerialized, OnDeserializing, OnDeserialized Attributes to fine-grain your serialization process.

This tutorial will explain how to serialize and deserialize types by decorating type with DataContract attribute.

First we use need to add reference to System.Runtime.Serialization. Secondly we decorate the type with DataContract Attribute, and inside type wee decorate fields and properties with DataMember Attribute. Then we instantiate DataContractSerializer instance and use its WriteObject and ReadObject methods to serialize/deserialize data.

Example of DataContractSerializer:

By using DataMember Attribute we can serialize automatic properties, because property itself will be serialized and not its backing field.

Because DataContractSerializer does not store type and assembly information we need to tell it which is the type we wish to serialize by specifying type in the DataContractSerializer constructor.

As no type or assembly information are preserved be sure to supply KnownType  Attribute to your base class to be able to use inheritance properly.


Data Contract Serializer


You can download solution from this link.

To return to other serialization techniques return to this location.

Binary serialization

Today’s topic is Binary serialization, if you wish to read more about serialization or other types of serialization please visit this link:

Binary serialization is type of serialization where type fidelity and reference integrity are preserved, meaning assembly information, private and public fields are being preserved as well as theirs memory locations. You would normally use binary serialization to preserve application state, store it to a backing store (storage medium) and use it later to run application on same computer or maybe multiple other computers.

Hearth of binary serialization is BinaryFormatter class and its Serialize and Deserialize methods. Serialize and Deserialize  methods take two parameters stream and object graph and serialize or deserialize object accordingly. Result of serialization are unreadable to human eye but you can read some information:

Binary Formatter

BinaryFormatter serialization result

As you can see type and field information are preserved.

If you wish serialized data in more readable way you can use SoapFormatter. Note that SoapFormatter is obsolete so use it only for debugging and testing purposes.


SoapFormatter serialization result

To mark a type serializable use Serializable attribute to decorate type. Serializable attribute is not inherited so if you wish to serialize both base and derived class decorate both of them with serializable attribute. Other approach would be to implement ISerializable interface.

If you wish not to serialize filed add NonSerialized attribute.

You can serialize null types, but you can not serialize or deserialize null streams.

Properties are not serialized but their private fields are. Do not serialize auto implemented properties because you cannot guarantee that theirs private fields will have the same name on the other machines as they do on yours.

If we wish more control during Serialization/Deserialization processes we can use attributes from System.Runtime.Serialization and apply them to the methods.
Attributes we can use for methods during serialization:
OnSerializingAttribute – use this attribute to prepare data before deserializing . For example encrypt password field or change distance from miles to kilometers.
OnSerializedAttribute – restores type to a status it was before applying OnSerializingAttribute.

Attributes we can use for methods during serialization:
OnDeserializingAttribute – because serialization cannot use constructor, use this attribute for method that will simulate constructor, and maybe set fields to default values.
OnDeserializedAttribute – use this attribute to manually set value of the fields just after serialization process has finished.


Example for Binary serialization.

We will try to serialize data from Employee class:



Download link for entire solution is here.

© 2021 LearnC#WithDarko

Theme by Anders NorenUp ↑