Tuesday, May 03, 2005

I stumbled upon this recently and wanted to share.  As you may be aware, attributes provide a mechanism to describe an assembly, class, method, etc with information known as metadata.  This metadata is useful alter behaviors (e.g. AutoCompleteAttribute), define security restrictions (e.g. FileIOPermissionAttribute), enforce compile-time analyses (e.g. ObsoleteAttribute, CLSCompliantAttribute, AttributeUsageAttribute) or simply provide information (e.g. AssemblyTitleAttribute, AssemblyFileVersionAttribute, AssemblyCopyrightAttribute).

Via reflection you can query a target such as an assembly, et al to see what attributes it has applied.  A simple, but somewhat useless example might resemble the following:

using System;
using System.Reflection;

object[] attribs = Assembly.GetExecutingAssembly().GetCustomAttributes(false);
foreach ( Attribute a in attribs ) {
   Console.WriteLine(a.GetType().FullName);
}

It simply spits out the attributes associated with the running assembly.  It's pretty cool, and there are some applications that take advantage of such functionality.

Most likely you've had the opportunity to version stamp an assembly with the AssemblyVersionAttribute.  If so, your code probably resembled:

[assembly: AssemblyVersion(”1.0.0.0”)]

If you then run the above code on an assembly so versioned, you might be surprised not to see it there.  I don't fully understand (nor have I thought much about it, nor investigated) the reasoning behind this.  If you want to extract the version from the assembly you have to go an alternative route.  Instead, you call the GetName() method on the Assembly to retrieve an AssemblyName object which contains a Version class.  A simple call to .ToString() on the Version will yield the property value.

using System;
using System.Reflection;

Assembly asm = Assembly.GetExecutingAssembly();
Version ver = asm.GetName().Version;
Console.WriteLine(”Version “ + ver.ToString());

Does anyone know of any other attributes that don't translate into metadata such as this?  Am I wrong and it's really there but I just don't see it or am not querying for it properly?

Tuesday, May 03, 2005 2:58:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [1]  |  Trackback

This evening I had the opportunity to attend the inaugural meeting of the Northern Utah .NET User Group and help support the community.  We had about 17 people attend, which was pretty good!  Our local MS Regional Director, Scott Golightly, presented on some of the new and upcoming VS 2005 features (such as ASP.NET Master Pages, Generics, new WinForms enhancements, etc).

The presentation was well received and a lot of fun, even if we could hardly see it due to the bright sunset through blindless/curtainless windows.  We all had a great time and enjoyed some good times.

Tuesday, May 03, 2005 2:29:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback

I am more and more convinced that Virtual PC (and its Server counterpart) are awesome products.  I've been using them for several years now and I absolutely love them.  That said, however, I do run into the occasional weirdness - mostly involving networking.

This really comes into play when constantly changing networks (home, office, hotel, friend's wireless, some DHCP, some not, etc).  All firewall issues aside, I've run into situations (usually in a DHCP environment) where the host can't access the VPC (by NETBIOS, DNS, IP, etc).  Then all of the sudden it can.  Then a few minutes later it doesn't.  I don't see this often, but occassionally I do ;)  When it does happen it's extremely frustrating; you never know when it's going to work and when it's not (85% of the time it doesn't, so you can probably make a pretty good guess as to when it's going to fail).

I haven't ever thoroughly diagnosed the problem, but I think it's a derivative of the fact that it's sharing the NIC with the host and some NICs/networks can't handle it well.  I've made a practice of setting up a private, virtual network with my VPCs rather than have them participate in the host's network directly.  This allows the host direct, named access to the VPCs and also allows for multiple VPCs (yes I've had up to 3 or 4 running w/o perf hits) to participate in their own private network.  By going through these steps, however, you restrict network access to the VPC from other than the host, but for the vast majority of my VPCs, I don't need any other access (except to occasionally test a website or something like that).

Here's how you set it up:

  • First, if you haven't already, add the Local Loopback Adapter.  This is accomplished (on WinXP) by:
    • opening the 'Add Hardware Wizard' (from the Control Panel)
    • indicating that 'Yes, I have already connected the hardware'
    • selecting 'Add a new hardware device' at the bottom of the list
    • selecting 'Install the hardware that I manually select from a list'
    • selecting 'Network adapters'
    • selecting 'Microsoft' and 'Microsoft Loopback Adapter'
  • Once it's been added, you configure the private network via 'Network Connections' in the Control Panel.  I typically rename my network to 'Local Loopback Network' from 'Local Area Connection X'.  I then assign it a unique, non-routable IP address (such as 172.10.0.1 or 192.168.99.1) - something that won't conflict with the various networks into which the host will be connected.
  • Then, open your VPC and manually assign an IP address to it on the same subnet (e.g. 192.168.99.2).
  • At this point, it's incumbent on us to edit the hosts file (found in %WINDIR%\System32\drivers\etc) to map the host name to its respective IP address.

That's pretty much all there is to it.  I've found this technique to be MUCH more reliable than any other mechanism.

Tuesday, May 03, 2005 2:23:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [2]  |  Trackback

Yesterday, I was presented with the following error message while running an application that I created:

The located assembly's manifest definition with name 'XXX' does not match the assembly reference.

The .NET Framework (specifically Fusion) is throwing a FileLoadException.  This particular exception is occuring because .NET is attempting to load and bind to a particular version of a library at runtime.  Now I know what precipitated this particular error:  I had just upped the version # of the application.  The symptoms were apparent, but the remedy wasn't quite obvious at first - at least until I figured out what was truly going on.

I had changed the version of my application (and all dependencies across the board) from version 1.0.0.0 to 2.0.0.0.  This would, under normal circumstances be sufficient to avoid this particular error, however these weren't normal circumstances.  Unfortunately, this particular exception didn't really identify the root of the problem, so I had to dig a bit deeper.

Here's what I did to try to fix the problem:

  • I opened up an administrative console and ran fuslogvw.exe (a handy tool available with the .NET Framework SDK).  This particular tool is great for helping diagnose assembly binding errors.
  • Selected the 'Log Failures' checkbox (this in turn updated HKLM\SOFTWARE\Microsoft\Fusion\LogFailures to 0x00000001).
  • Selected the 'Custom' radio control.
  • Ran REGEDIT adding a string value to HLKM\SOFTWARE\Microsoft\Fusion\LogPath, setting its value to c:\fusionlogs (a folder I created for the purpose of capturing the logs).
  • Ran IISRESET (my issue was, in fact, occurring within an ASP.NET application, and I had to restart the aspnet_wp.exe process for the FUSLOGVW and registry updates to take effect).
  • Reran the ASP.NET application to recreate the error.

With logging in effect, I simply had to refresh the FUSLOGVW dialog and see the exception log appear.

A quick glance in the log indicated that it could not load version 1.0.0.0 of my application.  What!?  Why is it even trying to load the old version?  This shouldn't be happening!  In most normal circumstances, like I said, this wouldn't be an issue.  But it turns out that my application actually has two parts:

  1. The web application (the one manifesting the problem).
  2. An administrative / management console that was installed via MSI on my machine in the \Program Files folder.  This console has the same dependencies as my web application.  The role of the console is to aggregate data that has been tested and verified and 'publish' them to a 'production' database for the web application to consume.  Some of the published data (in the form of XML) contains fully-qualified references to a third-party toolset used to publish the XML so that it can be read back dynamically by the component.

Well, despite having compiled the web application successfully, I had legacy (v1.0.0.0) dlls in the \Program Files directory, so when the data got published it would bake a v1.0.0.0 stamp in the XML file.  At runtime, the ASP.NEt application would try to load the v1.0.0.0 dll when only a v2.0.0.0 dll exists.

Once I saw that this was the problem, it was easy to fix.  The .NET Framework supports a mechanism known as binding redirection which effectively allow you to use a dll of a different version that what was originally bound at compile time.  Therefore, if an assembly were compiled against a strongly-named v1.0.0.0 assembly you can effectively redirect it to use v2.0.0.0 at runtime (note that this really only applies to strongly-named assemblies as there is no version checking for assemblies without strong names - the newer version will be used by default).  In order to accomplish this, you need to establish a .config file with a section that resembles the following:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="FancySchmancyLibrary" publicKeyToken="caeeebc55fa1f62d" culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

I've seen some people try to set oldVersion to something resembling "1.0.*" but that syntax is not supported.  If you want to redirect all 1.0.x.x versions, you must specify a range such as:

<bindingRedirect oldVersion="1.0.0.0-1.0.99999.99999" newVersion=“2.0.0.0“ />

It's a pretty powerful concept and in this particular case it saved my hide.

Tuesday, May 03, 2005 3:42:00 AM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Monday, May 02, 2005

I need to do this all the time, yet I invariably forget and spend a few minutes re-figuring it out (and feeling really stupid everytime), only to forget it the next time I need to do it.

If you have an assembly and need to get the PublicKeyToken for one reason or another, the easiest way that I know of is to use the sn.exe (Strong Name Utility) with the -T switch.

sn -T SomeFancySchmancyLibrary.dll

There...now maybe I won't forget it anymore.  Why do some things just not stick?

Monday, May 02, 2005 1:17:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [15]  |  Trackback
 Friday, April 29, 2005

Over the years I have become much more of a keyboard person than a keyboard-and-mouse person.  As a developer it saves soooo much time not to have to take my hands off the keyboard to simply click a single option and bring my hands back to the keyboard.

Therefore, I've decided to list out my favorite VS.NET keyboard shortcuts (in no particular order).  There are probably many more that I'm just forgetting here.

Toggle fullscreen mode
ALT + SHIFT + ENTER

Find In Files
CTRL + SHIFT + F

Comment / Uncomment
CTRL + K, CTRL + C / CTRL + U

Highlight vertical block of code
ALT + SHIFT + ARROWKEY
ALT + MOUSEDRAG (ok, ok, this one uses the mouse)

Go to Definition
F12

Navigate to Previous Cursor Location (useful after F12...plus it's multi-level!) - Navigate Backward
CTRL + -

Format Selection
CTRL + K, CTRL + F

Parameter Information
CTRL + SHIFT + SPACE

There are many other shortcuts I always use such as F4 for properties, F11 for Step Into, F10 for Step Into, CTRL + ALT + L for Project Explorer, CTRL + SHIFT + B for Build, but those are so common and there are so many that I didn't want to recreate Microsoft's documentation.

What are your favorite shortcuts that you'd like to share.

Friday, April 29, 2005 5:08:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Thursday, April 28, 2005

There are a lot of things to be excited about.  My fourth daughter was born not two weeks ago, my sister is getting married, work is going great, and I'm going to Tech-Ed 2005 in Orlando, Florida on June 5th - 10th!

This will be my first Tech-Ed and I'm really excited about it.  I've had the opportunity over the years to attend a couple of VBits, PDC, a couple of Microsoft Partner Conferences, and others, but I've never had the chance, for one reason or another, to attend a Tech-Ed.  If you're going to be there and want to hook up and talk tech or just hang out, let me know...it's going to be a blast!

Thursday, April 28, 2005 3:08:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, April 26, 2005

Here's some news I'm very excited to share and want to disseminate before too long.  In conjunction with Microsoft, several of the local .NET community leaders have been planning a brand new event for May 18th, 2005 called Betas 2005 Unleashed.

This event will focus on the up and coming technologies from Microsoft (Visual Studio .NET 2005 and SQL Server 2005) and will have a respective track for each.  This FREE conference will focus on the technologies and will not (I repeat NOT) simply be a conference of fluff and PowerPoint.  Each of the presenters will be diving right into the technology and will use it to drive their presentations.

In the Visual Studio .NET 2005 track we'll be discussing topics such as

  • Web Development Platform - ASP.NET 2.0 (presented by yours truly)
  • Smart Client Development Platform - Windows Forms, Mobile Development
  • Visual Studio Team System

The SQL Server 2005 track provides the following

  • SQL Server Developer Platform - SQLCLR, TSQL Enhancements
  • Business Intelligence Platform - Reporting Services, Analysis Services, Data Warehousing
  • Infrastructure Platform - Availability, Management, Database Mirroring

The conference venue will be the Miller Free Enterprise Center in the SLCC-Miller Campus in Sandy, Utah (9750 South 300 W).  The full day event will be on May 18th, 2005 from 8:30 AM - 5:00 PM (breakfast will be provided at 7:30 AM).

Come one and all to what will be a fantastic event!

Registration is open to everyone!

Tuesday, April 26, 2005 3:49:00 AM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Thursday, April 21, 2005
Ever deploy “debug” ASP.NET into production?  If so, you might want to review this excellent article by Milan Negovan.  Recommended reading for anyone who writes and deploys anything ASP.NET.
Thursday, April 21, 2005 2:08:00 AM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, April 20, 2005

Well, after much deliberation and discussion, we finally decided on a name for the new addition to the family:  Loganne Amber Zupancic.  Loganne pronounced as 'Logan'.  We opted for the spelling variation 1) to be more consistent with her sisters' names and 2) to make the name appear more feminine (though Logan is a perfectly good girl name).

She and mom got home from the hospital today and both are doing great.  We're so excited to have her home and in our lives!

Wednesday, April 20, 2005 10:19:00 AM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, April 19, 2005

Ok, I must admit that I think this is AWESOME!  Though I'm perhaps a bit late to this party, seeing that Craig Paterson posted on it last March, and apparently it's been available for some months, but I wanted to help spread the word for those that hadn't seen this, or known about it.

When it comes to favorite games, the original The Legend of Zelda is probably at the top of my all-time list.  That game was a lot of fun.  Well, it appears that Armageddon Games has created a tribute to the original game (in that it replicates exactly the game we all love), but they've made it extensible.  This allows people to go in an create new quests, items, enemies, graphics, etc.

I am in love...retro-love.

Tuesday, April 19, 2005 7:33:00 AM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback