All posts by historical

Backup an assembly from the GAC

Scenario : You build a new version of an assembly that needs to be deployed to GAC. You need to make sure you have a roll-back plan, but the original file that you added to the GAC (the previous version) is no longer available. It *is*, however, still in the GAC.

Problem : Windows Explorer won’t let you copy an assembly from the “C:\windows\assembly” folder.

Solution : The Command Prompt. Too many peaople, in my opinion, are way too fond of using the GUI for everything under the sun. I grew up with DOS, and was lucky enough to have been able to get comfortable with doing a lot at the command line (the same with my Linux boxes, btw).

To copy the file you want out of the gac, start a command prompt and type the following :

c:
cd\\
cd windows\\assembly\\GAC
cd
cd
copy .dll c:\\

On lines 4 and 5 above, tab completion (on later versions of windows, this is enabled by default) will help you enormously. Otherwise, you’ll need to list the directory contents a couple of times to figure out the version and assembly names.

Determine if an assembly is a debug or release build

*This code originally came from another blog, although it was written in VB over there. It has lost some elegance in the translation, but I needed a very quick solution this afternoon, and I needed it in C#, so here you go. *

I needed to determine whether several assemblies were built as “Debug” or “Release” code this afternoon. They didn’t have any debug symbols with them, so that was no help. A bit of searching led me to the code below.

private void testfile(string file)
{
	if(isAssemblyDebugBuild(file))
	{
		MessageBox.Show(String.Format("{0} seems to be a debug build",file));
	}
	else
	{
		MessageBox.Show(String.Format("{0} seems to be a release build",file));
	}
}

private bool isAssemblyDebugBuild(string filename)
{
	return isAssemblyDebugBuild(System.Reflection.Assembly.LoadFile(filename));
}

private bool isAssemblyDebugBuild(System.Reflection.Assembly assemb)
{
	bool retVal = false;
	foreach(object att in assemb.GetCustomAttributes(false))
	{
		if(att.GetType() == System.Type.GetType("System.Diagnostics.DebuggableAttribute"))
		{
			retVal = ((System.Diagnostics.DebuggableAttribute)att).IsJITTrackingEnabled;
		}
	}
	return retVal;
}

The overloaded “isAssemblyDebugBuild” method will accept either a string containing the fiull filename, or a System.Reflection.Assembly object. It will return its best guess as to whether the the assembly is a debug build, as a boolean.

To call the methods as they are (to get a MessageBox), just use something like

testfile(@"C:\myUnknownAssembly.dll");

or access the underlying methods directly :

bool isDebug = isAssemblyDebugBuild(@"C:\myUnkownAssembly.dll");

I hope someone can use this to save themselves some time.

Weather Forecasting

Since I now have a new motorbike ( see this gallery ) it is quie nice to be able to plan in advance what I am going to do on a given day. A lot of the time, this decision is going to be influenced, at least in part, by what weather conditions are likely to be.

For a while now, I have checked weather forecasts on the BBC weather page. However, it appears that the BBC recently changed their policy on presenting weather forcasts to be “more optimistic”. What this means is that if the forecast for tomorrow is “it’s going to rain for most of the day, but there may be some sun for half an hour in the early afternoon”, what you will get from the BBC is “sunny intervals” or maybe “showers”. I can’t understand the reasoning behind this, from a supposedly impartial organisation such as the BBC. I know that putting a positive spin on some things is good, but why the weather? Who is going to say to the BBC “Your forecast for yesterday was rain. It rained. It is therefore your fault that the weather was bad.” Not many, I would guess.*

All I want from a wether forecast is an accurate assesment of what the forecaster believe is going to occur. Not hard really, is it?

If anyone knows of a good (i.e. accurate) source of weather data on the net, please let me know.

*Of course, you can never be sure ;)

Excuse of the Day in the sidebar

You may have spotted the “Excuse of the Day” at the top of the left sidebar. This isn't a WordPress plugin as such, but a small bit of PHP in one of the theme files. If you want to use the same code, there are a couple of things you need to do.

1) In my case, I am concious of not wanting to abuse Eric's bandwidth, so I have set up a shell script via cron to wget the feed file once per day. I'd recommend this for another reason – if, due to unforseen circumstances, meyerweb is down, your code will still work on your local copy.
2) Edit your theme file in the appropriate place to include this block.

	

Technorati and Bad Behaviour

This blog is running Bad-Behaviour to try to limit spam and general naughtiness. It does it by header analysis on incoming requests, and it caches the results.

I noticed a couple of days ago that my Technorati pings were not updating on this site, and eventually narrowed it down to the fact that the Technorati Bot doesn’t send complete headers, so BB was blocking access to this valid source. Adding the technorati bot address to the whitelist file (as well as some other fiddling around that I’m not going to go into) means that the bot can now see the feed, and work with it correctly.

I hope this helps someone out there if they are having similar issues.

Remote Debugging Issues

My colleague, John, was having problems connecting the remote debugger to our SharePoint stage server. When connecting he got an “Access Denied” error. After spending much of the afternoon Googling for a solution, he came up with the following fix.

  1. Open an MMC session and add the Component Services snap-in. Alternatively, run “dcomcnfg.exe”
  2. Expand “Computers”
  3. Right-click on “My Computer” and hit “Properties”
  4. In the “Access Permissions” section of the “COM Security” tab, click “Edit Limits”
  5. Make sure the entry for ANONYMOUS LOGIN is allowed access to the Local machine
  6. Hit “OK”, and you’re done

Very handy thing to know about.