Archive
GitHub Copilot | Code suggestions
If you are a developer, Isn’t the below visual is scary good? You declare a function with meaningful name and the code is ready for you as a suggestion. Say ‘Hi’ to GitHub Copilot code suggestions.
About GitHub Copilot:
- GitHub Copilot is an AI pair programmer that offers autocomplete-style suggestions as you code.
- It is optimized to help you write Python, JavaScript, TypeScript, Ruby, Go, C#, or C++.
- GitHub Copilot is available as an extension in Visual Studio Code, Visual Studio, Neovim and the JetBrains suite of IDEs. For more information, see “Getting started with GitHub Copilot.”
Licensing:
- GitHub Copilot is available to GitHub customers with a personal account on GitHub.com.
- GitHub Copilot is free to use for verified students and maintainers of popular open source projects.
- If you are not a student or maintainer of a popular open source project, you can try GitHub Copilot for free with a one-time 60 day trial.
- After the free trial, you will need a paid subscription for continued use.
- For more information, see “About billing for GitHub Copilot.”
GitHub Copilot as Visual Studio Extension:
- You must have Visual Studio 2022 17.2 or later installed.
- In the Visual Studio toolbar, click Extensions, then click Manage Extensions.
- In the “Manage Extensions” window, click Visual Studio Marketplace, search for the GitHub Copilot extension, then click Download.
- Refer link for more details.
🙂
[Quick Tip] Short cut to open ‘Command Prompt’ pointing to a folder
In this article, lets learn a shortcut to open Command Prompt pointing to a folder from a Windows OS machine.
Regular Approach:
- To open a folder from a different drive than C, we use the following approach to point to the folder.
- Above example, I am pointing the Command Prompt to “D:\E\Practice\S2S\packages\Microsoft.CrmSdk.XrmTooling.PluginRegistrationTool.9.1.0.24\tools” folder using ‘cd’ command.
Shortcut:
- Go to the folder you want to point the Command Prompt to, and hit cmd.
- ‘Command Prompt’ window opens up pointing to the folder you hit the cmd from.
🙂
StyleCop error – The parameter is incorrect
Other day, I encountered following error while triggering ‘Run StyleCop‘ from Visual Studio.
Reason & Fix:
- In my case, I cloned a DevOps branch and ran the ‘Run StyleCop’ without building the code.
- Since there were no executable’s, StyleCop thrown error ‘The parameter is incorrect‘.
- Build the solution and ‘Run StyleCop’ should fix the issue.
🙂
Obsolete Secure Communications Protocol Supported – InfoSec – Fix
Last week our web application (i.e., ADX portal website) underwent Penetration testing (Also called ‘Ethical hacking’) and we got following recommendation:
Disable all affected protocols identified above. If possible, implement TLSv1.3, or TLSv1.2 otherwise.
Reason:
- In our application’s web server (IIS), TLSv1.0 and TLSv1.1 communication protocols were enabled.
- TLSv1.0 and TLSv1.1 were deprecated in major browsers as of Q1 2019 and will be disabled completely in early 2020.
Fix:
- We’ve used IIS Crypto tool to disable TLSv1.0 and TLSv1.1 protocols.
- IIS Crypto is a free tool that gives administrators the ability to enable or disable protocols, ciphers, hashes and key exchange algorithms on Windows Servers.
- Download the IIS Crypto GUI tool in your windows server where your application is hosted.
- Open the tool and un-check TLSv1.0 and TLSv1.1 options.
- You must restart the server for changes to take effect.
🙂
C# Error while calling API – Could not create SSL/TLS secure channel
Other day, we were getting following error while calling SSL enables 3rd party API from C# console.
The request was aborted: Could not create SSL/TLS secure channel
Fix:
- Add below statement before making your API call, which validates the SSL certification.
ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
- Include following namespaces
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
🙂
Post a File and Data to SandBlast API using Postman and generate C# code
We got a requirement to use SandBlast Threat Extraction process, for cleansing the files.
SandBlast Threat Extraction, is a solution by ‘Check Point’ company, which removes exploitable content, including active content and embedded objects, reconstructs files to eliminate potential threats.
‘Threat Extraction’ Upload API, requires following parameters
- Header
- Authorization
- Content-Type
- Body
- File Content
- request (This is string)
If you notice, we need to pass ‘File’ as well as ‘Data’ to the API.
As of now, Sandblast doesn’t have a native .Net library to make API calls. So I’ve used Postman tool as a starting point for my development.
Below is the step-by-step, to pass ‘File’ and ‘Data’ in request ‘Body’, using Postman
- Open Postman tool
- Create a new ‘Request’
- Set the method as ‘Post’ and URL.
- From the ‘Body’ tab, select ‘form-data’ option
- To pass the ‘File’, add a new ‘KEY’ of type ‘File’ and browse the file in ‘VALUE’ parameter.
- To pass the ‘Data’, add a new ‘KEY’ of type ‘Text’ and set the ‘VALUE’
Generate C# code from the Request:
- Postman has an amazing feature to generate the code in your required language.
- Click on ‘Code’ link and for C#, choose ‘C# (RestSharp)’ option.
- In your C# project, add RestSharp NuGet package.
- Paste the code in your class file and you are good to go now.
If anyone having struggling to use Sandblast API’s, post in comments section and I will address.
🙂
HTML & JScript – Read and Encode file
We got a requirement in ADX portal, to read and convert the file content to Base64String , which eventually will be submitted to an external API.
Below is the code snippet to read the File content, browsed using the HTML ‘File Upload’ control:
function readFileAsText(){
try {
// Read the browsed file from ‘File Upload’ control.
var fileToLoad = document.getElementById(“fileOE“).files[0];var fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
// Set the file content to variable
var textFromFileLoaded = fileLoadedEvent.target.result;
alert(“File Content – ” + textFromFileLoaded);// Using ‘window.btoa’ encode the plain text to Base 64
var convertedString = window.btoa(unescape(encodeURIComponent(textFromFileLoaded)));
alert(“Base 64 content – ” + convertedString);
};fileReader.readAsText(fileToLoad, “UTF-8”);
} catch (e) {
alert(“Error in readFileAsText(); Error – ” + e.description);
}
}<body>
<label for=”fileOE”>Pick the file </label><br>
<input type=”file” id=”fileOE” />
<input type=”button” value=”Upload” onclick=”readFileAsText()” />
</body>
- Execute the code and you will get output as below

File content as text

Encoded File Content (Base 64)
🙂
Unable to install ‘Windows Service’ using installutil.exe
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
Other day, I was getting below “The Linked file isn’t available” pop-up, while opening a word document shared by client.
Reason:
- 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.
Fix:
- 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.
🙂
[Log4net] Exception while reading ConfigurationSettings
We were using Log4net logging framework to log exceptions in our web application and encountered below exception during the log:
Reasons:
There can be many reasons right from misplacing Log4net config settings to not loading the config file.
Fix:
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:
<configuration>
<configSections>
<section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler,Log4net”/>
</configSections>
<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”/>
</layout>
</appender>
<root>
<appender-ref ref=”General”/>
</root>
</log4net>
<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.6.1″ />
</startup>
</configuration>
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){
try{
Log.Info(“Log Starts”);
// Throw error
throw new Exception(“Exception!!!!”);
}
catch (Exception ex){
Log.Error(“Error – ” + ex.Message);
}
finally{
Log.Info(“Log Ends”);
Console.ReadLine();
}
}}
- Execute the logic and you should get a log file stored in specified location with logs
Refer article for Log4net best practices.
🙂