Monday, 31 August 2020

How to Solve CMake was unable to find a build program corresponding to MinGW Makefiles

You may have a situation that requires you to use CMake to build a source code and then got hit with an error while executing a cmake command, which is something similar as shown below.

C:\SomeProject>cmake . -G "MinGW Makefiles"

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

-- Configuring incomplete, errors occurred!

There are few possibilities that may lead to this

1. Mingw-w64 is not installed

Since the error message mentioned that it is not able to find "MinGW Makefiles". Which mean that there is a possibility that you have not installed it to your machine. So, you may want to download the installer from here http://mingw-w64.org/doku.php and install it.

2. Installed Mingw-w64 but still showing the same error message

Most likely due to the installer did not place the necessary Mingw-w64 information to the %PATH% Environment Variables. So, you are required to fill in the Mingw-w64's bin path manually. To navigate to the Environment Variables:

a) In your Windows Search, search for the following keyword "Environment Variables" and select "Edit the system environment variables".

b) When the window "System Properties" appeared. Click on the button "Environment Variables".

c) On the next window, under the System variables section, look for the variable named "Path". Select it and click the Edit button.

d) In the Edit environment variable window, click New button and fill in the bin path of the Mingw-w64. Depend on the settings that you have picked during the Mingw-w64 installation, the default location of the Mingw-w64 can either be in Program Files or Program Files (x86).

Some of the example location:
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin
C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin

If you have multiple settings of Mingw-w64 installed, just pick 1 of the path based on the setting that you required. 

e) Once you are done, save your configured path by clicking on the Ok button to close the "Edit environment variable" window. On the "Environment variable" window, click Ok button to close the window.

If you have command prompt opened while editing the %PATH% Environment Variables, you are required to close them all and open up a new command prompt. This is due to the old command prompt caches the previous %PATH% settings.

This is all that you need to do and the error should no longer appear.





Friday, 7 April 2017

[Web Farm][Network Load Balancing] Unable to Serialize the Session State C# & VB

Do you faced a situation where you are required to host the same ASP.NET web application to multiple servers (Web Farm) to divide traffic into different servers due to high amount of traffic? Due to this, you configured the <sessionState> to use SQLServer in your web configuration file. While you are performing verification on your application, somehow you stumble upon an error as shown on the following image.


Based on the error "Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable object or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.", it basically means that when the <sessionState> is configured to use SQLServer, make sure that any object used to assign into Session must be decorated with serializable attribute.

Further read on the error, the key sentence "Type 'WebNLB.TestClass' in Assembly 'WebNLB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]". This tells you that you have a class name called TestClass and it doesn't have the attribute serializable. So add the serializable attribute to the TestClass.

[C#]
[Serializable]
public class TestClass
{

}

[VB]
<Serializable> Public Class TestClass

End Class

Do the same to your application. Make sure to add serializable attribute to all the classes that are used to assign into Session. Once you are done, redeploy your application to each of the servers and re-verify your application. You will notice that your application will no longer hit the error again.

Wednesday, 29 March 2017

[MSDTC] How to Setup Microsoft Distributed Transaction Coordinator

Ever faced a situation where you need to make changes to a record in 2 different SQL Server databases that are located in two different instances in different servers and need to ensure the changes made to the both of the databases are successful before commit? Before you can do so, you need to configure Microsoft Distributed Transaction Coordinator (MSDTC) and this post will guide you on how to do so.

This post will not go into what is MSDTC, but if you're curious and want to know what it is all about, do check out the following links.
https://msdn.microsoft.com/en-us/library/aa940166(v=winembedded.5).aspx
https://blogs.msdn.microsoft.com/florinlazar/2004/03/04/what-is-msdtc-and-why-do-i-need-to-care-about-it/

There are few things that you need to know before configuring MSDTC.
  • The MSDTC need to be configured on all servers that are involved in the transaction.
  • If you're using transaction in C# / VB with TransactionScope and requires to make changes to 2 databases located in two different instances in different servers, in this case, MSDTC has to be configured on server that launch the application & the 2 database servers. (Total 3 Servers)
  • If you're using transaction in trigger or stored procedure that make changes to its own database and another database located in another server, in this case, MSDTC has to be configured on the 2 database servers.
  • Firewall clearance for all servers that configure MSDTC.

The following steps will only shows the minimum settings required for the distributed transaction to work. If you need or requires the other settings, do not hesitate to make changes accordingly.
1) Open up run window, type mmc and click OK button.


2) Once the MMC console launched, select File which is located at the top menu, click Add/Remove Snap-in...


3) On the Add or Remove Snap-ins window, under Available snap-ins list box, look for Component Services, select it and click Add > button or double click it. It will then appear under Selected snap-ins list box. Once you are done, click OK button.


4) Back to the MMC console window. On the left pane, expand Component Services node, Expand Computers node, right click on My Computer and click Properties.


5) On the My Computer Properties window, select MSDTC tab, tick Use local coordinator and click OK button.


6) Back to the MMC console window, further expand My Computer node, expand Distributed Transaction Coordinator, right click on Local DTC and click Properties.


7) On the Local DTC Properties window, select Security Tab.
Tick Network DTC Access.
Tick Allow Inbound,
Tick Allow Outbound (This is not required for servers that which did not initiate the transaction). Once you are done, click OK button.

Note: The following figure shows the minimal settings required. If you requires the other settings, do not hesitate to change it.


The following steps guide you on how to allow MSDTC to pass through firewall

1) Open up firewall window and select Allow an app or feature through Windows Firewall located at the left pane.


2) Look for Distributed Transaction Coordinator, tick private / public / both depending on whether your transaction is in private / public / in both network. Click OK button.


That is all for the configuration part. Now, to verify whether your MSDTC has been configured successfully, you can test it out based on one of the following.

1) Connect to one of the database server with SQL Server Management Studio, Write a BEGIN TRANSACTION statement to make data change to current database and another database in different server with linked server.

2) Use the TransactionScope Class in C# / VB to make changes to 2 different database servers.