Technology with opinion

Wednesday, August 26, 2009

Working Around DLL Hell in .Net

Assembly Bindings with different Public Key Tokens

There was a little fiasco started when log4net accidentally generated a new public key token for log4net from version 1.2.9.0 to 1.2.10.0.  This became evident to me when I tried to do an assembly redirect in the .config file for NAnt so that it would use the newer version of log4net.  You get the public key token from any .Net assembly by executing the following command on it:

If you perforrm this against log4net 1.2.9 & 1.2.10 you will get b32731d11ce58905 & 1b44e1d426115821.  Therefore if you are executing a custom task that requires log4net (or who's dependencies require log4net) .Net will not let you redirect the two version because as far as Microsoft is concerend, they are not two different version of the same thing, they are different assemblies altogether.  However since they are different assemblies technically the work around is to rename one of the new assembly (1.2.10 in this scenerio) filename to log4net-1.2.10.dll.  Next in the NAnt.exe.config add the following within the <configuration> element

This will force .Net to load the new assembly alongside the old one thus avoiding any compatibility issues, bypassing DLL hell for good.

Tuesday, August 18, 2009

.Net Programmer Toolbox Summer '09

So for the Summer of 2009 this is the software that is in this .Net programmer's toolbox:
($ denotes how expensive it is. FOSS - free open source software)
  1. Visual Studio 2008 with SP1 - $$$
  2. NHibernate 2.1 - ORM framework - FOSS
  3. Spring Framework 1.3 - IoC/DI framework - FOSS
  4. NAnt 0.86 - .Net build tool - FOSS
  5. NUnit 2.5 - .Net Unit Testing framework - FOSS
  6. Telerik AJAX Controls 2009 - great inexpensive web controls for .Net.  They also have a fairly liberal license. - $$
  7. Resharper - inexpensive Visual Studio add-on for refactoring and overall enhancing your IDE - $
  8. Sqlite ADO.Net Provider - lightweight database great for Unit Testing or client-side database - FOSS
  9. StyleCop & StyleCopExt - Microsoft's source code analysis tool & my extentions - free
  10. MyGeneration 1.3 - .Net code generation tool - FOSS
  11. NBuilder - tired of writing hundreds of lines of code to create objects in memory for unit testing? This is for you - FOSS
  12. Rhino Mocks - best mocking framework for .Net. Supports generics - FOSS

Monday, August 17, 2009

Centering a DIV within HTML

I'm by far from an HTML or DIV expert but I try to stay compliant.  One of the change to HTML 4.01 standard requires that tables no longer be used for layouts but instead only be used for grid type data.  Putting that debate aside working with DIVs is a little tricky if you have grown accustom to HTML tables.  Until recently, what has long evaded me has been centering content within HTML without a TABLE or the deprecated CENTER tag until now.

There is a trick using negative margins that does it nicely and seems to work well in FireFox & IE.  First you will need to figure out a fixed size for your DIV (a good size that you content will fit within).  Let say your DIV is 300 pixels wide, next you multiply it times -.5 which will give you your left margin of -150 pixels.  You will always position this centered DIV using 50% left.  This will center your HTML content inside the DIV horizontally.  Perform the same technique with height & top margin in order to center vertically.

This will look like the following:

See Also: W3C Standard on HTML 4.01 Tables

Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. Additionally, when used with graphics, these tables may force users to scroll horizontally to view a table designed on a system with a larger display. To minimize these problems, authors should use style sheets to control layout rather than tables.

Tuesday, August 04, 2009

Using Spring.Net Proxy Factory with NHibernate

The latest version of NHibernate (2.1) discouples the framework from the dependency of relying on Castle (think DynamicProxy) therefore allowing you to plug in any framework for you are proxying.

Overview: NHibernate uses proxies to facilitate lazy loading, this proxy mechanism allows NHibernate to intercept the calls to your properties and classes thus delaying a call to the database that may not be needed (Lazy Loading).

After you have downloaded NHibernate 2.1 and extracted the contents you will notice a new folder titled "Required_For_LazyLoading". Inside this folder are 3 separate folders containing binaries for the following proxies: Castle: LinFu & Spring. Since I'm using Spring framework in the rest of my project this allows me to have one less dependency (which is a good thing). As I understand it LinFu is the fastest proxy of the bunch so if you aren't using Castle or Spring already you may want to consider it.

The problem is that the NHibernate is distributed with an older verison of Spring so we want to tell the .Net framework that it's okay to use the new version. To do so were are going to use Assembly Redirection in our App.config or Web.config. The section below belongs inside your <configuration> section: