Author Archive

Shadow Copy Cache Hell

May 22nd, 2008

This post may be terse and may possibly contain profanity. I’ve just wasted nearly a day and a half before solving this problem.

Situation:
I have Project….Lets call it Project “P”. Big project, .NET 1.1. Nasty stuff at the best of times.
Project A has a dependency on an internal framework project (Dependency “D”).

For the last 2 days, whenever i try and run a unit test using NUnit/TestDriven/ReSharper, my tests are littered with failures like this:

    TestCase ‘ProjectP.Test.Data.Documents.MemberAuthentication_Tests.Can_Confirm_Registration’
    failed: System.TypeLoadException : Could not load type DependencyD.ISomeInterface from assembly DependencyD.Framework, Version=1.1.0.0, Culture=neutral, PublicKeyToken=8c4881879956f3a5.
    at ProjectP.Test.Utility.TestUtility_For_People..ctor()
    d:\projects\ClientProject\Client.website\trunk\ProjectP.testing\data\people\MemberAuthentication_Tests.cs(92,0): at ProjectP.Test.Data.Documents.MemberAuthentication_Tests.Can_Confirm_Registration()

After clearing my local temp and my c:\windows temp, i was still getting this error.
After deleting all bin/obj directories in my project, i was still getting this error.
After deleting all known references to “DependencyD.dll” from my system, i was still getting this error.
After lots of googling, nothing turned up which would give me ANY indication that this was a problem.

To solve the problem, I attached the debugger to one of the tests as it ran and looked at the debug output window as it was loading each of the referenced assemblies…here’s what i saw:

    C:\Documents and Settings\xerxes.battiwalla\Local Settings\Application Data\assembly\dl2\GK3YAWO1.PD9\R117AEJZ.326\3cf8f4b1\9a0818d9_d632c801\DependencyD.dll

wtf? WTF is that directory and why is my dll there? some different Googling and i found the answer. Shadow Copy Cache is a feature of ASP.NET it seems which is the cause of my problems. I wont go into detail about what SCC is, but in a few words, it’s a private copy of all your DLLs for ASP.NET to use so that you don’t get sharing violation problems when your website code is changed.

Deleting the SCC directory and all its contents suddenly make my tests pass, and the world seems brighter once more. I cant FU**ING believe that was the problem. So obscure, i’d never heard of it.

I hope that this entry gets indexed by the search crawlers….i was unlucky in finding anything about this problem by searching for things like “TestDriven TypeLoadException” or “Could not load type from assembly wrong version”, i just dont want the same thing to happen again (or to anyone else).

grrrr….

Being driven down a path

May 15th, 2008

Recently, i’ve been looking more into TDD and mocking in particular.

I’m well versed with TDD and unit testing in general, and although i’ve dabbled in mocking before with NMock, i never really pursued it deeper; probably based on the combination of a number factors:

  • The product i was working on had it’s own in-house, custom-built ORM/OPF which wasn’t interface driven
  • There were patterns for testing code based on the aforementioned OPF which didn’t lend themselves for mocking too easily

Either way, i’ve sunk my teeth deep into it, and one thing that irked me about mocking was why I always seem to be mocking interface implementations and not concrete classes. From my (limited) understanding of how mocking frameworks work, one would assume that the definition of an object exposed through public methods on a concrete type would still allow you to mock the object. In a nutshell, i was wondering why can’t i mock my concrete classes?

Lets use an example (apologies if there are compile errors – i’m doing this off the top of my head)….I’m writing a class to perform calculations (uninspiringly named “Calculator”). I realise it’s a trivial example, so lets make it interesting by saying that the actual calculation logic won’t be handled by my application – it will be handled by a 3rd party object called SuperCalculator which takes the calculation and runs it across an array of supercomputers. As developers, we don’t care about the implementation of the SuperCalculator, only its interface.

So my code would look something like this:

   1:  public class Calculator
   2:  {
   3:    SuperCalculator superCalc = new SuperCalc();
   4:   
   5:    public int AddNumbers(int x, int y)
   6:    {
   7:      return superCalc.Add(x, y);
   8:    }
   9:   
  10:    public int SubtractNumbers(int x, int y)
  11:    {
  12:      return superCalc.Subtract(x, y);
  13:    }
  14:   
  15:  }

Now to test this using standard mocking techniques, I would need to pray that there is an interface for the SuperCalculator type

   1:  public interface SuperCalculator
   2:  {
   3:    int AddNumbers(int x, int y);
   4:    int SubtractNumbers(int x, int y);
   5:  }

…and the concrete class would be updated to use the interface definition (note the use of setter injection for mocking – i could have just as easily used constructor injection…)

   1:  public class Calculator
   2:  {
   3:    ISuperCalculator _superCalc;
   4:    public ISuperCalculator SuperCalc
   5:    {
   6:      get
   7:      {
   8:        if (_superCalc == null)
   9:        {
  10:          _superCalc = new SuperCalculator;
  11:        }
  12:        return _superCalc
  13:      }
  14:      set { _superCalc = value; }
  15:    }
  16:   
  17:    public int AddNumbers(int x, int y)
  18:    {
  19:      return superCalc.Add(x, y);
  20:    }
  21:   
  22:    public int SubtractNumbers(int x, int y)
  23:    {
  24:      return superCalc.Subtract(x, y);
  25:    }
  26:   
  27:  }

…and then your unit test starts making a mockery based on the interface (Rhino mocks and .NET 1.1 used here, but using generic params is just as cool)….

   1:  [TestFixture]
   2:  public class TestCalculator
   3:  {
   4:    [Test]
   5:    public void TestAddition()
   6:    {
   7:      MockRepository repos = new MockRepository();
   8:      ISuperCalculator mockSuperCalc = (ISuperCalculator)repos.CreateMock(typeof(ISuperCalculator));
   9:   
  10:      Calculator testCalc = new Calculator();
  11:      testCalc.SuperCalc = mockSuperCalc;
  12:   
  13:      Expect.Call(mockSuperCalc.Add(1, 1)).Returns(2);
  14:      repos.ReplayAll();
  15:      
  16:      int result = testCalc.AddNumbers(1, 1);
  17:      repos.VerifyAll();
  18:   
  19:      Assert.AreEqual(1, result);
  20:    }
  21:  }

phew…lot of code, but we got there. Now getting back to what irks me. The fact that we had to PRAY for an interface ISuperCalculator ortherwise we couldn’t mock out the dependency. And when you’re at the hands of a 3rd party library, who knows what you’re going to get.

So my questions came to – “is it possible to mock based on the concrete class?”….a bit of light Googling indicates it is possible, but only if you create a superclass of your concrete implementation and override all “public” methods which would now mean that they all have to be virtual by default, otherwise your test will end up calling code with undesirable results.

Why can’t the mocking framework take a concrete implementation, and mock it based on its public interface? The framework knows the interface to the object via reflection (and with VS2008, the intellisense is damn intelligent by allowing you to extend it), so why can’t it Reflection.Emit() all the necessary members (public/protected) and you can avoid the pain of hoping for an interface for a class that’s out of your control?

The other approach to it is to use a service proxy, and proxy all of the calls to SuperComputer through your OWN class MySuperComputer, which requires you to hand code the interface to SuperComputer, expose an IMySuperComputer, and then mock that….You’re hardly achieving anything though, because you’re just pushing the untestable dependency further down.

ramble ramble….if anyone has a thought on the matter, i’d like to hear it. I’m keen on continuing to use mocks, and certainly believe that implementing interfaces is good practice, but when the code you’re trying to mock is out of your control, what do you do?

[UPDATE]
hmm….after looking at this article it seems to explain one reason why you can’t create a pure mock from a concrete class…

Quote:

    Dynamic mock object tools like NMock or Rhino Mocks can only override virtual methods. This might not be so much a problem in other languages, but with the .Net languages all methods are non-virtual by default. This means that some of the behavior that you were trying to remove from the test with a mock is still there. The dynamic mock libraries work by using Reflection.Emit to create a dynamic proxy on the fly for the requested interface or abstract class.

bugger

CCNET will crash and die when you run out of disk space

May 12th, 2008

Maybe its the old version of CCNET we’re using, but please be wary of this problem.

After recovering space on the aforementioned drive, you’ll get the following message in the CC dashboard:

Unable to read the specified saved state. The configuration data may be invalid

The solution is to rebuild the content of your .state files for each project affected….And you’ll know which projects are affected because the dang state file is 0 bytes.

Google is your friend.

VS2005 IIS Binding Can be removed

May 12th, 2008

In Visual Studio 2005 SP1, the new “web-application” project type was introduced. This project type allowed us to have a csproj for the website project and suddenly we were in control of the content of a project and integrating it into an automated build process became simple.

However the best reason for wanting to ditch the old school website project in favour of the web-application project was not needing to bind the project to an IIS website. With an ASP.NET website project, the website project itself needs to be bound to a corresponding website under IIS, which is a real PITA, particularly when you don’t have the necessary environment set up.

So with VS2005 SP1 and web-application projects, all these problems are a thing of the past, right? Wrong, it seems.

I was opening one of our projects written by a contractor and it looks like he’s somehow managed to re-introduce project-website binding in a web-application project. Don’t know how, but whenever the project is opened, if it couldn’t connect to the project’s website running on localhost, it would throw a COM Interop Exception.

Simple solution – remove IIS website binding. It’s unnecessary and provides no benefit if your deployment process is handled outside Visual Studio. Open up the .csproj file, and remove the <ProjectExtensions> element and its children.

Problem solved.

Test your changes

April 30th, 2008
  1. Make sure you test your changes. end to end.
  2. Make sure you write unit tests to cover your code. Every possible line
  3. And for the love of God, don’t ask me to review your work when you haven’t taken the time to test it yourself. Not only do you waste my time, but you waste YOUR time which could be spent fixing the problems I discovered anyway.

Level 57 – Outland, i’m OMW

April 28th, 2008

I’m just about close enough to join Outland….after my 4 months hiatus from WoW, ive basically power levelled my way from 45 to 57 (soon to be 58) in order to catch up with the others.

and then once i’m 70, with PVP gear, i’ll blow the priest away and try a class which can actually tank. stupid cloth armor.

Here i am on the armory.

Enabling Permalinks For WordPress

April 24th, 2008

There are a number of good pages which explain how to enable permalinks and rewrite rules for WordPress, such as:

http://codex.wordpress.org/Using_Permalinks
and
http://faq.wordpress.net/view.php?p=20

None of them mentioned my problem – the main apache conf for the website had the setting AllowOverride None.

Hence my .htaccess wasn’t being honoured, hence my redirects weren’t working (and resulted in 404′s). Hence i ripped a clump of my hair out.

gah. hopefully someone stumbles across this and doesn’t waste as much time as i did.

Formatting code in my blog posts

April 24th, 2008

In case i forget or lose the details on how i can post code in my blogs, here it is:

WordPress doesn’t allow you to post HTML code directly into your blogs. Sucks.

A bit of googling turned up embed-it. This WP plugin allows you to post HTML code into your blog. it does using the concept of “Custom Fields”. Essentially they’re parameters in the blog entry which get replaced by whatever code you want on-the-fly..

This frustrates me though because i blog using Drivel in an attempt to make blogging faster and therefore motivate to do it more often. And drivel has no support for this, and i doubt the wordpress RPC interface does either.

oh finally, the C# code formatter – awesome.

Be mindful of IIS Virtual Websites

April 22nd, 2008

wow – I’ve just finished cleaning up a project conversion gone massively awry.

The proejct was originally in classic ASP, but over the years, people have extended it with ASP.NET parts (in this case, webservices).

The hosting provider was asked to configure the main root-folder of the website in IIS6 as a standard website, but a special request was made to the sub-directories into ASP.NET web-application folders.

…and of course here i come cleaning up the entire solution and migrating the classic ASP code to .NET and my deployments all break. why? because the webservices were expecting all of their own binaries to be nested within their sub-directory….a mess of binary files, and the website would just error that the referenced assemblies could not be found.

the solution? uncheck the web-application settings for all sub-directories and move the code binaries into the main bin directory.

i feel there’s more work to come on this solution…. :|

Strongly-Typing Your Domain Values

April 21st, 2008

I love this one. I don’t know the name of the pattern, but i love using it.

Imagine your system uses strings to represent the value of a status field. potential values of this field are:

  • New
  • Requested
  • Open
  • Closed
  • Deferred
  • In Progress
  • More Information Required

…and you want to write a method (or webservice) called UpdateStatus, which takes in one of these values.

Standard signature would look something like this:

public void UpdateStatus(string newStatus)

The use of “string” for the static type has the problem that someone could pass through a rubbish value as a string, and the UpdateStatus method is now responsible for domain validation of the input.

However, following the pattern below, you’re able to statically define your domain (if known at design-time) and enforce the stronger type in subsequent method calls.

public class IssueStatus
{
	void IssueStatus(string description)
	{
		this.description = description;
	}
		readonly string description;

	public static IssueStatus New = new IssueStatus("New");
	public static IssueStatus Requested = new IssueStatus("Requested");
	public static IssueStatus Open = new IssueStatus("Open");
}

and you can then use the strong IssueStatus type in your signatures:

public SaveButton_Clicked(object sender, EventArgs e)
{
	bo.UpdateStatus(IssueStatus.New);
}

public void UpdateStatus(IssueStatus newStatus)
{
	if (newStatus == IssueStatus.New)
	{
	// do something here
	}
}

I learnt this one on the job a few years back, and think it’s fantastic.

Lose the apps, Facebook

April 19th, 2008

…and while i’m on the topic of Facebook – LOSE THE SHITTY APPLICATIONS, FACEBOOK!. Your website is becoming overrun by hundreds of thousands of lousy applications, most of which are focused on trying to make a quick buck out of the system.

if you leave something popular open, it will be exploited by those who see monetary value in it’s existence.

Google (on the other hand) use very closed-circuit tactics for managing their software and environment, despite the perception of an open system.

  • 1. Their search technology is closed-source and proprietry
  • 2. Ad-Words is tightly controlled by Google
  • 3. Google CSE
  • 4. Google Maps has no SOAP API – just AJAX.

Where Google makes its success is in providing hundreds of little tools and applications to interface with their technologies within their controlled environment. Facebook gives you open slather to do whatever/whenever and rewards and promotes people for referral of applications – hence it is now a cesspool.

…soon enough the next big thing will be upon us and facebook will slowly phase out if they cant get it under control.

Stalking over the net – too easy

April 19th, 2008

Does it concern most people that Facebook (as one particular example) basically allows you to show and share virtually everything about you?

I don’t particularly care if any of the 390 odd people on my friends list check out my photo gallery, or tagged photos of me, but surely there comes a point when people you haven’t seen or spoken to since forever are able to go through all your info.

one half of me asks “well why are they even on your facebook in the first place, if you haven’t spoken to them for so long?”…..and the truth is….i dont know. i can’t explain my compulsion to want to try and re-contact people from my past. but at the same, i highly doubt i’m the only one does this.

so now you have a growing culture of people just adding each anyone and everyone else…..and access to information is easily available. only those who are truly anal go about changing the privacy settings from the defaults.

Reward Success, Reward Failure, Punish Inaction

April 17th, 2008

At my last job, this quote was printed on an old, half dog-eared, half-torn piece of paper, and stuck to a random pillar in the office.

As fate would have it, I sat next to this pillar for my first few months there, and this message seemed to resonate with me since then. It’s (quietly) one of my life mantras.

I don’t know who came up with the proverb, but i believe it’s quite accurate of how people should be treated (and ironically the complete opposite of how i was treated at the company).

Breakdown:
Reward Success – This one is pretty easy. If you do a good job, you should be rewarded for your efforts

Reward Failure – Important point. if you try, but fail. you’re still successful. You’re successful in that you’ve managed to try something new. You’ve managed to attempt something difficult, and although you didn’t get there, you’ve learnt more from failing than you possibly would have from succeeding. Sometimes it’s important to know that by touching a hot iron, you’ll get burnt. lesson learnt for future (yes i’m reliving a childhood memory there ;)

Punish Inaction – Fundamental point. If you do nothing; if you sit back, and let things go on around you without actively addressing the issue, you’ve failed miserably. knowing of a problem and doing nothing about it is the worst course of action that one could take. The problem spirals out of control and the you’re in the thick of it.

Why am i posting? Because i learnt that while i was on holidays a member of my team discovered that one of our computers was compromised, and failed to act on it. I discovered the problem myself, and have taken the (only) course of action which is to bring the servers down and re-build with a post-mortem to come. But to learn of a serious breach of security, and NOT do anything about it is undeniably the complete opposite of how the problem should have been addressed.

Reward Success – if the problem was acted on, then i would be blogging about the reverse right now

Reward Failure – if the problem was discovered, and they were unable to fix it, but managed to contain the damage, that’s still commendable. You can’t hold someone liable if they don’t know how to fix the problem.

Punish Inaction – the problem was not acted on. The problem was left around for nearly 2 months until my return, and subsequent discovery. Who knows how deep the problem has gone, and we’re now all entangled right in the middle.

it’s been a shitty week.

One Hundred Rules for NASA Project Managers

April 12th, 2006


href="file:///C:\Program%20Files\NewsGator\ngstyles.css">

LINK:   face="Times New Roman"> target="_self" title="http://www.altisinc.com/Links/100_Rules.html">One Hundred
Rules for NASA Project Managers

style='font-size:12.0pt'> 

style='font-size:12.0pt'>Really really cool.

 

style='font-size:12.0pt;color:navy'>—————–

Visual SourceSafe – “Version Not Found”

March 15th, 2006


I got this error today when trying to get-latest version
using a custom get-latest tool we have written at href="http://www.edi.com.au/">my current place of work. This tool uses
SourceSafeTypelib.DLL binary to communicate with the SS server, and the first
call to GetLatestAllFiles resulted in a COM exception citing “Version Not
Found”

 

A great deal of research went into finding the problem –
was it complaining about file versions? Different tree versions? Label versions??
With almost all avenues exhausted, I looked at the installed version of source
safe.

 

My primary machine (which works) runs SS v6.0c…..and
the virtual machine (which had the problem)? SS v6.0d.

 

Took a stab in the dark – uninstalled 6.0d and
re-installed 6.0c…..and who would have thought it, but that actually fixed
the problem….how bizarre :)

 

 

-x