Aug 31 2010

Answer by Seth Spearman for Runtime error when trying to run Fluent NHibernate tutorial example

I feel like an idiot for this but at the end of the day the mapping problem was caused by the fact that I had named the project FluentNHibernate (in my own defense it was in a SAMPLES folder) but that was causing the mapping to fail.

Internally Visual Studio defaulted the Assembly name to FluentNHibernate and that was causing the runtime error. Renaming the assembly to ConsoleApplication fixed it.

Seth

Aug 31 2010

Answer by Seth Spearman for Runtime error when trying to run Fluent NHibernate tutorial example.

I feel like an idiot for this but at the end of the day the mapping problem was caused by the fact that I had named the project FluentNHibernate (in my own defense it was in a SAMPLES folder) but that was causing the mapping to fail.

Internally Visual Studio defaulted the Assembly name to FluentNHibernate and that was causing the runtime error. Renaming the assembly to ConsoleApplication fixed it.

Seth

Aug 27 2010

Send faxes for free

You can send faxes for free at www.faxzero.com.  Faxes are limited to 3 pages and you can only use the service twice a day max. 

I just used it and it worked perfectly.  (I had to use the $1.99 Premium service because it was a 4 page fax.)

Putting this here to remind me.

Seth

Aug 26 2010

A little ASCII weirdness

Just did a little Excel “hallway” support.  The user had copied and pasted in some data from a web page to excel.  Column A “looked” like a row of numbers but there is nothing I could do to get excel to treat the values like numbers.  Formulas that were expecting numbers showed #VALUE errors.

It seemed that each cell had a SPACE after it.  And that is weird in its own right because in a cell with a number and a space Excel should treat the value like a number.  But sure enough I could delete the “space” from the value and the cell would then begin to act like a number.   Problem was NOT solved though, because the sheet had 4000 rows that needed cleaning up.

The weirdness continued when I tried to use the Excel REPLACE function to remove the spaces.  But Excel could not find a space in the column.  By this time I was weirded out and I asked the user to email the sheet so I could take a closer look.

Once back at my desk it only took a few minutes to solve.  I used the Excel VBA ASC function to tell me what the character was.  In the Excel VBA Editor’s Immediate pane I typed in

?Asc(Mid(Range(“A1”),6,1))

That showed me that the character was NOT a space but was ASCII code 160. 

To fix the user’s data I did CTRL-H (Replace dialog) and in the Find box I typed ALT-0160.  That put in a “space” and I was able to Replace All. 

Turns out that in HTML (remember the data was copied from a web page) that ASCII-160 is treated as a NON-BREAKING space. 

For the curious…here are a couple of links.

http://office.microsoft.com/en-us/excel-help/ascii-character-chart-HA001133136.aspx

http://www.ascii.cl/htmlcodes.htm

Seth

Aug 26 2010

GetDateTime batch file outputs a timestamp string

Yesterday I posted a couple of Notepad++ scripts.  One of them referenced a GetDateTime.bat file.  For that Notepad++ script to work that batch file has to be in the Notepad++ root folder.

Here is the batch file…

@echo off
for /f "tokens=1-3 delims=/.- " %%a in ("%DATE%") do set CUR_DATE=%%c%%b%%a
for /f "tokens=1-4 delims=:., " %%a in ("%TIME%") do set CUR_TIME=%%a%%b%%c%%d
echo %CUR_DATE%_%CUR_TIME%

Seth

Aug 25 2010

Notepad++ scripts to remember

#SHOW CONSOLE – RUN THIS AT NOTEPAD++ STARTUP
NPP_CONSOLE ON
CLS

#SQL EXECUTE SELECTED – SAVES SELECTED TEXT TO TEMP FILE AND RUN IN SQL
NPE_CONSOLE v+
$(NPP_DIRECTORY)\GETDATETIME.BAT
SET TEMP_FILE= $(SYS.TEMP)\$(OUTPUTL)
NPE_CONSOLE v+
SEL_SAVETO $(TEMP_FILE) :a
CLS
SQLCMD -S.\SQLExpress -E -i"$(TEMP_FILE)"

#SQL EXECUTE FILE – EXECUTES THE WHOLE SCRIPT IN SQL
#YOU COULD USE INPUTBOX TO GET THE DATABASE NAME
cls
SQLCMD.EXE -E -S.\SqlExpress -i "$(FULL_CURRENT_PATH)" -deScore

#OPEN EXPLORER – OPEN THE EXPLORER WINDOW FOR THE CURRENT FILE
NPP_RUN EXPLORER "$(CURRENT_DIRECTORY)"

Aug 23 2010

Comment by Seth Spearman on How do you load a dictionary into a console application from an app.config?

I think you're right. Will roll my own config I guess.
Aug 18 2010

How do you load a dictionary into a console application from an app.config?

I want to load a dictionary at startup in my console app from my app.config.

I know that I could use an xml library or linq to XML to load it to parse and traverse it. My question is there a BUILT IN way of doing it.

Isn't there some way to add an application configuration section into the app.config and then have it loaded automagically using ConfigurationManager class in the System.Configuration namespace?

Any example? BTW, I am in NET20.

EDIT
Sorry, I should have clarified. I want to load the dictionary WITHOUT using AppSettings. I know how to do that already. Of course, the downside of using AppSettings is that I have to change my code to add new values to my dictionary. That is why I am looking for a way to do it automatically.

Aug 18 2010

C# question for VBer. Do private fields have to be declared Static?

I am a vb.net programmer switching to C#.

I have the following code for a console application (targeting NET20)

using System;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace eScoreSwapper
{
    class Program
    {
        private string _dbName = ConfigurationManager.AppSettings["dbName"];

        static void Main(string[] args) {}

        static void InitVars()
        {
            if (string.IsNullOrEmpty(_dbName)) _dbName = "";
        }
    }
}

This is giving a compile error in the if clause of InitVars for the _dbName variable:

Error   1   An object reference is required for the non-static field, method, or property 'eScoreSwapper.Program._dbName'   C:\Users\SethS\Documents\eScore\Versions\Trunk\dotNet\eScoreSwapper\eScoreSwapper\Program.cs    26  38  eScoreSwapper

Is it because it is true. C# does not allow you to reference private class fields unless they are declared static? I am sure I am doing something wrong.

While I am at it can I ask another C# question. Why is the if statement valid? Why are braces not required? Is it valid syntax as long as if condition is followed by a single expression (as in t-sql IF ).

Thanks for your help.

Seth

Aug 17 2010

Comment by Seth Spearman on Runtime error when trying to run Fluent NHibernate tutorial example.

Thanks for your suggestion. As mentioned, since those files are in the fluent-nhibernate download zip...they were already added to my bin folder. However, per your suggestion I added references in my project to those files. But I am getting the same result. Seth