Friday, June 08, 2007

ClickOnce Signing Bug

Visual Studio 2005 has a minor bug related to removing the ClickOnce signing option for a project. When the 'Sign the ClickOnce manifests' option is enabled, VS2005 creates an two entries in the project file: <ManifestCertificateThumbprint> and <ManifestKeyFile>. The problem is that when the ClickOnce option is disabled, these two entries still exist in the project settings (but are not configurable through the IDE). The entries have to be manually deleted from the project file.

Not that big of a deal, but annoying when you're syncing projects between developers. This bug leads to the classic, "Well, it builds on my machine" argument.

Happy (un)signing!

Wednesday, June 06, 2007

.Net Remoting Woes

I've run into a number of problems related to Serialization that have prevented normal, everyday, remoting from working.

Signed Assemblies

When using signed assemblies…

Specifying Types as Serializable

It may not seem obvious at first, but .Net remoting is a form of serialization. Serialization is the "deconstruction" of an object into a flat binary object for storage or transmission over some medium. So, when an object is remoted using, say, MarshalByRefObject attention must be paid to serialization…

Monday, June 04, 2007

Assembly.LoadwithPartialName vs Assembly.Load

Isn't it true that when we want things done 'right' it generally means we have to do more work? This is true for loading assemblies in .NET 2.0. Remember the good old days of loading DLLs in Win32 using LoadLibrary and simply specifying a DLL name? Sure, it was easy and straightforward, but it led to countless hours of contractors dollars wasted on untangling DLL Hell.

Using a framework that promises to rid us of DLL hell means we need to me more precise when loading Assemblies. This is why 'LoadWithPartialName' has been depricted in v2 .net.

But can't there be a happy medium? What if the DLL I'm loading is part of a shared framework that my organization has control over. What if we can guarantee backward compatibility and all I want to guarantee is that the latest version is always loaded?


 

Tuesday, April 10, 2007

Interfaces vs. Abstract Classes

When should I choose to design using interfaces and when should I choose to use Abstract Classes?


Interfaces’ purpose in life is much more clear than abstract classes: they’re meant to define a “contract” between a client and a server.  They prescribe a precice way that two components communicate with one another.  They provide a means of component interchangeability.


Abstract Classes provide the same benefits of “interchangeability” and polymorphism.  However, Abstract Classes have a few limitations.  Here’s an overview of the differences and the implications:


Classes may only inherit from one Abstract Class, whereas classes may inherit from multiple interfaces


The implication of this fact helps us understand the real measning behind interfaces.  Interfaces define a “prescribed capability” wheras abstract classes define a “design contract”.


This quality of “prescribed capability” is apparent in most well written component oriented code, and is illustrated by the fact that most interface names are adjectives related to a verb.  For example, some common .net interfaces are:


·  IComparable


·  ISerializable


·  IEquatable


· IFormattable


The “…able” suffix affirms this concept even more.  Interfaces describe an object’s “capabilities”.  Interfaces are used when one component attempts to determine whether or not another component supports a certain capability.  If it does, then the component can be used.  The details of how the actual object behind the interface implements the prescribed capabilities is of no concern to the client. 


So it makes sense that a class would be able to inherit multiple interfaces – a component based framework allows any given component to fulfill more than one capability.


Further more, using the concept of prescribed capabilities (i.e. adverbs) to design class interfaces leads to much more robust and elegent software designs.  The book “Head First Design Patterns” provides good insight into this concept in its introduction in which they recommend thinking of interfaces interms of “behaviors a class may support” rather than “a generic type of class”.


So interfaces really should be used to describe behavior capability. 


Designing around behavior capability is less intuitive and designing around types.


Wheras interfaces are tailord to describing behaviors, abstract classes are more tailored to describing types.


We said before that “designing against capabilities rather than types” leads to more elegent designs.  While this is true in terms of the overall structure of a software system, it does not mean that there are not benefits to designing against types.


Abstract Classes allow a way of providing a “design contract” rather than a “behavior contract”.  A design contract helps a designer understand how a derived class should “look” rather than “behaive”.  A design contract influences the backend design of a system rather than the front end.  It provides a way of enforsing certain design rules when designing derived classes or creating implementations of interfaces.


[There are two issues: 1) Enforcing a common external design – enforcing how a component should be used, 2) Enforcing a common internal design – enforcing how various implementations of an interface are built.  Theres a lot more here!] 


Another benefit of Abstract Classes is that they are actual classes, which in .net means that they’re System.Objects.  System.Objects have a lot of benefits:


-       Type conversion


-       Serialization (I think…)


-       Others?


A General Purpose Template 


So which do we use?  Use both!


Interface              ILoadable, IPlayable


    ^


Abstract Class         Bscan


    ^


Concrete Classes       M9Bscan, CorelisBscan


 


In conclusion, although interfaces and abastract classes are very similar from semantic and binary perspectives, they have quite different purposes and in terms of design should be used differently.


Guidelines


-       Abstract Classes should be as abstract as possible; i.e. they should look as much like interfaces as possible


-       “default behavior” should be used with care


-       Class Properties should not be interfaces

Calling Static Method Using Reflection

I was loading an assembly that contained a class that derived from a class which was defined in my assembly.  I wanted to call a static method in that assembly, so I used the Reflection GetMethod and Invoke calls.  Then I realized, that the static method was actully a static method of the class defined in my assembly.  So instead of using GetMethod and Invoke I could have just called the static method directly.


Would there be a difference? 


Turns out that the static method is executed in the assembly in which it is defined, regardless of whether or not GetMethod and Invoke are called or if the method is called directly.


Testing BlogJet

I have installed an interesting application - BlogJet. It's a cool Windows client for my blog tool (as well as for other tools). Get your copy here: http://blogjet.com


"Computers are incredibly fast, accurate and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination." -- Albert Einstein

Wednesday, June 21, 2006

Notes on IE CSS Popup Bug

The "pure CSS" popup code doesn't work on IE. Check out this link for a fix:

http://www.tanfa.co.uk/css/articles/pure-css-popups-bug.asp

Links Related to Development Tools

http://www.hanselman.com/blog/content/radiostories/2003/09/09/scottHanselmansUltimateDeveloperAndPowerUsersToolsList.html
http://msdn.microsoft.com/msdnmag/issues/04/07/MustHaveTools/default.aspx

Links Related to .Net Reflection

http://www.programmersheaven.com/2/Dot-Net-Reflection-Part-1
http://www.programmersheaven.com/2/Dot-Net-Reflection-Part-2
http://msdn.microsoft.com/msdnmag/issues/05/07/Reflection/

NotepadEx

A simple notepad utility that saves a file as a web page with CSS formatting. Allows user to define CSS styles and provides intellitext dropdowns for selected text, paragraph, and words.

Monday, June 19, 2006

Links and Notes

MSDN article on how to use XmlDataSource to access data stored in an XML file.

XPath query strings

Wednesday, June 07, 2006

Windows Workflow Foundation

Human Workflow addresses the problem of using software to coordinate the interactions between real human beings. Specifically, from the software perspective, the Human Workflow problem is this: software algorithms (aka Business Logic) are deterministic but the primary participants (Humans) are non-deterministic. How do we account for the "non-determinism" of the humans that will be operating our Busniness Logic software?

Microsoft has created the Windows Workflow Foundation to attempt to address this issue. The Windows Workflow Foundation is a development tool for Visual Studio that allows a developer to create Workflow Models. [Give an example]. The key is that these workflow models can be changed "on the fly" allowing the developer to modify a system's business logic according to unexepected human decisions without "bringing the system down".

I'm not in the business of creating business models or developing enterprise level applications, but I'm keeping my eye on this.