Aug 17 2010

Runtime error when trying to run Fluent NHibernate tutorial example

I worked through the Fluent NHibernate tutorial at http://wiki.fluentnhibernate.org/Getting_started and the project compiles fine.

However, I am getting a runtime error and I can't seem to resolve it. The error is happening in the CreateSessionFactory method you can see in the tutorial. Here it is:

private static ISessionFactory CreateSessionFactory()
{
    return Fluently.Configure()
        .Database
        (
            SQLiteConfiguration.Standard
                .UsingFile(DbFile)
        )
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<FluentNHibernateSample.Program>())
        .ExposeConfiguration(BuildSchema)
        .BuildSessionFactory();

}

I think the most helpfule thing to do is to give you the Exception chain (is that a real word) from the Outermost exception to the inner most exception:

An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
    An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
        Could not compile the mapping document: (XmlDocument)
            persistent class FluentNHibernateSample.Entities.Employee, FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null not found
                Could not load file or assembly 'FluentNHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The tutorial was not clear on how to setup the reference (or at least seems incomplete based on the most inner exception) so I got the compiled assemblies from http://fluentnhibernate.org/downloads/releases/fluentnhibernate-1.1.zip and copied them into a libs folder. Based on googling the error I set a references to the FluentNHibernate, NHibernate, and NHibernate.ByteCode.Castle assemblies. I copied ALL of the dlls from the downloads page into the bin directory and I thought that all of the references would resolve. (That is my understanding of how it works). In any case here is the list of files I copied into bin.

Antlr3.Runtime.dll
FluentNHibernate.dll
FluentNHibernate.exe
FluentNHibernate.pdb
FluentNHibernate.vshost.exe
FluentNHibernate.vshost.exe.manifest
FluentNHibernate.xml
Iesi.Collections.dll
Iesi.Collections.xml
log4net.dll
log4net.xml
NHibernate.ByteCode.Castle.dll
NHibernate.dll
NHibernate.xml

I also copied System.Data.Sqlite assembly to the bin.

For the life of me I cannot figure out what the problem is. I have tried everything I can think of and googled multiple error messages but nothing has worked for me.

Help! I have wasted hours on this.

EDIT
I have put the source files for the project at http://dl.dropbox.com/u/8824836/FluentNHibernateExample.zip. Keep in mind that to fully replicate my environment you need to put all of the files from here into your output/bin directory.

Seth

Aug 15 2010

Does python have a ruby installer like gem that lets you install modules from the command line even if they are not on your machine?

With Ruby you can do gem install from the command line to install a module...even if it is not on your machine.

Can you do that with python. Does someone know of a module?

Seth

Aug 15 2010

Python cheat sheet 1

# PYTHON TIPS AND TRICKS

# int(), float(), str() are type conversion functions – pass the variable to them to return a new type.
# type() function displays the type of the variable.

# print statement prints output to the screen.
# in the interactive interpreter just type a variable name to output to the screen

# raw_input() function get a string value from the user and can assign to a variable.

# put a comma at the end of the print statement to capture the input on the same line as the print statement.  Like this:

print "Enter your name: ",
somename = raw_input()

# will appear as

# Enter your name:  Seth

# (pound) is the comment marker. 
# For multiline comments you can "trick" python into ignoring text using a multiline string like this:
"""
Anything in here will be ignore!!
Pretty cool.
It is technically not a comment but it is unassigned string that gets ignored.
"""

# speaking of … that is how you can create multiline strings in python.  I could ASSIGN to a variable and then use it.  Like this …

my_string="""  Whatever I type i
here is treated exactly like it is typed…even code and reserved words.
"""

print my_string

# import <module>         #imports a module for use
import time

# you still have to type fully qualify names for variables and methods or functions like this…
# <module>.<function> like this.
time.sleep(2)

# to avoid do the import like this
# from <module> import <methodname>  … for example

from time import sleep

# then you can just do
sleep(2)

# to import all of the public members of the module use …
# from <module> import * … for example
from time import *
# use this with caution because it can cause namespace conflicts.

##############################   SAMPLE PROGRAM
width = int(raw_input(‘What is the width of the room:  ‘))
#depth = int(raw_input(‘What is the depth of the room:  ‘))   #this works…just wanted to try it the other way.
print ‘What is the depth of the room:  ‘,
depth = int(raw_input(”))
sq_feet = width * depth
sq_yard = sq_feet / 9
cost = float(raw_input(‘What is the cost per square yard for carpet?’))
carpet_cost = sq_yard * cost

print ‘You need ‘ + str(sq_feet) + ‘ square feet of carpet’
print ‘You need ‘ + str(sq_yard) + ‘ square yards of carpet’
print ”
print ‘The cost of the carpet is ‘ + str(carpet_cost) + ‘ dollars.’

mystring = """
Anything in here will be ignored!!
Pretty cool.
It is technically not a comment but it is unassigned string that gets ignored.
"""
print ”
print mystring
from time import strftime

print strftime(‘%X %x %Z’)

raw_input()  # wait before exiting
exit()
##################################### END SAMPLE

Aug 12 2010

Blogging code from Windows Live Writer

Windows Live Writer is an AWESOME way to blog. 

Using the following post I figured out how to have awesome code formatting in my posts.

http://technologicaloddity.com/2010/01/16/using-live-writer-with-the-wordpress-syntaxhighlighter-plugin/

Look at my last post for an example.

Seth

Aug 12 2010

Sample code that uses the WLW PreCode Snippet Manager and SyntaxHighlighter. Looks pretty good doesn’t it?

using System;
using Quartz;
using Quartz.Impl;

namespace goAlarmsCS
{
    class alarmJob : IJob
    {
        public alarmJob()
        {
        }

        #region IJob Members

        public void Execute(JobExecutionContext context)
        {
            QuartzAlarmScheduler qas = QuartzAlarmScheduler.Instance();
            qas.Execute(context.Trigger.Name);
        }

        #endregion
    }
}
Aug 12 2010

Differences between Unit Testing Mocks, Fakes, and Stubs

Martin Fowler’s page on the matter is a well-known guide.  Here is how he defines the differences in summary:

  • Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists.
  • Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example).
  • Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it ‘sent’, or maybe only how many messages it ‘sent’.
  • Mocks are what we are talking about here (the article): objects pre-programmed with expectations which form a specification of the calls they are expected to receive.

Happy Unit Testing

Seth

Aug 11 2010

A simple and appropriate way to handle XML in your applications.

Good post here.

Also a little more details here.

Seth

Aug 11 2010

If your organization is NOT a software shop but DOES do a lot of custom software development…

…you should still use software development best-practices, according to this excellent blog post.  It is the definition of “professional.”

This is good stuff.  And here is his list of best practices defined at the end of the post:

  • Yes, you need to use source control.
  • Yes, you need to automate the build.
  • No, you shouldn’t be releasing the assemblies compiled on your machine.
  • Yes, you need to stop writing long methods and pay attention to code complexity.
  • Yes, you need to buy your developers the best tools available.
  • No, you don’t need to write your own logging framework.
  • Yes, you should be practicing test first development.
  • No, continuing to ship known defects is not acceptable.
  • Yes, you should understand who your customer is

Seth

Aug 06 2010

To run SQL Scripts from Notepad++

To setup notepad++ to execute sql scripts that you are writing do the following:

1.  Be sure that you have the nppexec plugin installed.

2. Hit F6 to open the nppexec execute window.

3.  In the Commands window type the following command…

SQLCMD.EXE -E -S.\SqlExpress -i “$(FULL_CURRENT_PATH)” -deScore

4.  Click Save and give the nppexec script a name.  Make a mental note of the scripts name.

5.  Click on Settings/Shortcut Mapper and choose the Plugin commands tab.

6.  Scroll through the list and find your new script (given in step 4).

7.  Double click the script and assign a keystroke to the script.  (I use ctrl-alt-F5)

Test it out.

Enjoy.

Aug 05 2010

How can I get DevExpress CodeRush to create NUnit test methods with the tm template instead of microsoft test methods in VS 2010

when I try to execute the test or testmethod templates respectively in visual studio 2010 using t and tm respectively it is giving me ...

using Microsoft.VisualStudio.TestTools.UnitTesting;    
    [TestMethod]
    public void Test()
    {

    }

I want it to give me the nunit decorator instead and stop adding the using reference to the microsoft tooling.

I can't figure it out.

Thanks.