Low Level Design

Be careful with varchars in Dapper!

Posted in CodeProject, Diagnosing ADO.NET by Sebastian Solnica on May 16, 2013

In this post I will show you an interesting problem that we experienced when querying a SQL Server database with Dapper. I will use a simplified data model and a sample application so you could reproduce the issue on your own. Our sample table will look as follows:

create table Stats (
    StatsDay datetime not null,
    EventName varchar(100) not null,
    Item varchar(100) not null,
    Value int null,
    constraint PK_Stats primary key(Item,EventName,StatsDay)
)

(more…)

Making elmah.axd a log viewer for multiple applications

Posted in CodeProject, Logging with Elmah by Sebastian Solnica on March 24, 2013

Elmah is a great exception logger for web applications. Next to the exception data (stacktrace, exception message etc.) it collects detailed request and runtime information. If I also mention that it’s easy to install and highly configurable it comes with no surprise that it became an industrial logging standard for .NET web applications. Elmah gives you a great choice of places where you can send your logs, though a database is the one I consider most useful. What I also value in Elmah is its log viewer (elmah.axd) – it has a nice exception list and a great exception details screen – I wish the ASP.NET Yellow Screen of Death had that look :) . The only thing I don’t really like in this viewer is a fact that by default it is bound to the application that has Elmah installed and is accessible only under http://<app-url>/elmah.axd. If you do not secure access to this handler everyone can see detailed information on your code and environment – just have a look how many developers forget about it. In this post I will show you how to remove the elmah.axd handler from your application and how to create a separate ASP.NET application that would be a central Elmah log viewer for your applications.

(more…)

Tagged with: , ,

Diagnosing ASP.NET views compilation with FrontMan

Posted in CodeProject, Diagnosing ASP.NET by Sebastian Solnica on January 25, 2013

In today’s post I will show you how we fought a pesky compilation problem with Razor views in our ASP.NET MVC application. One of the parts of our application is an email-sending engine which uses Razor templates to create message bodies. After deploying this app on IIS we started receiving the following errors (unimportant parts are stripped):

...
Line: 0\\t Col: 0\\t Error: Metadata file \u0027ev-server/dev2/appname/bin/EmailSystem.Client.DLL\u0027 could not be found

//------------------------------------------------------------------------------
// \u003cauto-generated\u003e
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.235
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// \u003c/auto-generated\u003e
//------------------------------------------------------------------------------
...

The first line suggests that it’s a compilation problem, but we didn’t really know exactly which part of the application was throwing it. I thought having a full compiler command line might help us. Unfortunately gathering it from ASP.NET application is not so easy.

(more…)

Tagged with: , ,

MSBuild: MSB3275 warning, GAC and .NET version

Posted in CodeProject, Diagnosing compilation issues by Sebastian Solnica on January 5, 2013

In this post I will describe for you an interesting problem that my colleague ran into at work. His original VS solution consisted of two projects targeting .NET 3.5 – let’s name them Alpha and Beta. Alpha had a direct reference to Beta and thus depended on it. Beta was using NHibernate, Castle.Core and some other libraries. During compilation Alpha he received:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3258: The primary reference "PathToBeta.dll" could not be resolved because it has an indirect dependency  on the .NET Framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which has a higher version "4.0.0.0" than the version "2.0.0.0" in the current target framework.

and the whole build failed with:

Error 3 The name 'Beta' does not exist in the current context

(more…)

Tagged with: , , ,

Topshelf Windows Service and try-finally

Posted in CodeProject, Diagnosing Windows Services by Sebastian Solnica on December 3, 2012

I recently needed to diagnose an interesting problem with one of our Topshelf Windows Services. The service ended in a StopPending state and we needed to kill it in order to make it work again. But before killing the service we collected a process dump for further analysis. In this post I will show you what I read from this dump and how this information might help you better understand your own Topshelf applications.

(more…)

NLog LayoutRenderer for assembly version

Posted in CodeProject, Logging with NLog by Sebastian Solnica on November 22, 2012

This post will be short and is inspired by Robert’s comment under my previous post (Thanks for it!). Robert pointed (and I completely agree) that it might be useful to have application assemblies versions listed in the log output.

(more…)

Tagged with: ,

To log or NLog

Posted in CodeProject, Logging with NLog by Sebastian Solnica on October 28, 2012

Today’s post is dedicated to NLog – one of the logging libraries available for .NET developers. NLog has a lot of features and options but also might seem complicated on first sight. Checking the examples should usually allay your fears but it will still take you some time to get along with NLog’s syntax and configuration. I will try to make the learning curve less steep by providing you with configuration options that are currently working in my projects. If you are new to NLog I recommend you to have a look at its tutorial before reading on.

(more…)

Tagged with: , , ,

Introducing Musketeer – the performance counter data collector

Posted in CodeProject, Profiling .NET applications by Sebastian Solnica on October 21, 2012

In this post I will show you how to create a very simple Windows Service (I will call it Musketeer) that will collect information about other processes running on a server. Such a tool might be helpful if you host Windows services on some remote server and you want to store information about their performance in a database for further analysis. This tool might also be a cure if your admins didn’t give you enough privileges to connect the Performance Monitor to the remote server:)

(more…)

Diagnosing ADO.NET with ETW traces

Posted in CodeProject, Diagnosing ADO.NET by Sebastian Solnica on September 7, 2012

The majority of modern applications use ORMs as a way to connect to a database. Those libraries simplify the usage of the underlying ADO.NET API in a way that we might even forget that under the hood we are dealing with a relational model. This object-oriented wonderland usually lasts till the moment when the first SQL exceptions crop up. If we configured our ORM correctly we should be able to diagnose database problems with just logs that it provides. But what if we didn’t or if the problem lies deep in the ADO.NET layer? We might then try to use a debugger or a SQL Server Profiler. Both those tools, although great, are usually too heavy (or too invasive) for a production environment. Fortunately there is still one option left – ADO.NET ETW tracing. In today’s post I will show you how to turn on this type of tracing and how to use it to quickly diagnose some database problems.
(more…)

Application Pool identity and Directory Security in IIS6

Posted in CodeProject, Diagnosing IIS by Sebastian Solnica on August 17, 2012

In today’s post I will describe different security settings of the application pool and the IIS6 directory. It’s not always easy to guess which permissions must be set on system folders and files in order to make the application run correctly. I will also show you how to diagnose those pesky security problems using available tracing options.

(more…)

Follow

Get every new post delivered to your Inbox.