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

C# .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

To remove all source control from a TFS project (not a VS project!) - you must use the 'tf destroy' tool. If, like me you try to delete the top-level directory/project node in Source Control Explorer (within VS), then you'll likely get the following error: TF10169: Unsupported pending change attempted on team project folder $/MyProject. Use the Project Creation Wizard in Team Explorer to create a project or the Team Project deletion tool to delete one. So, this (removing source control) is useful...
  • 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

Turns out you can't just move a TFS warehouse/cube from SQL Server 2005 to 2008... Once performed we got the following error on the TFS app server tier - when we tried to update/process the cube (both manually and via the TFS scheduler service): Detailed Message: Failed to load adapter Microsoft.TeamFoundation.Wa... Exception Info: \n Microsoft.TeamFoundation.Se... Error encountered when creating connection to Analysis Services. Contact...
  • 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

If you are programmatically assigning an image as a DiffuseMaterial to your 3D model, then you need to make sure that you have created TextureCoordinates. I was using some sample code that created a 3D object - and tried to change the brush from a color to an image. The color worked fine, but the image never showed (it was invisible). The reason was that the sample code only did mesh.Positions.Add() and mesh.TriangleIndicies.Add(). When I added the appropriate mesh.TextureCoordinates.Add() lines...
  • 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

When trying to run a .Net winforms app with a progressbar on it, I found that if it was run from a non-standard class, the marquee style did not work. The reason was because we were running the app from our own loader class, instead of the usual winforms program.cs. This was because we were instatiating it from VB using COM interop - I thought this was the cause of the issue - but it turns out that this is not the case... The problem was that our own loader class did not enable the windows XP visual...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

To update the UI with values returned from an asynchronous WCF/web service call you need to make sure the coding updating the UI is running on the UI thread. Depending on how you've performed the async remote service call, often this is done on another thread - so when the handler executes upon completion of the call it is not on the UI thread and causes a threading exception. Within winforms, the solution is to use the Invoke() method eg the following method would be on your form or user control...
  • 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

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

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

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 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

The following error can occur when executing the .DataBind() method on a Dundas chart object within an ASP.Net page (.Net 3.0): Series data points do not support values of type "myclass", only values of these types can be used: Double, Decimal, Single, int, long, uint, ulong, String, DateTime, short, ushort. I had set the DataSource property to a generics List of myclass objects (List<myclass>). It turns out that this error is caused by a mismatch between the type of objects within the list...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Using the VS2008 unit testing framework, if you want to check for an expected exception, sometimes your test will pass because the exception was raised by another line of code - after the line you were specifically trying to test. To resolve this you have to manually check for the expected exception - using a try-catch block. However there is a catch (excuse the pun).... Microsoft.VisualStudio.Test... will not fail when types are different as long as the actual...
  • 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

Had a strange occurance today... In between writing unit tests in VSTS (Visual Studio Team System 2008 Developer Edition), for some reason VSTS stopped recognising the test classes as tests - so all context sensitive test actions, buttons, context menu etc for unit tests were disabled. Still have no idea why - but I have a sneaking suspicion that some solution files may have been delete. To get this working again I simply added another Test project: Right click on the solution and select Add - New...
  • 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

Doing some winforms dev for a change - and had a need to hide a form, instead of closing it, when the user clicked the standard windows close form button (little cross [x] icon on the top right corner of the form). The solution is to create a handler for the FormClosing event of the form, then force the form to be hidden, then, the important part, cancel the close event... Eg: // Use this event handler for the FormClosing event. private void MyForm_FormClosing(object sender, FormClosingEventArgs...
  • 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

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

Ever wondered why your winforms app looks good (ie shows Windows XP type styling) in the Visual Studio designer (VS2005) yet when you run it, it looks very Windows 2000 (not very colorful and no rounded corners)? That's because by the XP styling is turned off by default. To enable it, include the following line in your form's constructor: System.Windows.Forms.Applic... Simple when you know huh. HTH Tim...
  • 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

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

Full C# .NET Archive