Friday, January 25, 2008

IList is not serializable in combination with XmlSerializer

Because IList<T> does not implement ICollection (but the generic ICollection<T> instead), the XMLSerializer is not able to serialize the items within the collection. More info on this "bug" can be found here:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105767

Friday, January 4, 2008

Implementing a custom Dispose for a form or usercontrol

Have you ever wanted to implement a custom dispose method for a usercontrol or a form. Trying to override protected void dispose(bool disposing) learns that the designer generated file (mycontrol.designer.cs) already implements this override.

Mark Seemann wrote an intersting approach for dealing with this situation in his blog. It makes use of an Disposer component. A new instance will be created with a reference to a method implementing the custom dispose functionality. This instance is being added to the components collection. When the components get disposed, the this Disposer calls the delegate function with custom dispose logic. That's it.

Thanks Mark for this article.

Wednesday, August 15, 2007

Error: Validation of viewstate MAC failed. in ASP.NET page

Full error:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the
same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.


This error may occur when one hosts an ASP.NET webpage on a web-garden.

Simple solution (for ASP.NET 2.0 and up): Generate a new machinekey and add it to the web.config.

Full explanation can be found in the blog of Jody.

Friday, June 8, 2007

Programmatic databinding between classes and controls

It's possible to programmatically databind to controls with the following statement:

myLabel.DataBindings.Add("Text", myObject, "Name");

However there are some specific controls that have trouble using databinding. Some should use another property, like Value or SelectedItem, while others need a specific
DataSourceUpdateMode. From my experience here's a list of controls and possible databindings:

  • Label
    myLabel.DataBindings.Add("Text", myObject, "Name");
  • TextBox
    myLabel.DataBindings.Add("Text", myObject, "Name");
  • NumericUpDown
    myNumericUpDown.DataBindings.Add("Text", myObject, "Age");
  • ComboBox
    mycomboBox.DataBindings.Add("SelectedItem", myObject, "Option", false, DataSourceUpdateMode.OnPropertyChanged);

Wednesday, May 16, 2007

Help not always on top!

Today I was asked whether it was possible to show the help in a non-modal manner. After a little searching on the internet, I found the following solution, posted in a forum by Rodger Constandse. It's a little trick but it works faboulous:

Create a new Form (once for an application). Call CreateControl() on it in order to create a handle to it, but it will not show up. See the following code-example:

public class MyApp
{
// Create a form as the parent for the Help window.
private Form m_HelpFormParent = new Form();

public MyApp()
{
// Enforce creation of a handle to the form
m_HelpFormParent.CreateControl();
}

public ShowHelp(string url, HelpNavigator command, object parameter)
{
// Call ShowHelp with the form created for this purpose as parent
Help.ShowHelp(HelpFormParent, url , command , parameter );
}
}

Sunday, April 22, 2007

Issue tracking with Gemini

In this blog I would like to mention some tools that I'm using, and that have helped me a lot. One of them is Gemini. We did issue tracking before with an Excel spreadsheet. But with growing number of team members that needed (simultanious) access to the issues, the spreadsheet way of working began to create a countereffect ...

After some searching on the internet I found Gemini (2.0.5 at the time), whose features look very attracting. Among the latetst version (2.1.1.) the following feature are available:

  • ASP.NET (2.0) web application running on IIS (v5, v6 or v7)
  • SQL Server database back-end (SQL Server 7, 2000, 2005 or MSDE)
  • Time-tracking (when you really want to ...)
  • Source control integration (Visual SourceSafe works perfectly, CVSNT integration and SubVersion adapter are available also)
  • Configurable email alert templates
  • Custom fields support (i.e. define additional fields for issues)
  • Personal issue filters (create your own view on the issue list trough a filter and save it the filter for later usage)
  • Gemini API – event/listener model (create your own extensions, we did not need them!)
  • Automatic project road map and change logs
  • Customisable issue type and priority (we extended the default types with ToBeTested)
  • Controlled anonymous user access
  • Flexible reporting – based upon XML/XSL
  • Export to Microsoft Excel
  • Issue linking across projects
  • Unicode support
  • Windows and web forms authentication (no need to log in when used on intranet)

One of the best things I liked was the ability to test with the free version for a reasonble amount of time (like forever) with a only few limitations. In the meanwhile our team has grown over the 10 user limit restriction and we have bought the product since it serves it's purpose very well. And that for only € 440, which gives you the abaility to use Gemini with unlimited users and on an internet-facing server!

These features combined with the financial aspect, convinced me to give it a try. Therefore I grabbed an old machine with a clean Windows XP installation. The machine specifications where not typically high end, with it's Intel Pentium III running at 800 MHz and 512 MB of RAM. Only installing takes a lot of time, but using the Gemini application has no noticable delays running on this hardware!

How to get up and running with Gemini on this machine (quickly may not be the right word, since 800 MHz is not lightning fast ...):

  • Install Windows XP, including IIS and with all the latest SP's and windows updates
  • Install Microsoft .NET Framework 2.0
  • Install SQL Server 2005 Express edition
  • Create a dedicated user account for Gemini which is allowed access to Gemini database within SQL Server.
  • Install Gemini
  • Adjust the web.config for customizing the following settings:
    - Database connection string
    - SMTP configuration
    - Set the Gemini URL, needed for emails being sent so that they implement the correct URL.
    - Set the DateFormat to EU
    - Set the authentication mode to Windows (instead of Forms) when using on an intranet.
    - Optional registration information

Additional (optional) steps:

  • In case you want to create the database and tables yourself, this is possible. See the documentation.Run IIS lockdown tool
  • Enable port 80 (HTTP WebServer) within the windows firewall.
  • Gemini supports Web Services Enhancements (WSE) 3.0. Certain web methods will require
    WSE to be installed on your web server in order to operate.

Last thing that I should really mention is the Gemini ScreenCapture application. This application allows a tester to quickly take a screenshot of the screen/window/user defined region and attach it to an existing issue. Before submitting it, the tester can something on the screenshot annotate with a pencil. This is really a cool feature that our testes use a lot.

Sunday, April 1, 2007

VSLive, Day 5, All about WPF

So, I'm very excited about Windows Presentation Foundation. Therefore I spent the last (workshop) day allday with Billy Hollis in his session about WPF, named: From the Ground up.

WPF is officially released. The tooling however to create i.e. XAML pages is in a very early state. The tools available at the time of writing can be found at the bottom of this page under resources. Therefore the amount of time it needs to write a WPF enabled application takes roughly 3 times longer than it should take, because of minimal tooling support. However it can still make sense to develop a WPF application, i.e. when the requirements of the app can be far more easily covered by an application using WPF.

Why is WPF such a revolution in UI design? The last transistion of the UI was 20 year ago. Every UI up until now was based upon GDI, invented in 1984. WPF is build on top of DirectX, which is capable of using all the power of graphic cards that are available to those stunning games also.

Furtermore it is vector based, making it possible to zoom without loss of detail.

In an attempt to fill in the gap between the rich UI experience on with Windows Forms on the web, a subset of WPF will be created by Microsoft, which is currently known as WPF/e (the e stands for everywhere). Some features are missing, like i.e. 3D. But WPF/e does not require .NET 3.0. It's even platform independent. It therefore supports MAC and Linux also. WPF/e will be introduced before the end of 2007. It will be a serious competitor for the nowadays widely used Flash.

User interfaces can be specified by XAML files (pronounced "Zammel"). XAML is an XML file, that describes the user interface as an hierarchy of (visual) elements. XAML is a big step towards declarative programming- Decalre what you want, not how it happens.

WPF Application Model:

  • System.Windows
  • Application objects as entry point
    - StartingUp, ShuttingDown events
    - Run method, MainWindow property, etc.
  • Visual elements
    - Page, Window

Sampleviewer (installed with "Visual Studio 2005 extensions for .NET Framework 3.0", currenlty a CTP) takes you around all the features of WPF one by one.

Differences between WPF and Windows Forms

  • No MDI in WPF
  • No build-in data grid in
  • WPF has "container/control" distinction
    - No Controls collection"Visible" > "Visiblity" in WPF
    - "Hidden" takes up space
    - "Collapsed" doesn't take up space
  • Absolute position in WPF is the exception, not the rule
  • Sizing and positioning are in device independent units (1/96 inch) in WPF
  • Scrolling is external to controls
    - ScrollViewer element
  • Non-containers can only hold one element
    - Called the controls "content"
    - Set with the Content property
  • Content can be any visual element
  • Content can itself be a container

Databinding:

  • Create a collection of stuff
  • Bind it to the context of the window
  • Bind controls to the item properties
  • Add navigation, filtering, sorting, and so forth

XAML Based Application (XBAP) are WPF enabled applications which can be used within a browser.

  • Act a lot like HTML pages
    - Non-installed, served from a web server
    - Browser hosted on the client (take over the whole browser surface)
    - Run in a security sandbox
  • Have their own project type under Visual Studio
    - Caution - March CTP bug on Vista
  • Published to Virtual Directory on web server
  • "NavigateURI" attributed used on links to navigate pages
  • App has read permissions to its original web directory
  • Can use IsolatedStorage for caching and state management.

Animation can consist of:

  • 2D and 3D Transforms
  • ...

Styles can be applied on the fly trough code or to triggers (i.e. hovering a button).

Ink is enabled in WPF (on Windows XP, after installing appropriate libaries).

3D Rendering of surfaces

  • Use full 3D capabilities underneath
  • Compose surfaces out of triangles
    - Triangle is the only primitive
    - Created as of MeshGeometry3D
  • Viewport3D is visual element to render 3D objects on screen in 2D
    - Apply camera angle, for example, to this viewport
  • Exporter for Autodesk 2DS Max is not (yet) official available

Types of events within the tree hierarchy of an WPF application

  • Direct (only on element)
  • Bubbling (move up the tree)
  • Tunneling events (from outside into the tree and down to the elements)

Tools for XAML:

Other resources:

Other blogs:

Examples of XAML Based Applications:

  • British Library, using WPF and thus requires Windows and .NET 3.0 installed at the client PC.