Method AddDirectory doesn't work if it's not the current directory. The fix is to change the line
AddFile( hbmXml.Name )
to
AddFile( hbmXml.FullName )
or (using a different AddFile overload)
AddFile( hbmXml )
BTW, in CLR 2.0, there is a new overload of DirectoryInfo.GetFiles that searches the entire subtree, thus eliminating the need for the recursive loop in AddDirectory.
I have copied the original version of AddDirectory below.
Mike Abraham
Code:
/// <summary>
/// Read all mapping documents from a directory tree. Assume that any
/// file named <c>*.hbm.xml</c> is a mapping document.
/// </summary>
/// <param name="dir">a directory</param>
public Configuration AddDirectory( DirectoryInfo dir )
{
foreach( DirectoryInfo subDirectory in dir.GetDirectories() )
{
AddDirectory( subDirectory );
}
foreach( FileInfo hbmXml in dir.GetFiles( "*.hbm.xml" ) )
{
AddFile( hbmXml.Name );
}
return this;
}