Wednesday, June 19, 2013

Assembly bind failure logging (Fusion) in .NET

The Assembly Binding Log Viewer displays details for failed assembly binds. This information helps you diagnose why the .NET Framework cannot locate an assembly at run time. These failures are usually the result of an assembly deployed to the wrong location or a mismatch in version numbers or cultures. The common language runtime's failure to locate an assembly typically shows up as a TypeLoadException in your application. I use information in this log really often, and I always struggle to find this article of how to configure it. And the steps are:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion
Add:
DWORD ForceLog set value to 1
DWORD LogFailures set value to 1
DWORD LogResourceBinds set value to 1
String LogPath set value to folder for logs (e.g. C:\FusionLog\)

I have to restart my machine before I see results.

Tuesday, June 18, 2013

Disk Usage (QueueLenght) monitoring - why my machine is not responding if CPU and Memory is doing good.

For a last year I saw many times that it is not CPU or Memory that is stopping system from responding quickly, it is hard drive that is the weakest link. A typical QueueLength (number of processes waiting for HD resource) should be around 0.05 or better 0.01 as illustrated below. (In order to see this screen hit open Windows Task Manager (ctr+shift+Esc)-> performance->Resource Monitor->Disk).

But if there are many processes trying to write on hd this diagram looks like this:

It means that HD is a major bottle neck in a system.

Thursday, June 13, 2013

Just Time for .NET

I need to represent just time in .NET, no date. My scenario is that I have a scheduler and I want to run a job 4 times a day at specific hour: 4:00, 10:00, 16:00, 22:00. There is no default data type in .NET to represent this kind of information. DateTime requests from me setting a Date (which is irrelevant in my scenario), and also the simplest DateTime constructor that uses hour also requests from me setting minutes and seconds, which again are irrelevant for me. The simplest constructor using DateTime looks like:
new DateTime(year:1, month:1, day:1, hour:4, minute:0, second:0);

If I try to parse a date from a string and I pass just time a date is set by default to "01/01/01" and I find it silly.
I can use TimeSpan, but this data type was design to keep a span of a time, not a point of a time, and it is really misleading.
The approach I took is to install NodaTime and there is a nuget package. Inside NodaTime there is a class called Period that is meant to represent exactly what I need a period in time. Constructor that I used is listed below.
Period.FromHours(4);

Wednesday, June 5, 2013

ASP.NET strongly typed repeater

Today, I looked at old ASP.NET code, and saw something like this:
<asp:Repeater runat="server" ID="repTourDepartureCache" >
    <ItemTemplate>
        <tr>
            <td>
                <%# Eval("Key") %>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

The problem is that the binding done here is done by so called "magic string". And if someone will change a property name from "Key" to something else this code will stop working. Programmer writing this code was not aware that in .NET 4.5 strongly typed data binding was introduced by using additional attribute ItemType. The above code should look:
<asp:Repeater runat="server" ID="repTourDepartureCache" ItemType="TTC.TT.Entities.ViewModels.PrettyPrintedTourDeparture">
    <ItemTemplate>
        <tr>
            <td>
                <%# Item.Key %>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

There is a full Intellisense support for this kind of binding. And it makes refactoring easier. For generic types ItemType definition looks like:
<asp:Repeater runat="server" ID="repTourDepartureCache" ItemType="System.Collections.Generic.KeyValuePair`2[System.String, System.String]">
</asp:Repeater>