Exceptions leading to failure in AdonetAppender.DoAppend: Pattern layout in log4net

If you use log4net then you have to be careful of using patternlayouts for parameters for Adonetappenders.  Log4net can work with all native .net datatypes including nullables.  However, a layout like this:
<parameter>
        <parameterName value=”@UidSubmission”/>
        <dbType value=”Int32″/>
        <layout type=”log4net.Layout.PatternLayout”>
          <conversionPattern value=”%X{uidsubmission}” />
        </layout>
      </parameter>

while valid for a simple type like an int, may generate an exception if it is a nullable or reference type.  This is because patternlayout infers a cast to string when binding parameters.  If the value of the parameter is null, that tostring cast will fail.  They make no mention of that in the patternlayout documentation that is here.  For reference types and nullables you would be better served by using a rawpropertylayout.  This binds directly to the datatype and does not do any casting.  The syntax is a bit unusual (it helps to bind to the log4net.xsd so you can see how to use this).  An example of such a parameter is below:
   <parameter>
        <parameterName value=”@DischargeDate”/>
        <dbType value=”DateTime” />
        <layout type=”log4net.Layout.RawPropertyLayout”>
          <key value=”dischargedate”/>
          </layout>
      </parameter>    
The error you will get in your log4net logs will look like this:
og4net:ERROR [AdoNetAppender] Failed in DoAppend
System.Data.SqlClient.SqlException: Error converting data type nvarchar to datetime.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events)
   at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
   at log4net.Appender.BufferingAppenderSkeleton.Append(LoggingEvent loggingEvent)
   at log4net.Appender.AppenderSkeleton.DoAppend(LoggingEvent loggingEvent)

Dumb VS Errors: LinqToSQL DBML Unspecified error

If you ever get an unspecified error when modifying a dbml file for a linq to sql class one of the possible problems is that you specified using statements outside the name space.  ie.  the following code will cause the error: 

using log4net;

namespace DQR
{
    using ValidationUtility;
    using System.Linq;
    using System;
    partial class tblTimeFrame
    {

The fix is to move the using statements inside the namespace:

namespace DQR
{
    using ValidationUtility;
    using System.Linq;
    using System;
    using log4net;
    partial class tblTimeFrame
    {

Believe it or not.  This fixes the problem and you can click the “View Code” link inside the dbml and be presented with the class.  Its not a major flaw, but, it is annoying when you have several classes in the dbml and navigating through the cs file becomes tedious.

Asynchronous Form Validation Using Windows Workflow

Just completed work on a Asp.Net validation framework using Windows Workflow for a client.  The client maintains a host of medical related data collection applications and needed a unified framework for validations for them for the client and code behind.  They wanted to write validation rules once and use them in multiple contexts:  client side via Javascript and in code behind as plain C# web service calls.  I designed and built for them a validation framework that consisted of

   1. asynchronous javascript validation using custom validators
   2. an XML web service that is called by javascript to execute validation rules that are expressed as workflow rules conditions (Business Rules Execution Service)
   3. ORM data mapping objects that workflow rule conditions are mapped to
   4. a business rules editor that leveraged the ruleset dialog editor to provide for editing rules.

The system is in the final test phases now.  I am writing an article on it that I hope gets picked up by someone if not I will post here.

This approach works for several key scenarios:

1.  Complex validations that are difficult to express in just javascript.
2.  There is a need to store validation rules in the database
3.  There is a need to use the same validation rules in multiple contexts:  client side, code behind, web service, etc.

Performance considerations are not what you might think.  A form with 50 elements and dozens of validation rules still takes about 200 ms round trip for the Business Rules service.  Workflow rules conditions have execution times approaching those of plain C#.  LinqToSQL mapping classes (what the rules conditions are bound to) have good hydration times from the db (100 ms or less for even large data mapped objects).

For inquiries or more specifics either look for my article when it is somewhere or email me.

MsBuild, CCNet, VS2008

If you ever want to get this all working. Please ignore all the blogs that try to indicate that somehow you can use a custom task library or maybe some feature of msbuild to do deployments. The best blog I have found on getting this all to work including deployment is here. Lets face it. Unless you have Team Foundation running, Microsoft wants you to jump through hoops to get continuous integration to work. Depend on CCNet and ignore having too much in MSBuild.

Windows Workflow for the rest of us

First off, get a good book. Workflow is too encompassing for you to pick up in a tutorial. Forget about learning it all in a weekend. Pick up a good book written by one of the original WF developers. My first choice was Essential Workflow by Shukla and Schmidt. More of a developer reference than anything else. There are other books for other users, but, you definitely need a book. Second, go ahead and move to Vista and Visual Studio 2008. Sure, you can do WF development in 2005 and XP, but, thats like desiging a Formula one race track when you have only driven Yugos: You can imagine what it feels like and if you have an excellent knowledge of race track design you can pull it off, but, for mere mortals its going to suck. Third, there is plenty of MS documentation on the MSDN site, but, you could just ignore all that and proceed to write some terrible implementations. Forth, the killer app for me of the moment is designing workflows using a Domain Specific Language. Fifth, profit.

WatinTest Recorder is brilliant

Watin is an amazing testing suite for web applications.  If you have not tried it immediately go here and watch how easy it is to create end user unit tests for web applications. Now if that isn’t amazing enough there is the WatinTestRecorder.  View the video here that shows how to create Watin tests for a full page of a web application in about 5 minutes.

More on Monorail

More on Monorail

         

Why are people still using ASP.Net WebForms?

 

Finally cooking with Monorail and ActiveRecord has come to the party.  Can’t believe that I just got log4net working yesterday and I’ve had log messages  in code from the start.  Turns out that you have to take the log4net config out of the web.config and put it in its own log4net.config file in the same directory as web.config.   I still haven’t figured out how to turn on event logging appender yet, but, I’m fine with file logging for now. 
Man, when it all comes together its a thing of beauty.  I’m making use of the paginationhelper now.  I have to use the caching one because of multiple search params, but, I could get away w/out the caching one if I had to.  I should be able to get deep into the SCORM stuff later today after cleaning up one or two things.  I’ve been mostly happy with everything except that I’m using sourcesafe.  2007 and Sourcesafe is still a hot mess.  On the next project, I’m definetly switching to subversion.   Friends don’t let friends sourcesafe. 

Thoughts on software

.Net web development frameworks

         

Why no one uses webforms

Castle Framework   Who gives a damn about viewstate

Went through the usual suspects.  I was looking for something that supported MVC, TDD, domain driven design and had nhibernate support.  Castle handily has support for all this.  Took a look at the spring project, but, I’m not that into aspect oriented (Can you name one major aspect oriented developed project?).  Are there too many frameworks and methodologies out there?  There is one train of thought that anything worthwhile is necessarily simple in its makeup and explanation.  I agree with this except I don’t think the proper methodologies are emphasized in computer science.  People are very caught up in buzz words, but, they don’t realize that there are a lot of people working on ways of making their work easier and worthwhile.  That it comes out in a variety of shapes and forms, is not an indication of merit, but, a reflection of how many smart people there are working on all this.  A few things that can help the development of maturity in software engineering:

  1. The cathedral and bazaar conflict has to leave the software engineering mindset.  This is a concern that is outside of our work.  We make the products.  Let the bankers, financiers and the like figure out how to sell it.  Software Engineers can no more impact the software engineering marketplace than automotive engineers can impact the automotive marketplace:  sure, we can design new forms and create new trends, but, when it comes down to it, its all about what some individual wants and how much they are willing to pay for it.
  2. The software engineering licensing movement has to move forward.  There are too many kids with bazookas out there.  In the last 60 years we have managed to create a wasteland of broken promises and even more broken systems.  A certain seriousness has to enter into the approach to software development.  Every day, system criticality increases as IT drives more and more of human endeavor.  We have to get serious about creating good software and to do that we need good software engineers.
  3. Intellectual property has to be recognized as an asset of the species rather than as corporate asset.  This may seem to contradict point one, but, let me clarify.  I said nothing about making all software free.  I believe developers should be paid for their work.  However, there must be a new model for what happens to software once its developers have received payment for their work.  Perhaps, we should all agree on some fair use clause that kicks in after X amount of years.  I am very opposed to the idea of perpetual copyrights to software.  Software has to be seen as a human intellectual product.  As such, it should only be protected for a limited amount of time and then released like all other human intellectual products.  The benefits to humanity of fair use far outweigh any financial incentive that any single developers every see in their lifetime (Bill Gates included).  Of course, this may mean a radical adjustment to the economic model for software.  However, this is happening as we speak anyway.  Software as a Service is the latest incarnation of transformations that are already happening.