Ah, this is great news. A new version of CopySourceAsHtml (CSAH) has just be released with support for VS2008 after a long hiatus. CSAH is a must Visual Studio addin for any developer blogger. Get the goods here.
Tags:
449bf349-0d73-4380-8ce2-d6e577a6c6c7|0|.0
Opening an application configuration is useful when you need access to information that is not available via an API. I have done this a few times for reading WCF configuration.
The following code is how I have previously achieved this.
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);
This works fine while the application is an exe. Unfortunately it fails when the code is hosted in IIS. You will get an error in the event log like the following:
A Webhost unhandled exception occurred.
Exception: System.ServiceModel.Diagnostics.CallbackException: A user callback threw an exception. Check the exception stack and inner exception to determine the callback that failed. ---> System.ArgumentException: exePath must be specified when not running inside a stand alone exe.
at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)
at System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel userLevel)
The issue here is that IIS doesn't have an exe path for the configuration manager to load from. The simple workaround for this is to access the required configuration section (rather than configuration group) directly using the ConfigurationManager and a wicked cool syntax. The previous example can now be rewritten like this:
ClientSection client = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
In this case I was after the client configuration for WCF services.
Tags: wcf, WCF
98e9153e-487e-4de8-a2da-4e396d4ec5c4|0|.0
I have previously posted (here, here and here) about using IErrorHandler to provide error handling and exception shielding in WCF services. What I haven't discussed is how to test an implementation of this interface.
The reason for posting this is that I recently found that I had a bug in a service where un-handled exceptions weren't being shielded from clients. This was purely because my unit tests were not validating the messages being generated for clients by the error handler.
The following method came about after a bit of research (mainly from here) and playing with code to make the solution work and easy to use. This method will assist unit testing the output of ProvideFault as it provides an easy way to extract a Fault from a Message returned by the ProvideFault method. This fault can then be tested for expected outcomes of the unit test.
private static T ReadFaultDetail<T>(Message reply) where T : class
{
const String DetailElementName = "Detail";
using (XmlDictionaryReader reader = reply.GetReaderAtBodyContents())
{
// Find the <soap:Detail> element
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element
&& reader.LocalName == DetailElementName)
{
break;
}
}
// Check that the reader is at the detail element now that we are outside the loop
if (reader.NodeType != XmlNodeType.Element
|| reader.LocalName != DetailElementName)
{
return null;
}
// Read again to move the reader into the contents of the details element
if (!reader.Read())
{
return null;
}
// Deserialize the fault
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
return serializer.ReadObject(reader) as T;
}
}
Tags: wcf, unit testing, Unit Testing, WCF
d89943b0-9a41-4629-a324-44e7ced515d1|0|.0
There have been several times when I have needed to process a string that contains a set of arguments. It always seems to be a lot of work splitting up arguments by using white space as a delimiter because you need to take into account white space that is surrounded by brackets.
Just for kicks, I tried to come up with a regular expression that would do just that. Here is the result.
[^\s"]*"[^"]*"[^\s"]*|[^\s"]+
Tags:
f1236fa0-6ea3-438f-8ff3-ddc7a2b572bd|1|4.0
No, this isn’t related to the Victoria fires. This is the sunset seen from the deck at home.

Tags:
3144db43-9eda-4f31-a92d-97502a7b0980|0|.0
I have just encountered a problem where the SQLEXPRESS instance installed on my machine was not starting. It looks like a recent windows update has failed, but also knocked out SQL Server. The event log contains the following entry:
Error 3(error not found) occurred while opening file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\master.mdf' to obtain configuration information at startup. An invalid startup option might have caused the error. Verify your startup options, and correct or remove them if necessary.
After searching around, there seems to be lots of forum posts going back several years about this issue. The problem is that the only known solution seems to be to change the credentials of the SQLEXPRESS service account to Local System. This will then allow the service to start. Doing this through the services console presents a problem however because you can't set the service credentials back to Network Service as you need to know the password.
A better answer was found in this forum post. Using the SQL Server Configuration Manager, you can change between the system accounts without needing to know the password.
What you need to do is change the account to Local System, then click Apply and Start. You can then click Stop and change the account back to Network Service and then click Apply and Start again.
Tags:
6a0b69c2-ce79-4b98-815f-10d0b92fce93|1|5.0
No seriously, it's not. I don't like hot weather. 33.8c (or 92.8f for my friends up north) at my desk at work is not nice. I'd take the snow any day.
Tags:
543f2d05-fe37-42f3-a487-6a03bf816d8f|0|.0
I'm working through the best way of getting DataDude to build and deploy a database using TeamBuild. When I kicked off a build, the build script failed with the following error:
Task "SqlBuildTask"
Building deployment script for [DatabaseName] : AlwaysCreateNewDatabase, EnableFullTextSearch, BlockIncrementalDeploymentIfDataLoss
MSBUILD : Build error TSD158: Cannot open user default database. Login failed.
MSBUILD : Build error TSD158: Login failed for user '[TeamBuildUserName]'.
Done executing task "SqlBuildTask" -- FAILED.
The problem here is that the logs don't contain the information about the target database or the connection string used to deploy the database. This means that I can't be certain that the properties defined for the project and build script are getting correctly propagated through the build process.
The solution is to modify the DataDude build script to include a log message that outputs the required property values.
- Open the DataDude build target file on the build server (found at C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\TeamData\Microsoft.VisualStudio.TeamSystem.Data.Tasks.targets)
- Find the SqlBuild target. It looks like the following
<Target Name="SqlBuild"
DependsOnTargets="$(SqlBuildDependsOn)"
Inputs="@(SqlBuildInputItems)"
Outputs="@(SqlBuildOutputItems)"
>
<SqlBuildTask
SourceItems="@(Build)"
PostDeployItems="@(PostDeploy)"
PreDeployItems="@(PreDeploy)"
TargetConnectionString="$(TargetConnectionString)"
TargetDatabase="$(TargetDatabase)"
OutputPath="$(OutDir)"
BuildScriptName="$(BuildScriptName)"
ReferenceAssemblyName="$(ReferenceAssemblyName)"
ProjectPath="$(MSBuildProjectFullPath)"
References="@(ReferencePath)"
- Add a message task to the start of the target so it looks like the following
<Target Name="SqlBuild"
DependsOnTargets="$(SqlBuildDependsOn)"
Inputs="@(SqlBuildInputItems)"
Outputs="@(SqlBuildOutputItems)"
>
<Message Text="Deploying database $(TargetDatabase) with connection $(TargetConnectionString)" />
<SqlBuildTask
SourceItems="@(Build)"
PostDeployItems="@(PostDeploy)"
PreDeployItems="@(PreDeploy)"
TargetConnectionString="$(TargetConnectionString)"
TargetDatabase="$(TargetDatabase)"
OutputPath="$(OutDir)"
BuildScriptName="$(BuildScriptName)"
ReferenceAssemblyName="$(ReferenceAssemblyName)"
ProjectPath="$(MSBuildProjectFullPath)"
References="@(ReferencePath)"
- Kick off another build. The database name and the connection string used to deploy the database will be rendered to the build log.
WARNING: If the connection string is using username/password authentication then these credentials will be rendered to the build log. It is advisable that this message task be commented out once the debugging requirements of the build have been satisfied.
Tags: TFS, TeamBuild
e21af1f4-5cdd-4daf-ae42-15e8c698f7ed|0|.0