Tim Huffam

Dotting the I and crossing the T of I.T.

  Home  |   Contact  |   Syndication    |   Login
  152 Posts | 0 Stories | 2310 Comments | 653 Trackbacks

News

Archives

Post Categories

Interesting Blogs/Links

ASP.NET

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

This is for TFS2008. This is based mainly on this article: http://blogs.msdn.com/b/jpr... But also had input from these: http://www.woodwardweb.com/... http://blogs.msdn.com/b/buc... http://blogs.msdn.com/b/jim... Also the following article discussing upgrading a...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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",...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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)....
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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"...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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:*...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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: obj.style.Left = 10; However FF requires that you specify the unit of measurement eg: obj.style.Left = "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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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:...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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);...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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"...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

This error occurs when attempting to view an asp.net 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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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 (http://www.andybudd.com/ar... - but I found it not obvious/simple enough (expecially for others who may have to maintain the css down the track - KISS) HTH Tim...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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(this.bt... The easiest solution, imo, is to simply remove the "OnClick..." HTML markup from the .aspx page. Eg change this: <asp:Button ID="btnTest"...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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(@... 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '" + searchtext.ToLower() + "'] Thanks very much to Harish for this
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Full ASP.NET Archive