Tuesday, 15 February 2011

Hidden Features of C#?

http://stackoverflow.com/questions/9033/hidden-features-of-c

 

This is kind of a meta answer that lists a set of answers related to features/keywords etc that you may already know about but there is some interesting debate and further links to some of them.

Thursday, 2 December 2010

Google Beatbox

http://kottke.org/10/11/google-beatbox

The latest big thing from Google: beatboxing. Just go to this page on Google Translate and press "Listen"

Wednesday, 23 June 2010

Building without Visual Studio


If you don’t have Visual Studio installed, maybe because this is a build server, then you will almost certainly get msbuild errors because it cannot find some tool or other from the Windows SDK.

Like:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1835, 9):
error MSB3454: Tracker.exe is required to correctly incrementally generate resources
in some circumstances, such as when building on a 64-bit OS using 32-bit MSBuild.
This build requires Tracker.exe, but it could not be found. The task is looking for
Tracker.exe beneath the InstallationFolder value of the registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A. To solve the
problem, either: 1) Install the Microsoft Windows SDK v7.0A or later. 2) Install
Microsoft Visual Studio 2010. 3) Manually set the above registry key to the correct
location. Alternatively, you can turn off incremental resource generation by setting
the "TrackFileAccess" property to "false".

You may also get a similar message regarding LC.EXE.

The v7.0A version of the Windows SDK is installed when you install Visual Studio 2010 and is expected by the .Net 4.0 version of msbuild. However, you don’t seem to be able to get it as a separate download!

A bit of Googling shows a few “solutions. Such as adding “TrackFileAccess=false” as a configuration option for msbuild (http://bradwilson.typepad.com/blog/2010/05/working-around-build-error-msb3454.html).

This works fine for the TRACKER.EXE problem but not for the LC.EXE version.

Here’s my solution:

  1. Download the v7.1 version of Windows SDK (for .Net 4.0 and good for all version of Windows)
    http://www.microsoft.com/downloads/details.aspx?FamilyID=6b6c21d2-2006-4afa-9702-529fa782d63b&displaylang=en
    Other versions are available from the Windows SDK MSDN Developer Center (http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx)
  2. This is a web installer. If you decide to go find the full ISO of the SDK it’s around 1.6GB. The web installer lets you only select the bits you want and should download/install in a few minutes.
  3. Run winsdk_web.exe you downloaded above. Click through until you get to the “Installation Options” page.
  4. De-select everything except the .NET Development – Tools. The page should look like this

  5. On Windows 2008 server it will let you also completely unselect the Intellisense assemblies too
  6. Select next until it starts installing.
    Even on a slow connection it should only take a few minutes.
  7. Lastly you need to convince msbuild to use this version of the SDK
  8. On the Start menu you will have a “Microsoft Windows SDK v7.1” folder
  9. Select “Windows SDK 7.1 Command Prompt”
  10. Enter the following commands
    > cd Setup
    > WindowsSdkVer –version:v7.1

    See http://msdn.microsoft.com/en-us/library/ff660764.aspx (Configuring Visual Studio for Visual C++ Development with the Windows SDK) for info
  11. Done. Msbuild will now be able to find the tools it needs

You will also run into problems is you’re trying to compile web apps with an error like

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Simply copy the folder “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0” from your dev machine with VS2010 installed onto your build server.

YMMV but this is what works for me.
Good luck

Wednesday, 17 March 2010

Don't just roll the dice

http://www.neildavidson.com/dontjustrollthedice.html

Don't just roll the dice

How do you price your software? Is it art, science or magic? This usefully short book will help you get the theory, practical advice and case studies you need to stop you reaching for the dice.

Download the free eBook (.pdf)

To buy a physical copy, or read or write reviews, visit Amazon.com or Amazon.co.uk

To find out more about the author, go to the neildavidson.com homepage

 

 

Tuesday, 9 March 2010

TFS considered dangerous

Martin Fowler did a survey of version control software coming up with an “approval” rating. Subversion 93%; TFS 0%.
Yes _zero_ percent!

All the others with high approval rating were DVCSs (git, Mercurial etc).

http://martinfowler.com/bliki/VcsSurvey.html

Monday, 8 March 2010

Enabling SQL Server access through the Windows firewall

This is one of the annoying things about setting up a new machine. You think that you’ve got all the system stuff installed. Application deployed. Everything seems good. Then, later, you try to resolve some issue by connecting from some other machine (like you’re dev machine) and it won’t let you. The firewall is blocking remote connections. You know you should “do the right thing” and put in a very specific rule to just allow SQL Server traffic but you need to get this done _now_ so you just disable the firewall to get your problem fixed.

Do you remember to re-enable it???

So here’s how you do it the command line way.

netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAIN

Copy it to a bat file somewhere then run it on whatever machines you need access to.

 

Taken from http://msdn.microsoft.com/en-us/library/cc646023.aspx

Monday, 2 July 2007

Overriding ConfigurationManager

So... we're building a system that will certainly need to be hosted across many machines to provide load balancing and splitting of tasks into granular pieces that can be distributed across the pool.
The problem comes when you need to duplicate configuration across all those machines. Sure we could copy app.exe.config and web.configs across the pool. But management of this soon becomes tendious and error prone. Especially once you start needing to assign clusters to specific customers to support SLAs.

System.Configuration.ConfigurationManager is the normal place to access various settings. But as with several System classes overriding behavior can seem impossible. A lot of the parts you want to override are internal and/or sealed.

Reflector to the rescue!

All the useful methods (like AppSettings) delegate via s_configSystem which is private static.
You'll notice that there's a SetConfigurationSystem method that sets s_configSystem. But of course it's private static (sigh). But at least it takes an interface type, so maybe there's a chance.

OK let's use FileDisassembler (a Reflector plugin) and get the sourse of some System assemblies out into files so we can do some searching.

SetConfigurationSystem is actually called from System.Web.Configuration.HttpConfigurationSystem where they use Type.GetType to create some more internal, sealed types from System.Configuration.Internal that in turn call SetConfigurationSystem. They do this to redirect to the web.config file and deal with the file changing so that the web app is restarted.

So the trick is to create a class that implements the interface IInternalConfigSystem. Three straight forward methods. Then use the technique from HttpConfigurationSystem to inject our class into ConfigurationManager.

Not as hard after all. Here's a really simple example...


public class MyConfigSystem: IInternalConfigSystem
{
public static void Install()
{
MyConfigSystem confSys = new MyConfigSystem();
Type configFactoryType = Type.GetType("System.Configuration.Internal.InternalConfigSettingsFactory, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true);
IInternalConfigSettingsFactory configSettingsFactory = (IInternalConfigSettingsFactory)Activator.CreateInstance(configFactoryType, true);
configSettingsFactory.SetConfigurationSystem(confSys, false);

Type clientConfigSystemType = Type.GetType("System.Configuration.ClientConfigurationSystem, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true);
clientConfigSystem = (IInternalConfigSystem)Activator.CreateInstance(clientConfigSystemType, true);
}
private static IInternalConfigSystem clientConfigSystem;

#region IInternalConfigSystem Members

object IInternalConfigSystem.GetSection(string configKey)
{
switch (configKey)
{
case "appSettings":
NameValueCollection nvc = new NameValueCollection();
nvc.Add("fred", "wilma");
return nvc;
case "connectionsStrings":
ConnectionStringSettingsCollection cssc = new ConnectionStringSettingsCollection();
cssc.Add(new ConnectionStringSettings("aName", "someConnectionString", "aProvider"));
return cssc;
default:
return clientConfigSystem.GetSection(configKey);
}
}

void IInternalConfigSystem.RefreshConfig(string sectionName)
{
switch (sectionName)
{
case "appSettings":
break;
case "connectionsStrings":
break;
default:
clientConfigSystem.RefreshConfig(sectionName);
break;
}
}

bool IInternalConfigSystem.SupportsUserConfig
{
get { return true; }
}

#endregion
}

Just ensure that MyConfigSystem.Install() is called before you call any method on Configurationmanager.

A bit of WCF and a bit of caching and we can have whichever sections we like retrieved from a service. We stil need to deal with single point of failure issues. But we have other parts for that :)