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:
        <parameterName value=”@UidSubmission”/>
        <dbType value=”Int32″/>
        <layout type=”log4net.Layout.PatternLayout”>
          <conversionPattern value=”%X{uidsubmission}” />

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:
        <parameterName value=”@DischargeDate”/>
        <dbType value=”DateTime” />
        <layout type=”log4net.Layout.RawPropertyLayout”>
          <key value=”dischargedate”/>
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)

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.

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.

SubTyping in ActiveRecord isn’t too clear.

I’ve spent quite a lot of time messing around the methods for subtyping in ActiveRecord.  The clearest method I’ve found is using concrete classes (what Fowler calls them).  For this to work you simple have a inheritance relationship between the base type and the subclasses and have the AR attribute on all the classes (I get a weird error if the base class doesn’t have this attribute).

public class BaseType

public class FirstSubType:BaseType

public class SecondSubType:BaseType

You end up with a little bloat in terms of sourcefiles and database tables, but, at least you have a very clear subtyping relationship.  I had wasted a lot of time with the AnyToAny relationship syntax.  Note:  There is no documentation whatsoever for how to use AnyToAny relationships in AR.  I reccomend searching the Subversion repository test cases for examples of how to use that.  Even the forums lacked any good description of how to code it.  Honestly this is one of those features that I would almost switch to NHibernate if I can’t work it.

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. 

TDD in Monorail

I’ve heard a lot of weird things about TDD in Monorail.  As a bastard child (open source project based on closed source technology—can you please open source C# please MS) project Monorail comes with its own gotchas.  So far I have discovered two problems that I have worked through.
1.  For whatever reason, you are stuck with the version of Nunit that the Castle distribution comes with.  You can get the source and try to figure out whats broken here, but, if you encounter strange exceptions when running tests in Nunit-Gui then a likely cause will be that you’re Nunit-Gui version and the Monorail version of Nunit do not match.  I consistently got a “accessing an unloaded appdomain” exception.
2.  Make sure that anything stored in property bags is serializable.  This was a weird one, being that the actual exception ends up being “System.IO.FileNotFoundException : Could not load file or assembly.”  In reality I discovered that a call to AssertPropertyBagContains was failing because an item I was storing in the propertybag was not serializable.  Easy fix for this is to add the Serializable attribute to the class and check for any custom Serialization stuff (changing collections to list and dictionary should fix problems with serialization).

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.