Posts Tagged ‘C#’

To get the identity from the insert when using dapper return the SCOPE_IDENTITY

So far has been working reasonably well.

Example below:



So I spend a lot of time with NServicebus and one thing I have come to recognise is that it is a configuration nightmare. Actually truth be told I no longer like dealing with NServicebus simply because during each month that passes I need to learn another way to configure something that was already configured.

Case and point.
Start NServiceBus and greated with
”  Additional information: NServiceBus performance counter for Critical Time is not set up correctly. “


In a previous post of mine I was super excited about using the stackframe for log tracing of calling methods stackframe

I’d now like to fast forward to c# 5.0 System.Runtime.CompilerServices

Using the compiler service we can skip the expense stackframe opperation and simply use optional parameters

So we now simply have:

//using compiler servers to get method name, file and line number

public static void WriteDebug(string message, [CallerMemberName] string callerMemberName = "", [CallerFilePath] string callerFileName = "", [CallerLineNumber] int callerLineNumber = 0)
Console.WriteLine("{0} {1} ({2} - {3}) - {4}", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss:fff"), callerMemberName, callerFileName, callerLineNumber, message);


I was curious about how nUnit compared to MsTest on paper.

So I composed a quick list of stuff found on the net and ran a quick project in both…


Hudson vs CC.Net

Posted: 2010-02-04 in Code and Computers

I posted a few months ago about using CruiseControl .Net in article “Continuous Integration – CC .Net”. The article was a bit long winded but the idea behind it was that Continous Integration is a must have for any sized development team.

Enter today, CI is still a must but today I swap my dagger to a sword called Hudson.

You see the major problem with CC.Net was its ability to spawn, well actually its inability. With the additional work load we had no way to ease the pain on the build server by giving it slaves. TeamCity has this abilty as does Hudson. Added to this issue with the constant “hacking” required to keep CC.Net update or even installed and you start getting a installation headache.


If you have the need in C# to get the calling method name, then use System.Diagnostics StackFrame.
Stack frame has a ton of useful debugging goodies, including line numbers, columns, calling assemblies, etc.

A quick example

//Get the method name of the caller (its two up, this plus the public)

StackFrame debugginInfo = new StackFrame(2);
string methodName = debugginInfo.GetMethod().ReflectedType.Name + "." + debugginInfo.GetMethod().Name;
raiseMessage = methodName + ": " + message;

This code is a small excert from my little static logger friend. If the caller passes in a debug log then the calling class and method name is prefixed to the logged message. The reason the 2 is passed in is because this is a private method (1) and is called from several overloaded public methods (+1 = 2).
Its a very clean ,very good solution when stack tracing a client log, without relying on the log caller to pass in descriptive location information.


What do blind people dream about

Singletons are bad umm ok!

Posted: 2009-08-17 in Code and Computers

Really I think the title says it all but let’s turn this from a statement to a theory.

Ok so why are singletons bad?

Global variables are bad right? Variables that inadvertently allow any code with access the ability to indirectly changing other code relying on the same variable. Problems that are also amplified with multi threaded applications (Google C# keyword volatile for more information).

So if everyone blindly takes global variables as being bad then why can’t people see that singletons are bad (umm ok).