Thursday, October 15, 2015

Windows 10 – BSOD on resuming from hibernate

After upgrading my machine to Windows 10, I found that after I hibernated by computer, it would always BSOD on resuming with the error: SYSTEM_SERVICE_EXCEPTION (cng.sys). After a whole bit of troubleshooting and nothing working, I found an old post regarding a similar failure on Windows 7. It suggested turning off Hyper-V (via Windows Features).


Turning it off on my Windows 10 machine, seemed to make the BSOD issue go away.

Monday, September 28, 2015

Importing Windows Event Log into SQL Server

LogParser is your friend:

Here is a sample command to import the data into SQL Server:

LogParser -i:EVT "SELECT * into prodEvents FROM  c:\temp\prod.evtx" -o:SQL -server:sqlServerName -driver:"SQL Server" -database:testDb -createtable:ON  -cleartable:ON -transactionRowCount:-1  -maxstrfieldlen:8000

note: use -username:test -password:test to specify username and password if you need to.
note: I cant seem to find a way around the 8000 character limit in LogParser. So it always truncates at 8000 characters :(

The table definition is:

CREATE TABLE [dbo].[prodEvents](
    [EventLog] [varchar](8000) NULL,
    [RecordNumber] [int] NULL,
    [TimeGenerated] [datetime] NULL,
    [TimeWritten] [datetime] NULL,
    [EventID] [int] NULL,
    [EventType] [int] NULL,
    [EventTypeName] [varchar](8000) NULL,
    [EventCategory] [int] NULL,
    [EventCategoryName] [varchar](8000) NULL,
    [SourceName] [varchar](8000) NULL,
    [Strings] [varchar](8000) NULL,
    [ComputerName] [varchar](8000) NULL,
    [SID] [varchar](8000) NULL,
    [Message] [varchar](8000) NULL,
    [Data] [varchar](8000) NULL

Keep in mind that you can run many SQL like queries directly against the EVT file locally on your machine without importing the data into a table.

Other useful queries:

logparser.exe -i:evt "select * from c:\temp\prod.evtx where timegenerated > '2015-09-01 00:00:00'"

More info:

Useful commands and tips: (for, but useful even for Event Logs)

Monday, March 30, 2015

Visual Studio rebuilds all projects instead of just the projects referenced by the current project

One of our Visual Studio solutions all of sudden started building all projects in the solution, even when I was trying to build one single project.

I found that Visual Studio allows you to set a flag in the registry that allows you to see more information regarding why it thinks a project is out of date and is trying to build it. The setting is called: U2DCheckVerbosity, which I believe stands for “Up to Date Check” verbosity level. By setting it to a value of 1, you get information in the output window that specifies why VS believes a project is not up to date and is causing it to build.

You can either create the new key manually, or copy the following text into notepad and save it as a REG file and run it.

Windows Registry Editor Version 5.00


Once thats done, if you look in the output window, you will see messages like:

Project ‘xxxxxx’ is not up to date. Project item ‘some_file_path\log4net.config' has 'Copy to Output Directory' attribute set to 'Copy always'.

I had not realized that “Copy Always” would cause a project to consider itself dirty and had gone through and set it on some config files I had recently added. So it turned out, it was I that was at fault. Fixed the config issue and everything is good now.

Wednesday, June 11, 2014

The ASP.Net MVC 5 Application Lifecylce


Highlevel Overview:


Detail – Execution pipeline:


HTTPApplication Processing Pipeline


HttpApplication Processing Pipeline – Process of request (MvcHandler executes the controller action)








Sunday, June 01, 2014

Please do not implement a finalizer willy-nilly!

I see many people implement the finalizer when they implement the dispose pattern in c#.

class MyDisposableClass : IDisposable
   public void Dispose()

   protected virtual void Dispose()


Please don’t do this (implement the finalizer)  unless your class uses unmanaged resources! One reason for this is that if you access managed resources in your Dispose method, they may have already been garbage collected if the Dispose method was called via the finalizer!

Here are some things to consider: (all pulled from MSDN documentation)

  1. The dispose pattern is used only for objects that access unmanaged resources, such as file and pipe handles, registry handles, wait handles, or pointers to blocks of unmanaged memory. This is because the garbage collector is very efficient at reclaiming unused managed objects, but it is unable to reclaim unmanaged objects. (
  2. Finalizers are notoriously difficult to implement correctly, primarily because you cannot make certain (normally valid) assumptions about the state of the system during their execution. (
  3. If a type does override the Finalize method, the garbage collector adds an entry for each instance of the type to an internal structure called the finalization queue. The finalization queue contains entries for all the objects in the managed heap whose finalization code must run before the garbage collector can reclaim their memory. The garbage collector then calls the Finalize method automatically…. (

Remember: Finalizers are typically not needed and even when needed there are better patterns available that allow you to side-step implementing the finalizer (eg: SafeHandle).


  1. Even if you implement the Finalizer “correctly” such that when you call Dispose, it only cleans out unmanaged resources, if you don’t have unmanaged resources, you have introduced a tiny performance penalty into your app and allow someone else to introduce bugs. So if you see a finalizer, check to see if you REALLY need it and if you don’t, get rid of it (and maybe even the implementation of the IDisposable interface.
  2. Sometimes the Dispose pattern is implemented to free up managed memory being used by the class. Again if you have written your code well, you should be able to rely on the .Net garbage collector to free up the memory for you.

Correctly implemented Dispose pattern

class CorrectlyImplementedDisposableClass: IDisposable
   bool disposed = false;

   public void Dispose()

   protected virtual void Dispose(bool disposing)
      if (disposed)

      if (disposing) {
         // Free any other managed objects here.  }

      // Only Free unmanaged objects here.  disposed = true;
class CorrectlyImplementedFinalizedClass: CorrectlyImplementedDisposableClass

Thursday, March 13, 2014

SPNs required when using Kerberos auth for Windows Auth on an website

To use Kerberos authentication

  • Internet Explorer security settings must be configured to enable Integrated Windows authentication. To enable the browser to respond to a negotiate challenge and perform Kerberos authentication, select the Enable Integrated Windows Authentication check box in the Security section of the Advanced tab of the Internet Options menu, and then restart the browser.


  • If a custom service account is used to run the ASP.NET application, then a Service Principal Name (SPN) must be registered for the account in Active Directory.

To register an SPN, use the Setspn.exe utility by running the following commands from a command prompt:

setspn -A HTTP/webservername domain\customAccountName

setspn -A HTTP/webservername.fullyqualifieddomainname domain\customAccountName

Thursday, February 13, 2014

Disabling ChromeDriver logging output

I was trying to figure out how to turn of the logging that the Selenium ChromeDriver was performing and had a hard time doing that.

Chrome Driver Logging Output

I finally figured out how to do it with the following code (the key line of code is highlighted):

		private IWebDriver CreateChromeDriver()
			ChromeOptions chromeOptions = new ChromeOptions();
			return new ChromeDriver(chromeOptions);

Saturday, December 21, 2013

Installing Amazon App-Store on Google Nexus 7

I wanted to use the Amazon app-store on my Google Nexus 7 tablet (mainly because I already have quite a few apps that I have bought for a previous Kindle Fire). So here is how to get the amazon app store on your Nexus device.

First, you need to enable installing of apps from stores other than the Google Play Store. To do this, go to Settings and  select Security. Under Device Administration, make sure “Unknown Sources” is selected.

Second, install the Amazon App Store. To do this, down the “apk” file from Amazon from: (There is additional information on Amazon’s page).

Thursday, December 12, 2013

CRM 2011–MSCRMKeyGenerator– Key not being regenerated correctly

Recently in a dev environment, when I tried to bring up our CRM environment, I was getting the following error:


Not very helpful. But if I look at the URL:


So there is certainly something weird going on here.

Looking at the application logs in the event viewer I found the following error:

Current key (KeyType : CrmWRPCTokenKey) is expired.  This can indicate that a key is not being regenerated correctly.  Current Key : CrmKey(Id:GUID, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:11/03/2013 17:47:19, ExpiresOn:12/06/2013 17:47:19, CreatedOn:11/03/2013 17:47:19, CreatedBy:NT AUTHORITY\NETWORK SERVICE.

After some googling, I found that the reason for this was that the “Microsoft Dynamics CRM Asynchronous Processing Service” may not be running. Which indeed was true in my case. But, after restarting the service, it still was not working.

The final thing that I had to do was issue an iisreset against the server hosting CRM.

Tuesday, December 10, 2013

Custom Rules in Fiddler

I needed to setup a filter in Fiddler so that I could view only JSON requests being made from my application. The default filter doesn’t allow for viewing only JSON requests. But luckily Fidller allows you to setup custom rules. Here is what I did:

Within the class “Handlers” add the following lines of code:

public static RulesOption("Display Only &Json Requests")
var m_bShowOnlyJsonRequests: boolean = false;

The above lines will add a Menu option under rules, that will easily allow you to turn on or off the JSON filtering.


Next, within the method: static function OnBeforeRequest(oSession: Session), add the following lines of code:

if (m_bShowOnlyJsonRequests && oSession.oRequest["Content-Type"] != "application/json"){
                oSession["ui-hide"] = "true";

The above lines of code allow filters to display only those sessions that have a content-type header set to “application/json”.

As simple as that!


1. The biggest problem that I have found is that there is hardly any documentation regarding the methods and properties available within the script file or off the oSession object (which is of type Session).

2. I think the script is based of JScript. I just wrote my code to resemble C# and it worked for my simple filter.

3. Samples from FiddlerBook site:

4. Fiddler Script Editor is a pretty good tool that can help writing complex rules (it provides some documentation, though it wasn’t always helpful).

5. More Samples:

6. Session object properties/flags: