Archive for the ‘Misc’ Category

Unable to install ‘Windows Service’ using installutil.exe

February 4, 2019 Leave a comment

The other day, I was using Installutil.exe from Command Prompt (refer below command), to install my Windows Service.

C:\Windows\Microsoft.NET\Framework\v4.0.30319>InstallUtil.exe -i “X:\XX\XXX.exe”

Although the tool was giving success response, Windows Service was not getting installed and not being listed in ‘Service Manager’ console.

Alternate Option:

  • While troubleshooting the issue, we came across another option to install the Windows Service using “SC Create

Using SC Create:

To install Windows Service,

  • Open the Command Prompt in ‘Run as administrator’ mode.
  • Below is the syntax using ‘SC Create’ to install the service.

C:\Windows\system32>SC Create “{Your WinService exe name}” binpath=”{Your WinService exe path}” displayname=”{Your desired name}


Using SC Delete:

To Uninstall the ‘Windows Service’,

  • Open the Command Prompt in ‘Run as administrator’ mode.
  • Below is the syntax using ‘SC Delete’ to Uninstall the service.

C:\Windows\system32>SC Delete “{Your WinService exe name}



[MS Word] The Linked file isn’t available

December 19, 2018 Leave a comment

Other day, I was getting below “The Linked file isn’t available” pop-up, while opening a word document shared by client.



  • Word document has charts and graphs controls embedded, which were rendering based on the data from another excel sheet.
  • Excel sheet had configured as a linked file in the Word document
  • Since Excel sheet was not shared by client in the first go, Word document was showing “The Linked file isn’t available” popup.


  • Once you got the link file (i.e., Excel sheet in my case), below are the steps to fix, if you are still getting the popup.
  • From Word document, click on File -> Info -> Related Documents -> Edit Links to Files


  • In the ‘Links’ window, either click on ‘Change Source’ to correct the ‘Link file’ path or click ‘Break Link’ button if you want to remove the files link.


  • Once the file paths are corrected, click on ‘Update Now’ to reflect the changes in Word document
  • Now, Word document should open with no “The Linked file isn’t available” pop-up.


Categories: Misc Tags: ,

[Log4net] Exception while reading ConfigurationSettings

December 16, 2018 Comments off

We were using Log4net logging framework to log exceptions in our web application and encountered below exception during the log:



There can be many reasons right from misplacing Log4net config settings to not loading the config file.


Below is the step by step approach on how to use Log4net framework.

Install Log4net NuGet package:

  • From Visual Studio, open Tools -> NuGet Package Manager -> Manage NuGet packages for solution…


  • Search for ‘Log4net’ and install the package


Add configurations in App.config/Web.config:

  • In your App.config/Web.config file, add a new config section named ‘log4net’. Make sure <configSections> is the first node under root <configuration> node.
  • Add <log4net> node with details like Path where you would like to store the logs and other properties.
  • Your App.config/Web.config file looks as below:

<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler,Log4net”/>
<appender name=”General” type=”log4net.Appender.RollingFileAppender”>
<file value=”D:\log.txt“/> <!–Physical path to log files–>
<appendToFile value=”true”/>
<rollingStyle value=”Size”/>
<!– Specifies the number of files that will be written. This is an example for ten files. The files will be named engine.log.1, engine.log.2, engine.log.3, etc. –>
<maxSizeRollBackups value=”50″/>
<!– The File Size limit for each file. KB stands for Kilobytes, MB (MegaByte) is also an option. –>
<maximumFileSize value=”5MB”/>
<staticLogFileName value=”true”/>
<layout type=”log4net.Layout.PatternLayout”>
<conversionPattern value=”%date %-5level – %message%newline”/>
<appender-ref ref=”General”/>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.6.1″ />

Using Log4net in your code:

  • We need to load the Log4net configurations defined App.config file in class file using below statement
    • Below statement can be either placed in your Class file or project’s “AssemblyInfo.cs” file

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

  • Define LogManager Object using below statement

private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

  • Use Log.Info(“”) to log info and Log.Error(“”) to log exception details.
  • With above specified statements your class file looks as below


using log4net;

// Load Log4net configurations defined App.config file
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Log4Net{
class Program{
// Define LogManager Object
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

static void Main(string[] args){
Log.Info(“Log Starts”);
// Throw error
throw new Exception(“Exception!!!!”);
catch (Exception ex){
Log.Error(“Error – ” + ex.Message);
Log.Info(“Log Ends”);

  • Execute the logic and you should get a log file stored in specified location with logs


Refer article for Log4net best practices.


Categories: Misc Tags: ,

Troubleshoot and Fix – Unable to access FTP folder error

September 12, 2018 Leave a comment

I was working on a POC/Prototype to read files from FTP location using console, for which I configured a FTP Site in my Windows 10 machine’s IIS.


FTP site connectivity worked fine till I switched my internet connectivity from LAN cable to WIFI, I started getting unable to access the FTP location error, when I access the FTP url from my console application.

Reason & Fix:

  • During the FTP web site configuration, we have to provide the “IP address:” which is specific to the machine.


  • When I switched from LAN to WIFI, my machine’s “IP address” has got changed.
  • Providing the correct “IP address” in ‘FTP web site’ binding solved the issue.
  • To check the “IP Address” of the machine
    • Open the ‘Command Prompt’
    • Execute ‘ipconfig‘ command
    • Copy the IP Address from “IPv4 Address”
    • Set the copied IPv4 Address in ‘FTP web site’ binding in IIS.


Refer this article on how to set up FTP website.



DataTable – Destory() method not removing all the rows

In one of my Dynamics portal’s requirements, I had to use Data Tables table control to bind the search results.


I used below snippet to bind the results.

var table = $(‘#customGrid‘).DataTable({
data: rows,
destroy: true,
columns: columns,
oLanguage: {
sLengthMenu: ‘Show _MENU_ items’,
sInfo: ” <b>Showing _START_ – _END_ of _TOTAL_ items</b>”,
sInfoEmpty: ‘ <b>Showing 0 – 0 of 0 items</b>’,
sEmptyTable: “No data to display”
‘columnDefs’: [

In the above snippet

  • #customGrid – Is ID of a HTML <Table> object which we use for DataTable.
    • <table id=”customGrid” class=”display”></table>
  • rows – JSon collection

Problem statement:

I am using ‘DataTable’ in one of my custom HTML Search pages

  • I was binding the Search results to the DataTable up on Search button click and have to clear the previous results when no match results found.
  • I was calling destroy() function to clear off the rows from previous Search.

if ($.fn.DataTable.isDataTable(“#customGrid”)) {

  • However, destroy() its not removing all the rows.

Reason and Fix:

  • destroy() remove all defined events and properties of DataTable object.
  • Its not clearing the <table> object rows (This may have fixed or changed in latest versions)
  •  So, to clear the rows, you must call empty() function of <table> object.
  • Below is the final code

if ($.fn.DataTable.isDataTable(“#customGrid”)) {
     // Destroy ‘DataTable’ object
    // Remove the <table> rows


Categories: Misc Tags: ,

Data Tables – Error – Non table node initialization

In one of my Dynamics portal’s requirements, I had to use Data Tables table control to bind the search results.

After referring helper files and configured the ‘Data Tables’ table control in my HTML, I encountered below error during the run:

Data Table - Error

Reason & Fix:

  • ‘Data Table’ table control requires a <table> place holder in the HTML page, which will get rendered with result set (i.e., json collection) in run time.

In your <script>:

var table = $(‘#customGrid‘).DataTable({
data: rows,
destroy: true,
columns: columns});

  • If you refer any control (i.e., Div/Span etc…) other than <table> you will get the error.

In your HTML <body>:

<table id=”customGrid” class=”display”></table>

  • I wrongly used <Div> control in my case and replaced with <Table> to fix the issue.


Categories: Misc Tags: ,

‘Duplicate record execution’ issue with System.Timer Elapsed event – Windows Service

We have a window service with System.Timer control ‘timerExecuteQuery’, which periodically polls the records from Data Base and process.

this.timerExecuteQuery= new System.Timers.Timer(3) { AutoReset = true };
this.timerExecuteQuery.Elapsed += this.TimerExecuteQuery_Elapsed;

Everything seems working fine until we noticed few records executing twice causing inconsistency.

The issue was random and unable to reproduce consistently.


  • In our scenario, the culprit was System.Timer’s Elapsed event
  • Our timer’s duration is 3 seconds with ‘AutoReset=true’, so, every 3 seconds Elapsed event kick in and executes the logic.
  • In few scenarios, business logic in ‘Timer_Elapsed’ was taking more than 3 seconds causing the trigger of new Elapsed event before completion of old thread. Hence records got executed more than once randomly.


  • We declared a global Boolean variable ‘executing’ and handled as below.
    • Set variable ‘executing=true’ before Business logic of ‘Timer_Elapsed’ event and set ‘executing=false’ after execution of Business logic.
    • Check the ‘executing’ variable value before the execution of business logic, if its True, return.

private bool executing = false;

protected void TimerExecuteQuery_Elapsed(object sender, System.Timers.ElapsedEventArgs e){

// ‘executing’ true denotes, previous elapsed event was not over
if (executing){

executing = true;

// Business logic
executing = false;