Monday, May 9. 2011
Upgrade test project from VS2005 to VS2010
The solution contains several projects, including test projects. All of which now target .Net Framework 2.0 (although some already reference .Net Framework 3.0 or 3.5 assemblies). We do not want to upgrade to .Net Framework 4.0 just yet. Goal of the upgrade is to have every project in the solution target .Net Framework 3.5.
After converting the solution to VS2010 most of the projects reference .Net Framework 2.0. Some of which do not build, because of references to assemblies targeted at a higher .Net Framework. Visual Studio 2010 does not allow cross-referencing to higher .Net Framework assemblies. Fixing this problem is quite simple: just re-target the project to .Net Framework 3.5.
All of the test projects have been set to .Net Framework 4.0. One could discuss if this is acceptable for test projects as these will not be released. But for now it was decided to keep every project targeted at .Net Framework 3.5. Fortunately most of the test projects were easily re-targeted to .Net Framework 3.5. Hint: if you run into problems here, make sure VS2010 SP1Rel is installed.
For one of the test projects the solution just would not load it if re-targeted at .Net Framework 3.5. Each time the project was re-targeted, the conversion wizard would just pop up and set it back to .Net Framework 4.0. Eventually we found a workaround by editing the project file by hand after the conversion.
Two manual fixes were needed:
After converting the solution to VS2010 most of the projects reference .Net Framework 2.0. Some of which do not build, because of references to assemblies targeted at a higher .Net Framework. Visual Studio 2010 does not allow cross-referencing to higher .Net Framework assemblies. Fixing this problem is quite simple: just re-target the project to .Net Framework 3.5.
All of the test projects have been set to .Net Framework 4.0. One could discuss if this is acceptable for test projects as these will not be released. But for now it was decided to keep every project targeted at .Net Framework 3.5. Fortunately most of the test projects were easily re-targeted to .Net Framework 3.5. Hint: if you run into problems here, make sure VS2010 SP1Rel is installed.
For one of the test projects the solution just would not load it if re-targeted at .Net Framework 3.5. Each time the project was re-targeted, the conversion wizard would just pop up and set it back to .Net Framework 4.0. Eventually we found a workaround by editing the project file by hand after the conversion.
Two manual fixes were needed:
- Change reference of "Microsoft.QualityTools.UnitTestFramework" to
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
- Remove contents of the tag
<FileUpgradeFlags>0</FileUpgradeFlags>
, which hints VS2010 to start the conversion wizard.
Wednesday, April 13. 2011
T-SQL: Import csv in temp table
Seems pretty simple to do... Just execute a query like this one:
SELECT * INTO #TESTCSV
FROM OPENROWSET (
'Microsoft.Jet.OLEDB.4.0',
'Text;Database=C:\;HDR=YES',
'SELECT * FROM test.csv')
In my case I was getting the following error message, which got me baffled for quite some time:
This really didn't make any sense to me. There were no duplicate column names in the csv file and surely there were no columns named 'NoName', nor did I forget to name a column...
Then it came to me: what if UNICODE isn't parsed correctly? Maybe that could cause empty columns headers? The file was exported by ReportViewer and I had not looked at the encoding of the resulting csv file. Guess what!? The encoding was UNICODE. So, after saving the file in ANSI encoding, the query executed like a charm.
SELECT * INTO #TESTCSV
FROM OPENROWSET (
'Microsoft.Jet.OLEDB.4.0',
'Text;Database=C:\;HDR=YES',
'SELECT * FROM test.csv')
Msg 492, Level 16, State 1, Line 1
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name "test#csv.NoName" is a duplicate.
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name "test#csv.NoName" is a duplicate.
This really didn't make any sense to me. There were no duplicate column names in the csv file and surely there were no columns named 'NoName', nor did I forget to name a column...
Then it came to me: what if UNICODE isn't parsed correctly? Maybe that could cause empty columns headers? The file was exported by ReportViewer and I had not looked at the encoding of the resulting csv file. Guess what!? The encoding was UNICODE. So, after saving the file in ANSI encoding, the query executed like a charm.
Friday, March 27. 2009
Wcf Exception Shielding - Unexpected FaultContracts
So you've got Wcf Exception Shielding in place. All is well and the Enterprise Library Exception Handling Application Block takes care of those nasty exception details that you don't want your site visitors to know about... But have you ever had the urge to do more than just property mapping between exceptions and FaultContract? I know I have 
There is a way to do this and it is actually quite simple to realize. You just have to create your own custom IExceptionHandler. But let's start with a bit of configuration. By default you would have an Exception Policy named "WCF Exception Shielding". Like so:
<exceptionHandling>
<exceptionPolicies>
<add name="WCF Exception Shielding" />
</exceptionPolicies>
</exceptionHandling>
This policy handles specific Exception types and for each of those it will pass the exception through a chain of IExceptionHandlers. The last of these would normally be Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler. For instance:
<exceptionTypes>
<add type="System.DivideByZeroException, mscorlib"
postHandlingAction="ThrowNewException" name="DivideByZeroException">
<exceptionHandlers>
<add exceptionMessage="Dividing by zero is not allowed."
faultContractType="DivideByZeroFault, MyDll"
type="FaultContractExceptionHandler, ExceptionHandling.WCF"
name="Fault Contract Exception Handler">
<mappings>
<add source="Guid" name="Id" />
<add source="Message" name="Message" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
Now what if your FaultContract would need additional data, that you can't just map from the Exception properties? For example:
- you might need the Message property of the InnerException;
- you need data that was logged to a database when the original exception got thrown.
To make this possible, just create your own IExceptionHandler that will be used instead of the provided FaultContractExceptionHandler. There are two things to keep in mind when you do this. First of all you should always set the postHandlingAction to ThrowNewException. Second, you should let your IExceptionHandler return a specific Exception type: FaultContractWrapperException. Read More

There is a way to do this and it is actually quite simple to realize. You just have to create your own custom IExceptionHandler. But let's start with a bit of configuration. By default you would have an Exception Policy named "WCF Exception Shielding". Like so:
<exceptionHandling>
<exceptionPolicies>
<add name="WCF Exception Shielding" />
</exceptionPolicies>
</exceptionHandling>
This policy handles specific Exception types and for each of those it will pass the exception through a chain of IExceptionHandlers. The last of these would normally be Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler. For instance:
<exceptionTypes>
<add type="System.DivideByZeroException, mscorlib"
postHandlingAction="ThrowNewException" name="DivideByZeroException">
<exceptionHandlers>
<add exceptionMessage="Dividing by zero is not allowed."
faultContractType="DivideByZeroFault, MyDll"
type="FaultContractExceptionHandler, ExceptionHandling.WCF"
name="Fault Contract Exception Handler">
<mappings>
<add source="Guid" name="Id" />
<add source="Message" name="Message" />
</mappings>
</add>
</exceptionHandlers>
</add>
</exceptionTypes>
Now what if your FaultContract would need additional data, that you can't just map from the Exception properties? For example:
- you might need the Message property of the InnerException;
- you need data that was logged to a database when the original exception got thrown.
To make this possible, just create your own IExceptionHandler that will be used instead of the provided FaultContractExceptionHandler. There are two things to keep in mind when you do this. First of all you should always set the postHandlingAction to ThrowNewException. Second, you should let your IExceptionHandler return a specific Exception type: FaultContractWrapperException. Read More
« previous page
(Page 2 of 5, totaling 15 entries)
next page »