Tuesday, August 31, 2004

VS2005 Beta1 - Source doesn't match IL while stepping through DLL

I am having the weirdest problem. I have a unit test .EXE which exercises my code which lives in a .DLL assembly. However, the code that the debugger is stepping through doesn't match what's actually happening.

For example, say I have this:

1: public bool Load (XPathDocument doc)

2: {
3: using (new LogIndent (log.Info, "Load"))
4: {
5: if (doc == null)
6: {
7: log.Warn ("doc is null -- nothing to load");
8: return;
9: }
10:
11: if (log.IsDebugEnabled)
12: log.Debug ("doc=" + doc);
13:
14: try
15: {
16: XPathNavigator nav = doc.CreateNavigator ();
17: XPathNodeIterator iter = nav.Select ("[snip]");
18: if (iter != null)
19: {
20: while (iter.MoveNext())
21: {
22: Dump (iter.Current);
23:
24: string flowName;
25: flowName = iter.Current.GetAttribute (
26: "Name",
27: iter.Current.NamespaceURI);


I have a break point on line 3 which the debugger drops me off at. At each step I'm hitting F11 - Step Into. Here is what I see:

3: using (new LogIndent (log.Info, "Load"))
7: log.Warn ("doc is null -- nothing to load");

  • Note that I should have stepped into the LogIndent constructor since the code exists in this assembly.

  • Plus, I shouldn't have jumped over the if

  • Also, I shouldn't have stepped into this if at all since doc is not null (I checked it in the calling application.)

  • 11:    if (log.IsDebugEnabled)

    Now when I step into I'm in the constructor for LogIndent that I should've hit first!?! If I continue a bit further:
    12:      log.Debug ("doc=" + doc);
    
    22: Dump (iter.Current);
    25: flowName = iter.Current.GetAttribute (

    Here again
  • I should have stepped into log.Debug

  • I should have hit the XPathNavigator, XPathNodeIterator, if and while statements

  • I should have stepped into Dump

  • to top it off, stepping into GetAttribute drops me into log.Warn with the message "doc is null -- nothing to load" from line 7

  • However, if I switch the assembly to an .EXE then everything behaves normally.

    Is it me? Should I submit this to LadyBug? Ugh.

    [Listening to: Eminem - Amityville]

    Monday, August 30, 2004

    Enabling CodeWright 7.x / VS.NET 2003 synchronization

    After upgrading my version of VS to VS.NET 2003 at work I was missing the Add-in required to synchronize files between VS and CodeWright. After a bit of spelunking here's what I found. The add-in menu is completely controlled by the registry.

    First, register CWVS7Adin.dll as you would any COM dll.

    Then, save this to a .reg file and import it.

    REGEDIT4

    [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.1\Addins\CWVS7Adin.Connect]
    "FriendlyName"="Codewright synchronization"
    "Description"="Synchronizes files between VS.NET and Codewright"
    Now when you open up the Add-in manager dialog you should see it properly.

    [Listening to: Tool - 4 degrees]

    Updated: shrinking down .reg entries to fit screen

    Sunday, August 29, 2004

    Using System.Reflection to get at private fields in a class

    6:41 In my unit testing binge I have come across the need (albeit a questionable one) to validate the contents of values internal to a class.

    It took me a bit to figure out how to do this, so I figured I'd share it here.

    The magic is in FieldInfo.GetValue (thanks to Stefan Goßner for pointing me in the right direction here.)

    For instance, I have this:

        public class FlowManager
    
    {
    private OrderedDictionary<string, IBlock> m_Flows;

    //... etc ...
    }
    I would get a reference to m_Flows like this (stripped down, but you get the idea):
        private OrderedDictionary<string, IBlock> GetFlows (
    
    FlowManager flowManager)
    {
    FieldInfo field = fm.GetType ().GetField (
    "m_Flows",
    BindingFlags.NonPublic | BindingFlags.Instance);


    if (field == null)
    return null;

    return field.GetValue (flowManager)
    as
    OrderedDictionary<string, IBlock>;
    }

    Updated: playing with formating to make the source look like source

    Saturday, August 28, 2004

    NDoc and VS2005 Beta 1 -- Has anyone gotten it to work?

    I'm trying to use NDoc to generate my documentation, but both the GUI and Console version complain that my assembly is invalid:

      Error: LoadAssembly: Exception is System.BadImageFormatException: The format of the file 'Gesture.Hookup.Core.dll' is invalid.

    When I see things like this I add the following to the .config file of the app that's blowing up:
      <configuration>
          <startup>
              <supportedRuntime version="v2.0.40607" />
          </startup>
      </configuration>

    But that didn't work. I even added:
      <requiredRuntime version="v2.0.40607" />

    but no go.

    Has anyone gotten this to work?

    HookUp update

    I've started working on this again. Slowly. Very slowly.

    Mostly I'm getting the infrastructure going. I'm working in VS2005 Beta 1. I put together a few of the utility and base classes as TDD as I could. (I'm weak.)

    First of all I'm developing as a non-admin, using Least Privilege.

    I'm using MbUnit for unit testing. I couldn't get the GUI working, it gives me a ThreadAbortException while trying to populate the tree. Since I've set up the test cases as an exe with an AutoRunner I don't really need to worry about it yet.

    I put in log4net for logging, although I can't seem to get any output during my MbUnit test cases. It's probably because of the way MbUnit loads the AppDomain. I haven't really investigated any further.

    I have cleaned everything up with FxCop and I only ignored 2 warnings:

  • "Avoid having a namespace with a small number of types" on a namespace where I'm holding some assembly/project level constants
  • Avoid building non-callable code into assemblies" on the VS generated Resources.cs file

  • Not too shabby.

    I am in the process of adding all of the xml comments so I can use NDoc. I'm such an NDoc junkie. How is it that a geek gets excited about created documentation? Or Unit Tests? Hold on, am I dead?

    Finally, I have just added PowerCollections into the mix. Haven't really gotten started on them yet, but soon.

    Thursday, August 19, 2004

    VSHOST -- the Hosting Process

    Dave Templin explains what that MyApp.vshost.exe is and what it's doing in my bin folder.

    [Listening to: Monty Python - Always Look on the Bright Side of Life]

    Wednesday, August 18, 2004

    Of Repaving, Virtual PCs and Paying Attention

    Well, it came time to repave my machine (as it always seems to do.) No sweat. I had all of my dev stuff on a VPC image. I even had the C partition going unused from a previous repaving.

    So, I install XP + updates + firewall + virus scanner. All is well.

    I installed VS2003, Office, etc, etc. All is well.

    I mount my VPC iso and install. All is still well. I'm on a roll.

    Now comes time to load my VPC image. Boom. Odd. It's complaining about some setting in the Virtual Machine. Maybe I constructed this one with a different amount of memory. Oh well, I'll just blow away the Virtual Machine .vmc file since it doesn't really hold all that much. All the good stuff is in the .vhd file anyway.

    I create a New Virtual Machine and load my Virtual Hard Drive. Invalid format?!? Huh? It tells me to go through the XP recovery steps. Fine. {Getting a bit queesy now.}

    After chugging along for hours (or so it seemed) it was recovered. Okay. Reboot the VPC and... Boom. UGH!

    Only now do I finally notice that I've mounted the wrong ISO. I mounted the Connectix 5.2 VPC instead of VPC 2004. I'm an idiot. But now it's too late. I didn't think to enable Undo Disk before trying this. It's toast.

    Nuts.

    It's a damn good thing that I had all my source in VSS which I archived before the repave. Saved my ass it did.

    The moral of the story. Pay attention dimwit or you might lose something permanently next time.

    It's a good thing I didn't go into medicine: "Nurse, you did backup the patient like I asked right?"

    [Listening to: Powerman5000 and Rob Zombie - Blast off to Nowhere]

    NSort: Generics and Testing

    Another keeper from Jonathan de Halleux of MbUnit fame:
    NSort: Generics and Testing.

    This is a pointer to a sorting library NSort, a nice refresher (read: reminder) on Composite Unit Testing plus a neat way of extending MbUnit without actually touching it. Sweet, sweet, sweet.

    [Listening to: Genesis - The Lamb Lies Down on Broadway]

    Tuesday, August 17, 2004

    Help Make Blogs More Visible!

    There are by some estimates more than a million weblogs. But most of them get no visibility in search engines. Only a few "A-List" blogs get into the top search engine results for a given topic, while the majority of blogs just don't get noticed. The reason is that the smaller blogs don't have enough links pointing to them. But this posting could solve that. Let's help the smaller blogs get more visibility!

    This posting is GoMeme 4.0. It is part of an experiment to see if we can create a blog posting that helps 1000's of blogs get higher rankings in Google. So far we have tried 3 earlier variations. Our first test, GoMeme 1.0, spread to nearly 740 blogs in 2.5 days. This new version 4.0 is shorter, simpler, and fits more easily into your blog.

    Why are we doing this? We want to help thousands of blogs get more visibility in Google and other search engines. How does it work? Just follow the instructions below to re-post this meme in your blog and add your URL to the end of the Path List below. As the meme spreads onwards from your blog, so will your URL. Later, when your blog is indexed by search engines, they will see the links pointing to your blog from all the downstream blogs that got this via you, which will cause them to rank your blog higher in search results. Everyone in the Path List below benefits in a similar way as this meme spreads. Try it!

    Instructions: Just copy this entire post and paste it into your blog. Then add your URL to the end of the path list below, and pass it on! (Make sure you add your URLs as live links or HTML code to the Path List below.)

    Path List
    1. Minding the Planet
    2. Luke Hutteman's public virtual MemoryStream
    3. JayBaz_MS blog
    4. A day in the life of a home-grown project
    5. (your URL goes here! But first, please copy this line and move it down to the next line for the next person).


    (NOTE: Be sure you paste live links for the Path List or use HTML code.)

    Another milestone in my progression into the BlogSphere

    Well, my blog has been linked to for the first time in a "main feed". Alan Dean has done me the honours here refering back to my "me too" blog on PassWORDS vs. PassPhrases. Thanks a bunch Alan.

    I guess Chris and Raymond can close up their laptops and practicing their hunting/gathering skills -- I'll take over from here ;)

    I have been linked to before in a follow up post by Sebastien Lambla here.

    While I'm on the podium I still must thank Jonathan de Halleux who posted the first ever comment to one of my blog entries.

    Now all I need is a "first-order" link. You know, the ones where someone links to some original content on my blog. I guess I need some original content now.

    [Listening to: Guns 'N Roses - One in a Million]

    [PermissionSetAttribute] Least Privilege

    I've been looking for something like this. I'm all for the least privilege thing, but I'm not quite sure where/how to start. Maybe this'll give me a leg up.

    Alan Dean shows a good starting point for
    Developing software with least privilege using PermissionSetAttribute. Via DotNetJunkies.

    [Listening to: Beatles - Something]

    Wednesday, August 11, 2004

    Application Verifier

    Rusty Miller brings up what looks to be a very useful testing tool: The Application Verifier.

    He says it can help track down heap corruption. Hey, isn't that what C# is for ;-)

    Friday, August 06, 2004

    Duelling Collection Libraries

    [Insert banjos here.]

    Brad Abrams points to a couple of collection library projects:

    PowerCollections
    A new library from Peter Golde modelled after the BCL framework. So far there is only one usable class, the OrderedDictionary
    C5
    A more complete library paralleling System.Collections.Generic from Peter Sestoft et al.

    [Listening to: Disturbed - Dropping Plates]

    Cheapskate alert: Essential XML now available as a FREE download

    This does my inner-cheapskate a world of good. Essential XML is now available from TheServerSide.NET as a FREE download.

    Thanks to Rob Caron for the pointer to Brian Ritchie's entry here.

    [Listening to: Cardigans - Sabbath Bloody Sabbath]