Simon Green's Developer Blog
Developing .NET in the cold white north ...

Running .NET Apps in 32-bit mode on 64-bit Windows

Monday, 17 December 2007 12:37 by Simon

The normal behavior for .NET 2.0 applications compiled with the default 'Any CPU' platform is to run as 32-bit on x86 (32-bit) Windows and as 64-bit on x64 (64-bit) Windows.

Occasionally, some apps won't run correctly - I've recently run into this with CCNetConfig (a CruiseControl.NET Configuration tool) and have seen it before with other tools. Another obscure scenario where it shows up is if you try to use the JET OleDB driver which will fail in 64-bit mode because there isn't one! (it has to be 32-bit).

Rather than have to recompile the app or even worse, run a 32-bit Virtual Machine, there is an easy way to force .NET to run an app in 32-bit mode using the 'CorFlags.exe' tool.

Depending on your system this may be installed in different places. I've seen it in different places on XP64 and Vista X64:

  • C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\x64\CorFlags.exe
  • C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\CorFlags.exe

Running this from the command line with the path / filename of the app you want to change and the switch /32BIT+ to turn on 32-bit mode, e.g.:

   CoreFlags.exe TheApp.exe /32BIT+ 

If that fixes the problem then you know that it is a 64-bit issue. You can re-enable 64-bit operation for the app by turning off the 32-bit switch with the parameter /32BIT-, e.g.:

   CoreFlags.exe TheApp.exe /32BIT- 

Voila ... control over 32-bit and 64-bit execution without doing a recompile! I'm not 100% certain but I think that this switch sets the same flag that the 'x86' and 'Any CPU' targets set in Visual Studio.


Tags:   , ,
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (6) | Comment RSSRSS comment feed

Bootstrap your build - good practice for CruiseControl.NET

Sunday, 16 December 2007 03:43 by Simon

If you are reading this (a developers blog) then chances are you are already in the 20% of developers who know there is more to development than 'developing' (code). So, you are probably using version control such as Subversion, SourceGear Vault or heck, even SourceSafe (for all people knock it, it is infinitely better than nothing at all!) and maybe have a continuous integration system such as CruiseControl.NET or Draco.NET setup to automatically do a build when the source-code changes.

What many people leave out though is making sure that the build scripts themselves and the whole source control configuration is itself protected by version control so that in an emergency a new build machine can be setup quickly and easily without having to develop everything from scratch or remember all the triggers, rules and targets that were in the original system.

Here is a technique that I've found useful and also helps to keep the build configuration for each project with the project that it belongs to (i.e. in it's repository) rather than off somewhere else. It also enables you to make all changes to your build system via the normal Subversion working-copy / commit process.

For this example, lets assume that we have 3 subversion repositories:

The build repository would contain the default CruiseControl.NET files including the ccnet.config file in the server folder which is where the configuration for each project normally resides. We're going to move pieces of that file into each separate project repository.

The CruiseControl.NET wiki describes how to Configure CruiseControl.Net to Automatically Update its Config File which is the bootstrap part of the process - this allows us to make changes to the build config file from another machine without having to get onto the build server and also ensures that all the configuration is stored in a repository.

My ccnt.config file is slightly different to the one shown in the wiki to enable the individual project configurations to be stored in their own repositories so each project has it's own folder:


<!DOCTYPE cruisecontrol [

  &lt;!ENTITY accelerator SYSTEM "file:accelerator\ccnet.config">

  <!ENTITY redirector SYSTEM "file:redirector\ccnet.config">

]>

<cruisecontrol>

  <project name="ccnet">

    <sourcecontrol type="svn">

      <trunkUrl>http://buildserver/svn/build/trunk/CruiseControl.NET/server/config</trunkUrl>

      <workingDirectory>C:\Program Files (x86)\CruiseControl.NET\server\config</workingDirectory>

      <executable>C:\Program Files (x86)\VisualSVN Server\bin\svn.exe</executable>

    </sourcecontrol>

    <triggers>

      <intervalTrigger name="ci" seconds="60" buildCondition="IfModificationExists" />

    </triggers>

  </project>

  &accelerator;

  &redirector;

</cruisecontrol>

 

Remember that the ccservice.exe.config and / or ccnet.exe.config file will need to be changed to tell CruiseControl.NET where to look for the ccnet.config file now that it isn't in the original place:


 <appSettings>

  <!-- Without this appSetting ccservice will look for ccnet.config in its own directory. -->

  <add key="ccnet.config" value=".\config\ccnet.config"/>

  <add key="service.name" value="CCService"/>

  <add key="remoting" value="on"/>

  <add key="ServerLogFilePath" value="ccnet.log"/>

  <!-- Used by the WebDashboard ServerLog plugin to locate the log file produced by the LogFileTraceListener (above) -->

  <add key="ServerLogFileLines" value="100"/>

  <!-- Used by the WebDashboard ServerLog plugin to determine how many lines from the log file should be read -->

  <add key="WatchConfigFile" value="true"/>

  <!-- Turns on or off the file watcher used to monitor the ccnet.config file -->

 </appSettings>

 

The next step is to supply the ccnet.config files for each project which will come from the repositories for those projects.

I've created a 'build' folder in each ...

... and inside that is the ccnet.config project snippet for that project:


  <project name="redirector">

    <workingDirectory>E:\ccnet\redirector</workingDirectory>

    <sourcecontrol type="svn">

      <trunkUrl>http://buildserver/svn/redirector/trunk</trunkUrl>

      <executable>C:\Program Files (x86)\VisualSVN Server\bin\svn.exe</executable>

    </sourcecontrol>

  </project>

 

(the real-life project contains a lot more - labellers, targets etc...)

The final piece to tie everything together is to make these project-specific files part of the config folder that the build ccnet.config file is in above and for this we use the svn:externals facility.

I used TortoiseSVN to add the property to a checked-out copy of the config folder:

NOTE: The screeshot above only shows the first entry. An additional entry would be made for the accelerator project.

After committing all these files the build server will automatically update it's own ccnet.config and get the separate snippet of the file for each project from the separate project repositories because of the svn:externals. The folder structure will then appear as below:

Everything is stored in source control which makes moving to a new build machine easier and the configuration for each project is stored in the same repository as the project itself.

Adding or removing projects from the continuous integration / build system is simply a case of editing the root ccnet.config file and setting the appropriate svn:externals property on the config folder which can be done on a working copy of the build repository. An additional advantage is that all changes can now be done via subversion itself without needing direct access to the build machine so normal repository security can be used.

Incidentally, in case you are wondering what happens if a non-working configuration is committed don't worry - CruiseControl.NET is smart enough to avoid using something that won't load and keeps the previous version in memory so all you need to do is correct it and commit a new working version and it will then pick that up and carry on.


Ode to the MVC Framework

Sunday, 9 December 2007 13:36 by Simon

We've all been there ... thought we were going to get some code out of the door but then for one reason or another we couldn't manage it. I hope ScottGu et al who worked so hard to try and get it out this weekend don't take this the wrong way but here is a modified version of the lyrics to a song from the musical 'Les Miserables' for all of us who are sooo keen to get our hands on the new framework and waited all weekend for it ...

MVC framework (to 'Les Miserables - Empty Chairs At Empty Tables' music)

[A developer who got his hands on the MVC framework and blogged about it]

There's a grief that can't be spoken
There's a pain goes on and on
Empty pages, empty tables
Now my sites are dead and gone

Here they talked of view-controllers
Here it was they lit the flame
Here they sang about the framework
And the framework never came.

From a blog page in Seattle
They could see a world reborn
And they rose with voices ringing
I can hear them now!
The very code that they had posted
Became their last communion
On the lowly CTP...
At dawn.

Oh my friends, my friends forgive me.

[The ghosts of those who died waiting for the MVC framework appear.]

That I have code and you have none
There's a grief that can't be spoken
There's a pain goes on and on

Phantom frameworks run on windows
Mock assemblies on the floor
Databases with no tables
Where my view will run no more.

[The ghosts fade away.]

Oh my friends, my friends, don't ask me
What your sacrifice was for
Empty projects with no tables
Where my code will run no more...

Ah well, at least I have something to look forward to next week!!

Tags:   ,
Categories:   .NET | MVC
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

MVC Framework for ASP.NET

Sunday, 9 December 2007 04:02 by Simon

The ASP.NET 3.5 Extensions Preview (which includes microsoft's new MVC framework) should be release today on ASP.NET. It was due to ship earlier in the week but due to a bug got delayed. However, the team behind it have been working over the weekend to get it out. I can't wait to get my hands on it.

I've used ASP.NET for development even though I know about the other approaches (Ruby on Rails, Castle etc...) simply because I make a living out of coding and most clients want the big corporate supplied platform. Going into a company and trying to sell Ruby on Rails can be quite difficult and there simply aren't the opportunities / jobs about to justify switching to it (although I can understand people using it on private projects and startups).

Some question whether Microsoft should be producing a copy or clone of what existing open source projects already do. Well, I'm glad they are doing it!

Love em or hate em, Microsoft make some great development tools and platforms / frameworks and using these is how I make a living. 

What I think the ASP.NET MVC framework will do is validate the approach (if it needed it) and also allow it to be used in corporate / enterprise environments - i.e. it will become mainstream and less time will have to be spent selling it to people who really don't know the difference between a MVC and an MCP but don't want to risk their position by allowing some developer or consultant to lead them down the road to a minority used platform.

ScottGu has made some posts about what the MVC framework is and getting started with it which are a great read:

ASP.NET MVC Framework
ASP.NET MVC Framework (Part 1)
ASP.NET MVC Framework (Part 2): URL Routing
ASP.NET MVC Framework (Part 3): Passing ViewData from Controllers to Views
ASP.NET MVC Framework (Part 4): Handling Form Edit and Post Scenarios

Also, some other blog posts provide more detailed information about various aspects:

TDD and Dependency Injection with ASP.NET MVC
ASP.NET MVC Preview: Using The MVC UI Helpers

I can't wait to use this and already have some apps planned to use it ...

Tags:   ,
Categories:   .NET | MVC
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

NHibernate VistaDB Driver and Dialect

Friday, 7 December 2007 13:35 by Simon

Well, I finally got a bit of spare time and published the NHibernate driver and dialect for VistaDB as a CodePlex project.

As I mentioned in my previous blog entry, VistaDB is really useful even if you only use it during unit testing.

The really great thing about it though is that you can do normal database / NHibernate development and have a simple XCopy deployment which makes application demos very easy (complicated installs and configurations are often a barrier to evaluation and possible sales). Depending on your application and the usage that it gets VistaDB may or may not be up to the task of handling the persistence for the full deployment (it is a file-based database although a proper server version is on the way). With NHibernate though this isn't a worry as the customer is free to use any of the other supported database engines for the deployed version.

I intend to update a forum application I wrote a number of years ago to the new ASP.NET MVC about to be release and use the VistaDB database during development. The current SQL Server database is fairly large (about 4Gb) and has well over 2.5 million posts on it so it should give it a good test - I will let you know how I get on with it.

Tags:   , , ,
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (1) | Comment RSSRSS comment feed

Using VistaDB for unit testing (even if you target SQL Server)

Wednesday, 21 November 2007 16:06 by Simon

In case you aren't familiar with it, VistaDB is a lightweight, embedded database engine written entirely in managed code. It is a fantastic product that is coming on in leaps and bounds. Their aim is to be fully SQL compatible with SQL Server and are even adding support for TSQL.

I've used in on a few of my own projects and have been very impressed (I have a forum application with a 4Gb SQL Server database and approximately 2.5 million posts that I have just started converting to use it).

Even if you decide that you don't need it though it may still be worth looking at for testing purposes.

The client project I'm currently working on uses NHibernate for the persistence layer. Having developed an NHibernate Dialect and Driver for VistaDB (which I need to publish!) we've been able to use this when running unit tests. Instead of having to setup databases we can just create an in-memory database for use by the unit tests which is destroyed when they are finished. It is quick, convenient and avoids a lot of dependency issues PLUS it runs Linux / MONO (our app is cross platform).

 

Tags:   , ,
Categories:   .NET | Build
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

Generate build, solution and project files from Xml

Wednesday, 21 November 2007 15:35 by Simon

The current project that I am working on has experienced a few problems recently where developers have made changes to the build files (such as adding assembly references) but not the Visual Studio project files or vice versa which results in the rest of the team coping with a broken build or a solution that appears broken when first opened.

While the obvious and probably most common solution would be to use the Visual Studio definition of the projects as the master and create the build file from that (or use MSBuild directly) we do have some added complications that prevent this approach:

  • The application is cross-platform and has to run on Linux / MONO as well as Windows / .NET
  • There are C#, C++ and FORTRAN modules in the application (scientific computing)
  • Some developers work on Linux and do not want to use Visual Studio

I have evaluated and had some success with the Prebuild project which lets you define all the project settings and dependencies in an Xml file (which isn't too dissimilar to the Visual Studio format but is probably 'politically acceptable'). From this Xml file the tool generates the Visual Studio solution & project files plus the (NAnt) build files. It can also generate Mono Develop or Sharp Develop projects for use on Linux to keep everyone happy.

While it's a great tool there are a few things I don't like - I wish you could define your own templates for build files instead of being forced to use the one provided (although you can change the source to alter what it generates). Also, it doesn't directly support the build tool we are using (SCons) but I'm hoping we can switch to using NAnt at some point to fix some other issues.

It does address the main problem though - ensuring that there is only one 'truth' and a single way to add project references (in the Xml file). Adding it to the build files or the project files directly is pointless as they are both generated as part of the build process (which will then fail if the Xml definition is wrong).

Also, it's quite nice to just have source code checked into the repository ... no build files, no solution, no projects. Everything is created as needed which may also help as the team migrates to VS.NET 2008.

How the banks could thwart Phishing attacks

Wednesday, 21 November 2007 15:20 by Simon

Let's face it, the evidence is that Phishing works and that there is little the banks and other sites can do because anyone can setup a site that looks like another one and lure users to it.

Banks will obviously do what they can to shutdown phishing sites but they only need to stay alive for a short while and fool enough customers to make it worthwhile and it is obviously worthwhile because they keep doing it.

So, the answer is to make it *not* worthwhile.

Someones bank account details with logon information is a valuable commodity and can no doubt to sold or used directly.

What would be less valuable and less use to a phishing site owner is a list of millions of false accounts. Would they be able to sell 10,000,000 useless accounts that perhaps had a few genuine ones sprinked in it?

Perhaps when a phishing site is discovered the banks could deluge it was false account logons thus making the captured list of data practically worthless and adding to the time and effort required to copy the list around.

Would this work? I don't see why not.

Another benefit is that the bank could use the fake account logon information to detect attempts to logon to the accounts and potentially trace the people using the information illegally.

 

Tags:   ,
Categories:   Phishing
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

NAnt task for Red-Gate SQL Compare

Sunday, 7 May 2006 16:47 by Simon

One of the aims of Continuous Integration is to always have a releasable version of a project ready. For the code itself this is no problem but if the project includes a database with schema changes then it can be a little more complicated, especially if you have several versions of an application that are supported. You need a way of creating database change scripts for each version of the database as part of the build process.

Red-Gate make an excellent product called SQL Compare which can compare two database versions and produce a script to convert one version to the other and a SQL Toolkit that allows you to automate the process. They had a link to a NAnt task on their site but I found this a little inflexible so I created the one below which gives more control over what is compared and also allows you to set various SQL Compare options.

The main feature are that you can compare the current development SQL Server database against other databases and / or database snapshots with script generated to convert to and from each version. You can also save a database snapshot which can be put back into source control (as can the change scripts).

Here is an example of the configuration:


<?xml version="1.0"?>

<project name="comparesql" default="comparesql" basedir=".">

 <loadtasks assembly="C:\Program Files\nantsql-0.85-rc3\bin\NAnt.SqlTasks.dll" />


 <!-- target .NET framework and corresponding compiler directives -->

 <property name="nant.settings.currentframework" value="net-1.1"/>


 <target name="comparesql">

  <sql-compare

   folder="c:\output"

   title="TRUNK"

   server="DEVSERVER"

   database="AppDb"

   uid="dbuser"

   pwd="dbpassword"

   snapshotFilename="trunk.snp"

   scriptFilename="trunk.sql"

   saveScript="true"

   saveSnapshot="true">

   <objects>

    <object type="Field"/>

    <object type="Function"/>

    <object type="Index"/>

    <object type="Rule"/>

    <object type="StoredProcedure"/>

    <object type="Table"/>

    <object type="Trigger"/>

    <object type="UserDefinedType"/>

    <object type="View"/>

   </objects>

   <options>

    <option type="IncludeDependencies"/>

    <option type="IgnoreFullTextIndexing"/>

    <option type="IgnoreUserProperties"/>

    <option type="IgnoreUsers"/>

    <option type="IgnoreOwners"/>

    <option type="IgnorePermissions"/>

    <option type="TargetIsPreYukon"/>

   </options>

   <databases>

    <database

     title="BRANCH100"

     server="DEVSERVER"

     database="AppDb"

     uid="dbuser"

     pwd="dbpassword"

     snapshotFilename="BRANCH100.snp"

     scriptFilename="BRANCH100.sql"

     saveSnapshot="true"

     saveScript="true"/>

    <database

     title="BRANCH115"

     server="DEVSERVER"

     database="AppDb"

     uid="dbuser"

     pwd="dbpassword"

     snapshotFilename="BRANCH115.snp"

     scriptFilename="BRANCH115.sql"

     saveSnapshot="true"

     saveScript="true"/>

   </databases>

  </sql-compare>  

 </target>

</project>

I will post the source code on the main InteSoft.NET site for download.

 

Tags:   ,
Categories:   .NET | Build
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed

"Bad Request" error when using friendly URLs with special characters in ASP.NET

Sunday, 7 May 2006 16:45 by Simon

Our ASPRedirector.NET product can be used to re-write query-string URLs to friendly URLs with ID parameters converted to text. This is typically done for Search Engine Optimisation to improve page ranking because words appearing in the URL are taken into account by search engines. We have developed re-writing configuration rules for many eCommerce / shopping-cart software packages such as BV Software's BVCommerce and MediaChase's eFC.

However, if the category and / or product name contain certain reserved characters then you can run into a problem. Even if the characters such as $. %, ? are encoded correctly the page may not be returned and all you see is "bad request" (error 400). It isn't URLScan that is causing this though but the behavior of the ASP.NET ISAPI filter which doesn't pass the request on.

There is a Microsoft KB Article 826437 about the issue

The solution given is incorrect though and the correct registry key entry is shown below:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET]
  "VerificationCompatibility"=dword:00000001

This fixes the issue and allows you to have nice, optimised URLs on your eCommerce website - regardless of the characters in you category and product names.

 

Tags:   , ,
Categories:   .NET
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed