Geeks With Blogs

Tim Huffam Dotting the I and crossing the T of I.T. ASP.NET
Programmatically create a branch with the TFS 2010 API
When creating a branch programmatically using the TFS 2010 API, if you do not do things in the correct sequence, TFS does not create the proper object types and/or relationships eg either the folders will not show as branches (showing the branch icon instead of the folder icon) in Source Control Explorer or they will show as branches, but when you do View Hierarchy, it will not show the relationships/structure. After much trial an error I have found the solution... (assuming the source folder already ......

Posted On Thursday, April 19, 2012 10:40 PM

How to change the endpoint url of services that Silverlight clients use.
If your Silverlight app references services, the endpoints to these services are stored within a config file within the xap bundle - which is usually deployed as .xap file within the ClientBin dir of your web app. To change the end point urls:1) Rename the xap file (eg within E:\Demos\MySilverlightApp.W... to .zip. 2) Unzip it 3) Edit the ServiceReferences.ClientConfig file (to update the endpoint url) and save it.4) Recreate the zip file5) Rename the .zip file as .xap That's it ......

Posted On Sunday, January 8, 2012 8:17 PM

TFS 2008 error: MSB4131: The "Reason" parameter is not supported by the "GetBuildProperties" task.
This error occured on our TFS2008 (RTM) build server after installing VS2010. This is caused because VS2010 updates the MSBuild targets file Microsoft.TeamFoundation.Bu... but not the Microsoft.TeamFoundation.Bu... file (which preforms the tasks mentioned in the targets file). To resolve you need to update TFS (build) server with SP1. See this article. HTH Tim ......

Posted On Thursday, February 3, 2011 5:22 PM

Error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk
This error occurred on our TFS2008 build server which we had upgraded to cater for VS2010 projects (by installing VS2010 on the build server - see this article). Error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\Vis... was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. However - although we had installed VS2010 on the build server - we had not installed ......

Posted On Wednesday, December 8, 2010 1:46 PM

Creating mulitple TFS Build services on the same server - one for VS2008 projects and one for VS2010 projects
This is for TFS2008. This is based mainly on this article: But also had input from these: Also the following article discussing upgrading a ......

Posted On Wednesday, December 1, 2010 8:51 PM

Upgrade TFS 2008 to be able to build VS2010 solutions/projects - need to delete workspaces
After following steps in this link, I found that my projects would still not build correctly. The error I got in the build was: "The path C:\Documents and Settings\myBuildServiceUser... Settings\Temp\myProject\Bui... is already mapped in workspace myBuildServerMachineName_16." To fix this problem you need to delete all workspaces on the build server (owned by the user account that the build service runs as) - these are named buildservername_nn where buildservername ......

Posted On Sunday, August 22, 2010 5:51 PM

VS2010 debugger catching AssertFailedException instead of running and failing tests
When workig on a project in VS2010 and performing a "run tests in context" the debugger was catching and halting on a test that fails, raising the exception AssertFailedException. I thought this was strange as the same test (in fact any test) that failed in VS2008 would simply just be noted in the test results as Failed... Turns out it's the way I've been running tests.. Both VS2008 and VS2010 have the same shortcut mappings: - "ctrl-r, t" for "Run tests in context" - "ctrl-r, ctrl-t" for "Debug ......

Posted On Wednesday, July 28, 2010 9:18 PM

Databinding a .Net WinForms ComboBox to an Enum
This is quite simple... Define the enum eg: public enum MyEnum{ ItemOne, ItemTwo, } Within the form set the datasource of the combobox to the values of the enum eg: myCombo.DataSource = System.Enum.GetValues(typeo... To have the combo auto select a value based on a bound object, set the databinding of the combo eg: class MyObject{ private MyEnum myEnumProperty; public MyEnum MyEnumProperty{get {return myEnumProperty;}} } MyObject myObj = new MyObject(); myCombo.DataBindings.Add(new Binding("SelectedIndex", ......

Posted On Wednesday, April 7, 2010 10:00 PM

Centering div tags using CSS
As text-align doesn't work I use a simple work around: .mydiv{ width: 100%; left: 50%; } It's not perfect - but very simple and easy to understand - and you can modify it to suit. Seems to work ok in IE 6 & FF 2.0. Here's another method ( - but I found it not obvious/simple enough (expecially for others who may have to maintain the css down the track - KISS) HTH Tim ......

Posted On Tuesday, May 15, 2007 5:11 PM

Remote debugging with ASP.NET 2.0 - finding the process id (PID) of the worker process.
To start remote debugging an ASP.NET 2.0 app (assuming the app is up and running on the remote server): On the remote server start the Visual Studio 2005 Remote Debugger. For this you need to have the VS2005 Tools installed (not necessarily the full VS2005). On your local machine, within VS2005 select Debug - Attach to Process... In the Qualifier field (in the Attach to Process screen) enter the name of the remote server and press ENTER. Select the IIS worker process (w3wp.exe) that is running your ......

Posted On Tuesday, August 8, 2006 10:56 AM

Turning on code coverage/instrumentation in a TFS Build
This requires a testrunconfig file that has been configured correctly. To do this I did the following: In VS2008, right click on Solution Items folder and select Add - New Item... Select Test Run Configuration and enter the name WithCodeCoverage.testruncon... Open/edit this file in VS. Select the 'Code Coverage' item on the left, then selected (checked) the assemblies I wanted to instrument Click Apply to save these changes. Note that you can select which is the active test run configuration from ......

Posted On Tuesday, June 16, 2009 11:32 PM

How to turn on unit testing in your TFS build
The following will make your builds (running on a TFS Server) execute your unit tests after the build: Open your build file (eg TFSBuild.proj). VS2008 has a nice xml editor for this. Search for the RunTest node and change it from: <RunTest>false</Ru... to: <RunTest>true</Run... Look for a section that starts with: <ItemGroup> <!-- TEST ARGUMENTS ... and add nodes within this (after the comments and before the closing of the ItemGroup node) - one entry for each ......

Posted On Tuesday, June 16, 2009 10:54 PM

How to unit test against resources (localization) values within Visual Studio 2008
When unit testing you sometimes need to test that values are being set to the correct literal/constant value - and this value is often stored in a resources file. However, for some reason the VS2008 'Create Private Accessor' feature did not work for me for resources (maybe be cause they're all static properties and the generated _Accessor classes need to be instantiated). So to make these resource available within the unit test project I simply made the Resources class public (by default it's internal). ......

Posted On Friday, May 22, 2009 4:07 PM

Error: Failed to access IIS metabase. Hosting WCF Service in IIS
This error ("Failed to access IIS metabase") can occur when you try to access your WCF when you have added for hosting within IIS. To solve this problem do this: Reregister ASP.NET for IIS: Open an Visual Studio Command Prompt (or a regular command prompt and cd into the .Net dir - usually: C:\WINNT\Microsoft.NET\Fram... then type: aspnet_regiis -i When complete, from the same command prompt run: iisreset Verify your IIS virtual/app dir is setup correctly (uses .Net 2). If you don't ......

Posted On Thursday, May 14, 2009 3:13 PM

Script to remove unchanged files in TFS/VS2008
TFS has a wonderful feature whereby it marks files as changed, even though there are no changes. These files show up in the Pending Changes window in Visual Studio (VS 2008). To work around this, add the following external command to your VS tools: First you need to install TFS Power Tools In VS go into Tools - External Tools and click Add Enter the following details: Title: Unchange Command: C:\Program Files\Microsoft Team Foundation Server 2008 Power Tools\tfpt.exe Arguments: uu /recursive /noget ......

Posted On Thursday, January 22, 2009 3:31 PM

How to move/drag objects in Silverlight (2.0)
The following code shows you how you can make Silverlight controls/objects moveable by dragging them with the mouse. Page.cs: <UserControl x:Class="MovingObjs.Page" xmlns="http://schemas.micro... xmlns:x="http://schemas.mic... Width="400" Height="300"> <Canvas x:Name="LayoutRoot" Background="White"> <Border CornerRadius="10" x:Name="brdMovable" BorderBrush="Black" BorderThickness="2" Background="AntiqueWhite" Canvas.Top="100" ......

Posted On Wednesday, November 5, 2008 12:24 PM

How to remove TFS workspaces
This will actually remove the your workspaces - unlike the VS/TFS Source Control Explorer which simply does not display them - duh! From the VS command prompt: tf workspaces /remove:* ......

Posted On Thursday, October 9, 2008 9:10 AM

Firefox 3 ignores cache control http headers - security risk for online apps!
If a user, using Firefox 3, signs out of a web site and does not close the browser, anyone else using that browser subsequently can view the content of pages loaded by the previous user (eg in an internet cafe, or any place where workstations are shared eg universities) - exposing private/confidential data. This only affects HTTP post requests (not gets) and only Firefox version 3 - earlier versions (1.5, 2 etc), and IE, are not affected. The main points are: This is definately a bug: a violation ......

Posted On Friday, September 26, 2008 3:17 PM

ASP.NET SQL Server error: The connection was not closed. The connection's current state is open
The following error occured when 2 requests hit an ASP.NET (2.0) web app (using SQL Server 2005) at the same time: The connection was not closed. The connection's current state is open Normally this only occurs if you have a connection that is not being closed. However in our case all connections where being closed using a try-finally block (personally I prefer using a using block). This error only occured when the 2 request were initiated from different machines. It turns out that the error occured ......

Posted On Tuesday, September 9, 2008 12:48 PM

Task Oriented Programming
For some time I've been wondering if there's a better way to program business logic. Years ago I used to write COBOL, then moved onto a 4GL, bla bla bla... and today I find myself well entrenched in OO with Microsoft's .Net. Development times don't seem to be much better these days - and the complexity of things seems to have mushroomed. We went from barely-a-3GL to 4GL back to 3GL plus an explosion of things you need to consider. We started with procedural code then moved to OO and seem to have ......

Posted On Tuesday, September 9, 2008 12:10 AM

CSS Absolute positioning in Firefox and IE
A couple of notes regarding absolute positioning in FF and IE... Specifying position values: IE allows you to omit the unit of measurement for Left and Top. It assumes pixels eg: = 10; However FF requires that you specify the unit of measurement eg: = "10px"; Using other elements parents to calculate your object's position: The scenario might be you have a div that you want to position over or by another object - but that object has no position values. In this case I ......

Posted On Saturday, September 6, 2008 9:57 AM

VS 2008 crashes when running unit tests - VSPERF?
Sometimes Visual Studio 2008 (Team System Developer Edition - with Team Explorer and TFS Power Tools) crashes (disappearing completely) when running unit tests. I have not yet tried SP1 for VS2008 - will hopefully try this in the next week or two. Not really sure what causes this - but have noticed that the following error is written to the windows event log prior to the crash (not at the same time). Event Type: Error Event Source: VSPERF Event Category: None Event ID: 1406 Date: 22/08/2008 Time: ......

Posted On Wednesday, August 27, 2008 9:36 AM

VS2008 Javascript debugging error: The breakpoint will not currently be hit. No symbols have been loaded for this document
When trying to debug javascript using Visual Studio 2008 there a couple of things you need to do first - otherwise it (debugging) will not work and you'll get the following error when you hover over breakpoint in your javascript: The breakpoint will not currently be hit. No symbols have been loaded for this document. Note that this is only for debugging using IE (6) - not sure about other browsers/versions. Within IE go into Tools - Internet Options - Advanced tab and make sure the 'Disable Script ......

Posted On Monday, August 18, 2008 10:04 AM

How to find out what the client (browser) is posting back to the server (with ASP.NET C#)
For those of you wanting to know just what is being sent (posted) back from the client (browser) to the server (ASP.NET) - when a postback occurs - use the following lines in your C# ASP.NET program: string msg = ""; for (int i = 0; i < Request.Form.AllKeys.Length; i++) { msg += i.ToString() + " " + Request.Form.GetKey(i) + ": " + Request.Form[Request.Form.G... + "\r\n"; } System.Diagnostics.Debug.Wr... Either look at the output window or put a break-point on the last line so you ......

Posted On Thursday, July 24, 2008 1:43 PM

Web development client side debugging - display area, javascript injection and accessing the dom at runtime
For those of you who don't have access to IE or FF dev toolbars - this is how we used to do client side runtime debugging... Drop the following code into your web page (preferrably at the bottom): <script> function log(text){ document.getElementById("lo... = text; } function dump(){ log(document.body.innerHTML); } function logProps(obj){ var msg = ""; for(var i=0;i<obj.attributes.len... { msg+=obj.attributes[i].node... + ": " + obj.attributes[i].nodeValue + "\r\n"; } log(msg); ......

Posted On Friday, July 11, 2008 10:52 AM

ASP.NET 3.5 controls not being rendered
For some reason some controls/tags within ASP.NET do not always get rendered/passed to the client. This has happened to me on a number of occasions. It seems limited to <style> and <script> tags - but happens for both raw HTML (within the aspx designer) and dynamically created tags (eg using new HtmlGenericControl("style")... This is happening to controls/tags within AJAX updatepanels within, webforms and usercontrols. Sometimes I can work around this by simply placing these controls/tags ......

Posted On Wednesday, July 9, 2008 10:50 PM

Javascript error using Telerik controls with ASP.Net: Error: 'Telerik' is undefined
The following javascript error occurs when trying to use the Telerik controls and you haven't updated your ASP.NET (2.0) web.config file correctly. Error: 'Telerik' is undefined To fix make sure the following lines are within the <system.web> section of your web.config file: <httpHandlers> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.S... System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad36... validate="false" ......

Posted On Wednesday, July 9, 2008 9:03 AM

Visual Studio (VS200) loosing it's source control bindings
VSTS2008 has, on occasion, lost it's source control settings - specifically, the bindings to TFS server for a given solution and it's projects. This seems to be because the solution and project files are not being updated when you use the TFS Source Control Explorer to do a 'Get Latest' - a 'feature' of VS2008 which allows you to work disconnected/offline - however it seems to have an issue trying to reconnect itself. To resolve we simply removed the local source directory and did a 'Get Specific ......

Posted On Thursday, June 12, 2008 11:08 AM

Manually configure a web app dir for a specific version of the .NET framework
In some cases you may want or need to change the version of .NET that a particular web application directory uses. Normally this is done via the ASP.NET tab on the IIS properties page for the web app, however it can also be done manually at the command line... CD into the dir containing the version of .NET that you require eg: C:\WINDOWS\Microsoft.NET\Fr... Run aspnet_regiis.exe specifying the name of the dir you want this set against. eg aspnet_regiis.exe -s W3SVC/nnn/ROOT/xxx (where ......

Posted On Friday, August 4, 2006 12:24 PM

VS Collection Manager location. Registering/enabling html help collections.
Use the Collection Manager to enable/disable which html help collections are available to your Visual Studio IDE (dynamic help etc). For VS.NET 2003 use: ms-help://MS.VSCC.2003/VSCC... For VS2005 use: ms-help://MS.VSCC.v80/dv_vs... For more info see the FAQ at the Helpware Group's web site. HTH Tim ......

Posted On Thursday, July 13, 2006 8:52 AM

Case insensitive XPath

XPath statements are case sensitive.  To get around this use the following example to convert all data to lower case before performing the equality check:

/bookstore/book[translate(@category, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + searchtext.ToLower() + "']

Thanks very much to Harish for this!

Posted On Thursday, July 6, 2006 11:01 AM

System.ObjectDisposedException: Cannot access a disposed object. Getting Linq to prepopulate/explicitly fetch data from the database.
Exception: System.ObjectDisposedExcept... Cannot access a disposed object. Object name: 'DataContext accessed after Dispose.'. This can occur when using Linq to SQL to retrieve data from a database - and when you try to access data after the data context object has been disposed. More specifically, the exception occurs when trying to access an item that has not yet been retrieved from the database and the data context object has been disposed. This often occurs when using a variable, that was populated ......

Posted On Tuesday, June 3, 2008 9:41 AM

Cannot change column to Not Null: Cannot insert the value NULL into column '', table '.dbo.Tmp_'; column does not allow nulls.
When modifying a table SQL Server (2005) and unchecking a column's 'Allow Nulls' (ie trying to make the column Not Null) the following error may occur: '<tablename>' table- Unable to modify table. Cannot insert the value NULL into column '<columnname>', table '<dbname>.dbo.Tmp_<... column does not allow nulls. INSERT fails.The statement has been terminated. This occurs if there is already data in this table and this column contains nulls. The solution is to simply ......

Posted On Thursday, May 29, 2008 9:05 PM

MSBuild fails when building solutions with database projects
There is a known problem with MSBuild whereby it does not cater for database project types as these project types (database projects) are not buildable. This is only an issue when specifying a solution file (as the item to build) within the MSBuild script. Because these are not buildable projects VS does not show them in the solution configuration manager. Unfortunately this means they cannot be manually configured not to build (as a work around to this problem). When using solution files within ......

Posted On Tuesday, May 27, 2008 6:20 PM

cannot run unit tests in VS2008 - Test Run deployment issue: The location of the file or directory is not trusted.
This is an error message I got when trying to run unit tests within Visual Studio 2008 (developer edition): Failed to queue test run 'tim@MyComputer 2008-02-11 10:33:11': Test Run deployment issue: The location of the file or directory 'c:\nettiers\adventureworks... is not trusted. The application is .NetTiers generated app (pointing .nettiers to the Adventureworks db - Microsoft's SQL Server sample database). I believe the problem ......

Posted On Monday, February 11, 2008 1:58 AM

ASP.NET error running web app: HTTP Error 403 - You are not authorized to view this page
This error occurs when attempting to view an application (using the Run button or right clicking on the project and selecting 'View in browser'). This usually occurs because the browser is looking for something that does not exist. For example, when using the project name 'MyProject', VS opens a browser with the following URL: http://localhost/MyProject/ Although this points to a project (virtual directory/application within IIS), it does not point to a specific resource. In my case I just ......

Posted On Thursday, February 7, 2008 2:48 AM

Application Architecture, Software Development Frameworks, ORM, MVC/P and the Holy Grail - Part 1
Note this article is primarily based on Microsoft/.Net technologies, although the principle apply to any technology. Before development of any reasonable business software project begins the following areas need to be nailed down: Application Architecture (application structure) ORM (Object/Relational Mapping - data source access and translation to/from business objects) Base framework (system framework, helper classes, base classes, etc) UI. There are many tools available that will dictate or guide ......

Posted On Sunday, February 17, 2008 3:25 PM

Using strings and enum - C# .NET
I've read a few articles recently regarding the use of strings with enums - discussing how to access the constant name values or how to set a variable with the correct value when you only have a string value (enum constant name) - and all present somewhat convoluted ways of achieving this. I'm guessing the authors are not aware that the .Net framework provides methods for this - out the box. Hopefully the following code shows how to do this. private enum CarTypes { Lotus = 0, Morgan = 1, Atom = 2 ......

Posted On Tuesday, September 18, 2007 3:47 AM

Unit testing with NUnit and member accessibility - and the InternalsVisibleTo attribute
One of the annoying things about unit testing, is that not all members of the target code class are accessibly to the test fixtures. There are limited options to work around this (as you really don’t want to put the unit tests within the code assembly). In the past, the usual method has been to open up the access levels of the code class members. This isn’t ideal from a best practices and security point of view. However, as of .Net 2.0 a better method has been introduced. This is to use the InternalsVisibleTo ......

Posted On Thursday, August 30, 2007 4:39 AM

.Net Error: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException : The type '... .LoggingExceptionHandler..' cannot be resolved.
Here's another problem I had when trying to get the Microsoft Enterprise Library - exception logging working. The following error was caused because I did not add references to all the assemblies used. MyApp.UnitTests.BuildHelper... : Microsoft.Practices.Enterpr... : The type 'Microsoft.Practices.Enterp... Microsoft.Practices.Enterpr... ......

Posted On Monday, August 27, 2007 4:24 AM

.NET Error: System.Configuration.ConfigurationErrorsException : An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly
The following error was caused because of referencing unsigned (not strongly typed) assemblies - in my case because I was using assemblies from the Enterprise library source/working dir (C:\EntLib3Src\App Blocks\bin) instead of from the main Enterprise Library install dir (C:\Program Files\Microsoft Enterprise Library 3.1 - May 2007\Bin): MyApp.UnitTests.BuildHelper... : System.Configuration.Config... : An error occurred creating the configuration section ......

Posted On Monday, August 27, 2007 4:16 AM

NUnit not working properly - cannot find TestFixtures (Reason: Has no TestFixtures)/getting Visual Studio to automatically run NUnit
When trying to run NUnit against an assembly, it loads the assembly fine, but when you run it, it cannot find any tests (even though the assembly contains many tests). Under the 'Tests Not Run' tab, if you expand the treeview, it states: "Reason: Has no TestFixtures". This problem is caused when NUnit does not have adequate rights to the assembly. In my case it was because my project was on a network drive. A simple solution to this is to add a post build event in Visual Studio to copy the assembly ......

Posted On Thursday, August 2, 2007 2:23 AM

Manually writing to the same windows event log as log4net
This is something I wanted to do as a quick work around (rather than writing my own log4net appender) to being able to write SuccessAudit and FailureAudit events to the event log (something which log4net does not support out the box). Here's the method I used: private static ILog _Log = LogManager.GetLogger(Method... static log4net.Appender.EventLogAp... _eventLogAppender = null; // This only works if you have an EventLogAppender configured.public static ......

Posted On Thursday, December 7, 2006 2:47 PM

Unhandled exceptions in secondary threads on .NET 2.0 will shut down the whole app.
Under .NET 2.0 an unhandled exceptions on a secondary thread now are no longer swallowed by the framework - instead they will shut the app down. However using the AppDomain.UnhandledException event will handle this - or you can revert to .NET 1.1 behavior by adding this line to your config: <legacyUnhandledExceptio... enabled="1" /> You should now use a try/catch block on every thread entry method. See this great doc on threading (page 12 inparticular). Thanks to Matt and Jan for this ......

Posted On Wednesday, November 22, 2006 12:01 PM

Error installing .Net 3.0: Microsoft .NET Framework 3.0 has encountered a problem during setup.
This error: Microsoft .NET Framework 3.0 has encountered a problem during setup. Setup did not complete correctly. occured while installing the .NET 3.0 redistrubutable (downloaded from here) on my PC running XP Pro SP (also with .NET 1.1 & 2.0). After some investigation it turns out this error was caused when installing the WCF (Windows Communication Foundation) components - when trying to open the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\C... ......

Posted On Friday, November 17, 2006 9:28 AM

SQL Server datetime set blank or null = SQL Server error: System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
This error (System.Data.SqlTypes.SqlTy... SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.) will occur if you try to pass an uninitialised DateTime value into an SQL Server stored procedure from .NET code (in my case C# in an ASP.NET app). To work around this you must pass in a value - null will not work. In my case I have a generated class that passes a System.DateTime variable into the System.Data.SqlClient.SqlCo... method. So my ......

Posted On Wednesday, November 8, 2006 8:32 PM

Printing nicely from the web: Printing web pages or alternate documents
Many web pages are not designed with any consideration for printing - this is one of those annoying things that one comes across more often than not. Here are a couple of simple ways to make sure your pages are printed in a formatted way: Use a specific print style sheet. This is the most common approach used on the web. The idea being you create another stylesheet that is specifically for formatting your web page(s) for printer output. There are many examples on the web of how to do CSS so I won't ......

Posted On Tuesday, October 31, 2006 12:30 PM

DOM Inspector missing from Firefox 2.0
If you've just installed Firefox 2.0 and found that the DOM Inspector is missing, here's how to add it: Run the Firefox 2.0 install again. Choose to do a Custom install (not the default of Standard) Make sure DOM Inspector is selected. Complete the install. I had previously posted a solution for missing DOM Inspector for Firefox 1.x here. However that solution does not work with Firefox 2.0. HTH Tim ......

Posted On Wednesday, October 25, 2006 12:46 PM

ASP.NET event firing twice
This seems to be a very common problem where by your event handler method gets run twice. It is caused by VS.NET inserting 2 wireup of the event handler: - once in the aspx (HTML) eg: <asp:Button ... OnClick="btnTest_Click" /> - and once in the VS.NET generated section (InitializeComponent) eg: this.btnTest.Click += new System.EventHandler( The easiest solution, imo, is to simply remove the "OnClick..." HTML markup from the .aspx page. Eg change this: <asp:Button ID="btnTest" ......

Posted On Monday, October 23, 2006 4:27 PM

ASP.NET error: An error occurred creating the configuration section handler for DrKW.Directory.WebService: Could not load file or assembly 'DrKW.Directory.WebService' or one of its dependencies
The following error occurred when I tried to run a ASP.NET app that had just been converted from .NET 1.1 to .NET 2.0 (using the VS2005 wizard): An error occurred creating the configuration section handler for DrKW.Directory.WebService: Could not load file or assembly 'DrKW.Directory.WebService' or one of its dependencies. The system cannot find the file specified. The problem is exactly as the error message states - "The system cannot find the specified file". My section element within configSections ......

Posted On Tuesday, September 5, 2006 12:16 PM

ASP.NET error: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level
The following error occured because a web.config file existed, in a directory beneath my main app root dir, should not have been there: It is an error to use a section registered as allowDefinition='MachineToA... beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. C:\Dev\SVN\authenticationse... It is actually valid to have a web.config in a dir beneath your app ......

Posted On Tuesday, September 5, 2006 12:07 PM

Cannot add diagram to SQL Server 2005 DB: Database diagram support objects cannot be installed because this database does not have a valid owner.
When trying to add a diagram to an SQL Server 2005 db I got the following error:Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects. I tried the suggestion mentioned in the message but that didnt work. Also found that SQL Server Management Studio ......

Posted On Wednesday, July 5, 2006 7:36 PM

Error: System.Net.WebException: Too many automatic redirections attempted.
This error can occur when an application performs a web request to a web app that's trying to interogate the Request.UserAgent - but the requesting app has not set the user agent in the request. To resolve either set the user agent before sending the request eg: HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(theUr... (compatible; MSIE 6.0; Windows NT 5.1)"; Alternatively, and preferrably (if you have access to it), fix the server side web application to check ......

Posted On Tuesday, July 4, 2006 2:45 AM

Error using client certs: The page requires a valid client certificate (403.13). How to turn off CRL checks in IIS.
The following error may occur when trying to use a client cert for the first time (this error is from IIS 5): The page requires a valid client certificate The page you are trying to view requires the use of a valid client certificate. Your client certificate was revoked, or the revocation status could not be determined. The certificate is used for authenticating you as a valid user of the resource. HTTP 403.13 - Forbidden: Client certificate revoked The cause of this is usually "the revocation status ......

Posted On Monday, June 12, 2006 9:57 AM

Installing Community Server 2 - web install on XP localhost with sqlexpress
I had to resort to using the web installer as the CS MSI installer didn't work (threw error stating it could not find MDAC 2.7 or above - even though I'm running XP Pro SP2 which has the MDAC components built into it - duh!). Download CS 2 web install & unzip. Edit Installer\default.aspx - modify the line: bool INSTALLER_ENABLED = false;so the installer is enabled eg: bool INSTALLER_ENABLED = true; Using IIS admin, create virtual dir (eg 'cs') pointing to the 'web' dir beneath the installation. ......

Posted On Thursday, June 8, 2006 7:24 AM

ASP.NET 2.0 error: Unable to start debugging on the web server.
The following error may occur when trying to run/debug an ASP.NET 2.0 web app, when the web server is not configured properly: "Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information." This is usually caused because of one or both of the following problems: The directory the web app resides in has not been registered as a web application. The correct ......

Posted On Monday, May 29, 2006 6:08 PM

Atlas web site templates missing from "My Templates" after Atlas installation
If you've just installed ASP.NET Atlas, and have started up VS2005, clicked File - New - Web Site... ..but, hang on... the "Atlas Web Site" template isn't there (as it should be according to the 'Setup your environment' section of the Atlas setup). In my case it appears that the original installation either had a problem (although I don't remember any issues at the time) or some how corrupt the templates or lost reference to them. Well all's not lost. To fix I did the following: Open Windows Explorer ......

Posted On Thursday, May 25, 2006 6:46 PM

How to convert special characters to HTML encoded equivalents using C#.NET
public string HTMLEncodeSpecialChars(string text){ System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (char c in text){ if(c>127) // special chars sb.Append(String.Format("&a... else sb.Append(c); } return sb.ToString();} ......

Posted On Thursday, May 25, 2006 12:31 PM

How to get ascii/unicode character codes using C#.NET
For each character in the string this displays: The character It's unicode character code in hex It's unicode character code number string text = "0 a+…”"; foreach (char c in text) { Console.WriteLine("{0} U+{1:x4} {2}", c, (int)c, (int)c); } HTH Tim ......

Posted On Thursday, May 25, 2006 12:28 PM

System.DirectoryServices.DirectorySearcher.Timeout and ServerTimeLimit not working for non AD LDAP directory (GDS)

I've been running several searches against a GDS LDAP directory - and
the Timeout and ServerTimeLimit properties of the DirectorySearcher
class appear to have no effect.

After further testing I've discovered that the problem is caused because I was using sub second timeout periods eg 500ms - and the LDAP server I'm accessing (GDS) only supports timeout periods of whole number seconds.



Posted On Friday, May 19, 2006 8:34 AM

Access is denied - Javascript error when attempting to load xml from an external site.
As yet I don't have the answer to this problem - so any suggestions would be very much appreciated! I have a JS library with an object that loads xml from a specified URL and populates specified HTML elements with the data. This works fine. However recently I refactored the code that calls this library, to be more OO (to allow it to be more easily extended). Now the xml "load()" method raises the error "Access is denied" when loading from external urls. I've proved that the load library still works ......

Posted On Wednesday, May 17, 2006 8:13 AM

DOM Inspector not working in FF (FireFox)
When you install Firefox on windows, by default it does not install the DOM Inspector. To make sure it installs it, select Custom Install then select Web Developer Tools. If you already have FF installed you can install the DOM Inspector without having to reinstall FF: Run the FF installer - just so it unpacks the install without installing anything. Use file explorer to locate the C:\Documents and Settings\<username>\L... Settings\Temp dir. FF will have created a temp directory to unpacked ......

Posted On Thursday, May 11, 2006 7:40 PM

Problems with NDoc (content not updating/reflecting changes or missing content)
If you are not seeing changes you've made to your xdoc comments, it's possible that NDoc is referring to an old xdoc file. I had this occur when, some time ago, I had set my project's build options to use a XML Documentation File (eg MyAssembly.xml), then at a later state I cleared the setting. When I set up NDoc to point to my assembly (eg MyAssembly.dll) it used the MyAssembly.xml file instead. This caused two problems - firstly it the docs were out of date, and secondly any changes I made subsequently ......

Posted On Tuesday, May 2, 2006 2:06 PM

text-align: center; not working in Firefox
I have the following scenario: .container{ text-align: center; border: solid 1px blue;}<div class=container><tabl... In IE (6) this displays as you would expect (with the table centered). However with Firefox (1.5) the table is left aligned. Apparently this is due to a bug with the way FF handles CSS. The workaround is to use this: text-align: -moz-center;instead of text-align: center; Don't ask me why "-moz-center" ......

Posted On Wednesday, April 19, 2006 7:28 PM

Error (m_safeCertContext is an invalid handle.) when accessing a client certificate using .NET 2.0/VS2005
This error (m_safeCertContext is an invalid handle.) occurs when you try to access a client cert (or a member of the cert) from a ASP.NET 2.0 application developed using VS2005 eg: X509Certificate cert = new X509Certificate(Request.Cli... certSerial = cert.GetSerialNumberString(); The error is thrown because no valid certificate is found. This can be caused by either: A problem with the cert. A common reason for this in a development environment is one of the cert properties ......

Posted On Tuesday, April 18, 2006 1:58 PM

CSS nowrap alternative
To achieve the same results as a TD nowrap (<td nowrap="true">) using cascading style sheets, use the following: white-space: nowrap; This style attribute only applies at the TD element level ie needs to be applied to each TD, ie not the the TR or TBODY. If you're desparate to not apply it to each TD, then you can get away with only applying it to the TD's of the first row - but this is only effective if applied to the cells containing thelongest data (so IMHO is a half-baked approach - ie ......

Posted On Sunday, April 16, 2006 4:48 PM

Converting an integer to hexidecimal using C#.Net

This is done using the String.Format method.  You can use both positive or negative decimal values (that must of course be integers) eg:

int decimalValue = -12345;
Console.WriteLine (String.Format("{0:x2}", decimalValue));


Posted On Tuesday, April 11, 2006 11:33 AM

Log4Net - writing to windows event log with ASP.NET
I found that there were a couple of things required to get this working - over and above the samples shown here. To initialize Log4Net and to tell it to load it's configuration from the web.config file add the following line to the Application_Start method within Global.aspx: log4net.Config.XmlConfigura... To make sure all unhandled exceptions are logged add the following line to the Application_Error method within Global.aspx: Log.Fatal("An uncaught exception occurred", this.Server.GetLastError())... ......

Posted On Thursday, April 13, 2006 7:48 AM

Running NUnit against multiple versions of .NET (1.1 and 2.0) from Visual Studio (VS.NET 2003 and VS2005)
This is not the prettiest solution - but is the only way I could easily get it all working - so I could click the Run button from VS to startup NUnit and run my tests project. As a primer, read James Newkirks article on this (he explains the config files a bit more than I do). Firstly to get NUnit to work with .NET 2.0 assemblies you need to have this in your nunit config file (nunit-gui.exe.config): <startup> <supportedRuntime version="v2.0.50727" /> <requiredRuntime version="v2.0.50727" ......

Posted On Thursday, March 30, 2006 8:47 AM

How to determine assembly and .NET CLR runtime versions at runtime.
This really very simple, once you know how.... To get the version of the currently running assembly: System.Reflection.Assembly assembly = System.Reflection.Assembly.... assemblyName = assembly.GetName();Version assemblyVersion = assemblyName.Version; To get the version of the CLR runtime: Version CLRVersion = Environment.Version; ......

Posted On Tuesday, March 28, 2006 3:14 PM

System.BadImageFormatException : The format of the file ‘TestLibrary’ is invalid. NUnit on VS 2005 / .NET 2.0
A thousand thank you's to James for this post:

Posted On Friday, March 24, 2006 12:37 PM

Cannot access System.Web.HttpContext.Current.Session - or web app terminates, when using
When you reference System.Web.HttpContext.Curr... within a class (that is not a page or control) and the method has the [AjaxPro.AjaxMethod] attribute it terminates the current execution and returns to the client. To solve this you simply need to provide the HttpSessionStateRequrement argument to the AjaxMethod attribute - setting it to the appropriate enumeration (None, Read or ReadWrite) eg: [AjaxPro.AjaxMethod(AjaxPro... string MyAjaxMethod(){...} ......

Posted On Wednesday, March 22, 2006 6:49 PM

VS.NET error when browsing web services: The proxy settings on this computer are not configured correctly for web discovery
The proxy settings on this computer are not configured correctly for web discovery. Click the Help button for more information. This error occurs (in VS.NET 2003) when trying to browse for web services (add a web reference) if you are behind a proxy &/or firewall. The solution for this is posted on the MS site: ......

Posted On Tuesday, March 14, 2006 2:30 PM

.NET 2.0 error: Request for the permission of type 'System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
This error occurred when trying to run code that accessed the System.DirectoryServices namespace. To work around this, just open up your .NET 2.0 security: Start the .NET Framework 2.0 Configuration tool (from Administrative Tools). Expand Runtime Security Policy. Expand User - Code Groups and right-click on All_Code and select Properties. On the Membership Condition tab make sure All Code is selected in the dropdownlist. On the Permission Set tab make sure FullTrust is selected in the dropdownlist. ......

Posted On Wednesday, March 8, 2006 1:40 PM

Serialization: How to serialize and deserialize using C# .NET
Serialize (convert an object instance to an XML document): // Assuming obj is an instance of an objectXmlSerializer ser = new XmlSerializer(obj.GetType()... sb = new System.Text.StringBuilder()... writer = new System.IO.StringWriter(sb);... obj);XmlDocument doc = new XmlDocument();doc.LoadXml(s... Deserialize (convert an XML document into an object instance): //Assuming doc is an XML document containing a serialized object and ......

Posted On Thursday, February 9, 2006 2:59 PM

Error: The underlying connection was closed: The remote name could not be resolved. When doing HttpRequest from ASP.NET.
The following error occured when trying to open a web page (ASP.NET) that was doing an HttpRequest. "The underlying connection was closed: The remote name could not be resolved." This is usually caused because the ASP.NET app is on a network that is using a proxy server - and as ASP.NET does not run as a user account, it does not have access to the proxy settings in the registry. To resolve add the following section to your web.config file. <defaultProxy> <proxy usesystemdefault = "false" ......

Posted On Thursday, February 9, 2006 9:20 AM

SQL Server 2005 SQLExpress error: ...provider: Named Pipes Provider, error 40 - Could not open connection to SQL Server
I got this error immediately after installing VS2005 & SQL Server 2005 Express and trying to establish my first connection using the new server - not a good start at all - and by the looks of it, it's happened to many hundreds, if not thousands, of others too. Generally this error occurs if you cannot connect to the SQL server - as the message says (no sh*t). However, what's not obvious is why... First suggestion is to make sure that you specifiy the instance name as well as the server name (christ ......

Posted On Monday, January 30, 2006 12:32 PM

IE bug: HTTP POST with zero content-length (content-length = 0) (even though there is data in the post request)
This little gem comes to us courtesy of MS's IE, whereby it resets the connection and sets content-length to 0 (zero), even though there is data in the post request, when the keep-alive timeout expires. Fortunately this only occurs when using HTTPS, and apparently it's limited to a particular version of IE (although I'm not 100% convinced about this). This bug is documented very well here and by ibm here, and an typically difficult to understand MS solution here. Another solution I think may work ......

Posted On Thursday, January 26, 2006 2:35 PM

IE and Firefox compatible javascript to enable or disable an anchor tag
IE supports provides a half-baked implementation of the non-standard attribute 'disabled' on anchor tags (ie it changes it's color -even though it does not actually disable the anchor (if it has an href value). Firefox does not provide any support for it. To add full 'disable' functionality to both browsers there are a couple of work arounds (hacks): Override the onclick event of the anchor (to do nothing) and override the visual settings. or, more simply Add or remove the href attribute (both browsers ......

Posted On Thursday, January 19, 2006 12:54 PM

IE and Firefox compatible javascript to reference innerText/text attribute
function getObjInnerText(obj){ if (document.all) { // IE; return obj.innerText; } else{ if (obj.text) { return obj.text; } else alert("Error: This application does not support your browser. Try again using IE or Firefox."); }} ......

Posted On Thursday, January 19, 2006 11:12 AM

IE and Firefox compatible javascript to reference a single object or a collection of child objects in the DOM
To obtain an object or a 'all' collection of child objects somewhere in the DOM you can use something like this: var all, myObj; if (document.all) { // IE; all = document.all["myParentObj"]... myObj=document.all["myFormE... } else{ if(document.getElementById(... && document.getElementById("my... all = document.getElementById("my... myObj=document.getElementBy... } else alert("Error: This application does not ......

Posted On Wednesday, January 18, 2006 11:43 AM

.NET 2.0 different versions - x86, x64 and ia64

Heath does an excellent job detailing this:

Posted On Thursday, December 22, 2005 10:02 AM

Converting SQL Server data types to .NET types

The following link contains a list of Microsoft SQL Server data types and a list of their .NET CLR equivalents:

And this link shows the mapping between C# built-in types and the .NET CLR types:


Posted On Saturday, December 10, 2005 12:32 PM

Turning off .NET security
When you're developing .NET apps the .NET security can be a right pain in the butt, so to avoid any more head aches you can simply turn it off by using the caspol utility eg: caspol -s off While this is somewhat overkill (much like cutting your toe nails with a sythe), it certainly gets you up and running in no time. However the problems come when you start moving from your dev platform, onto testing & prod environments. But hopefully with you'll implement a more thorough approach. This works ......

Posted On Friday, December 2, 2005 10:03 AM

IIS error: The parameter is incorrect

This error occurs within IIS 6 when you try to start your web site and it has not been assigned to a valid application pool.

This usually happens when the default app pool has been deleted.





Posted On Friday, November 18, 2005 1:20 PM

ADSI error: The directory datatype cannot be converted to/from a native DS datatype. When retrieving DS property value.
This occurs when using ADSI (ActiveDs.dll) when retreiving a property value whose type (in the schema) is not the same as that specified in the method you use. In my case I was trying to access a property which was a dn (distinguished name), however the method I was using to retrieve the value was defaulting to type ADSTYPEENUM.ADSTYPE_CASE_IG... This caused the following error: Exception Information****************... Type: System.Runtime.InteropServi... ......

Posted On Wednesday, November 9, 2005 1:17 PM

OleDbDataReader and OleDbConnection Close() method problem
I find that when using the Close() method for both the OleDbDataReader and/or the OleDbConnection, when connected to a Sybase server, my ASP.NET process hangs. I had a need to run multiple different queries in sequence, so wanted to reuse the connection and just close the reader each time. And just wanted to close the connection at the end (as a good practice ;-) ) Couldn't find a solution, nor the reason, so, the workaround is... Put all the db access code into one method and call that each time ......

Posted On Thursday, November 3, 2005 12:14 PM

VS.NET error: ... The host name in the certificate is invalid or does not match.
The following error occurs in VS.NET when you try to open a project that requires certificates and the host name in the url differs from the cert: The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://<host>/<pr... 'The host name in the certificate is invalid or does not match'. To resolve you need to make sure the host name in both the .sln and .webinfo files is the same as on the server's certificate. ......

Posted On Wednesday, November 2, 2005 10:28 AM

CodeSmith templates for DNN module development, BLL, DAL, etc

Check out these babies.  Bloody marvellous!


Posted On Thursday, October 27, 2005 10:21 AM

Convert VB.NET to C#

Just found a neat web app for doing this here - great job James!

He writes about it here.

Posted On Thursday, October 27, 2005 3:54 AM

"Error 1308. Source file not found" occurs when installing MSDN Library
This error occurs if you try to install the MSDN library using a network or localdrive install - where you've copied the content of the CD's/ISO's into separate directories, eg: c:\msdn_2005Oct_disc1c:\msd... To solve this problem, copy the contents of all dirs into 1, eg just copy the Program Files directory from all other disc dirs (in this example (c:\msdn_2005Oct_disc2 & c:\msdn_2005Oct_disc3) into the first disc dir (c:\msdn_2005Oct_disc1). Then re-run the ......

Posted On Wednesday, October 19, 2005 10:57 AM

Displaying RSS XML as HTML using javascript
Here's an HTML page containing javascript functions for displaying an RSS feed in nicely formatted HTML. Licence Agreement: To use this work, you, the licencee, agree to purchase, me (Tim Huffam) a pint of beer. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HT... HTML RSS Viewer </TITLE><script> var rssDoc = new ActiveXObject("MSXML2.DOMDo... rssDoc.onreadystatechange = popData; function displayRSS(path){ mainTitle.href = ......

Posted On Monday, October 17, 2005 12:06 PM

Displaying RSS XML as HTML using a XSLT transformation
Thought it was about time there was a xsl template for allowing you to view RSS... so here's a basic one I've knocked up.. feel free to use (note that I've added some jigery-pokery so it caters for encoded embedded html within the rss description element). I'll follow this post with another one showing how to acheive this using javascript (ajax style). To use, just save the following xsl to a file, then add a reference to it in your rss feed with the following line: <?xml-stylesheet type="text/xsl" ......

Posted On Monday, October 17, 2005 11:57 AM

'System.Security.SecurityException: Requested registry access is not allowed.' when writing to event log
I got this error when I try to create an eventlog source and when I try to write to the new event log (after resorting to manually creating the event log source) with my ASP.NET application. See the end of this post for the full error message and stack trace. This seems to be a very commom problem - and not consistent either. My guess is that it's due to the tightening of security recently, ie XP SP2. Use of the Network Service account (on win2k3) or AD accounts can help. To resolve you need to give ......

Posted On Wednesday, October 5, 2005 8:46 AM

Resetting DNN or membership password and password salt
If you're a plonker like me and have forgotten a password, you have 2 options: Call the 'aspnet_Membership_ResetPas... sproc. Simply update the aspnet_membership table manually by copying the password and passwordSalt column values from another user (whose password you know). Here's some code I used: declare @u uniqueidentifierset @u = (select userid from aspnet_users where username = 'userwhosepswdyouknow') UPDATE aspnet_MembershipSET [Password] = (select password from aspnet_membership where ......

Posted On Wednesday, September 28, 2005 7:31 PM

Importing previously exported certificate for IIS
To import a previously exported certificate (.pfx file) 1) Open MMC console for managing certificates. If you do not have a console shortcut (.msc) setup then: Add MMC snap-in for certificates: 1.1) Start - Run - enter: mmc 1.2) Within MMC console, select File - Add/Remove Snap-in 1.3) Click Add… 1.4) Select Certificates in list and click Add 1.5) Select Computer account 1.6) Click Next, then Finish 1.7) Once you're back at the MMC console you can save this console setting to a .msc file. 2) ......

Posted On Tuesday, September 27, 2005 12:47 PM

Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged.
When trying to run/debug my ASP.Net web app from VS.NET (2003) I get this error: Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged. This was caused because I had renamed the virtual dir that the project resides in - and because of this IIS had decided to revert the dir from an application to a dir. To resolve simply make it an app again via the IIS Management tool: Within the IIS management tool, select your virtual dir. Right-click ......

Posted On Wednesday, September 14, 2005 8:52 AM

The Web server reported the following error when attempting to create or open the Web project located at the following URL: '...'. 'A certificate is required to complete the client authentication'.
If your ASP.NET app requires a client certificates (in my case in an HTTP Module doing authentication) then you will get this error when you first open the project within VS.NET (2003): The Web server reported the following error when attempting to create or open the Web project located at the following URL: ' 'A certificate is required to complete the client authentication'. This seems to be a bug with VS.NET - the workaround is to click OK to the error ......

Posted On Thursday, September 8, 2005 2:24 PM

Unable to open Web Project '...'. The file path '...' does not correspond to the URL '...'. The two need to map to the same server location. HTTP Error 403: Access Forbidden
I got this error (and serveral variations of it while trying to fix it) when trying to open an ASP.NET (.Net 1.1) web app in VS.NET (2003) (on an XP Pro box): Unable to open Web Project 'TestW'. The file path 'C:\inetpub\wwwroot\TestW' does not correspond to the URL 'http://Localhost:/TestW'. The two need to map to the same server location. HTTP Error 403: Access Forbidden This was caused by two problems: I had added a certificate to the server (IIS 5) - and the cert specified my full machine domain ......

Posted On Thursday, September 8, 2005 12:16 PM

Copyright © Tim Huffam | Powered by: