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.

Saturday, March 31, 2007

VSLive, Day 4, .NET 3.0 & ASP.NET 2.0

More WPF today and a little bit on ASP.NET

WPF Keynote:

WPF = The best of the Web + The best of the desktop

Powerfull Graphics:

  • Scalable
  • Persisted, you draw something once and it stays on the screen.
  • 2D
  • 3D
  • Media
  • Animation

Next Generation Reading:

  • Pagination
  • Columnization (automatically and dynamically layout for best reader experience, seen new york time, seattle ...)
  • Cleartype
  • Rich content integration

Rich UI Framework

  • Databinding, but not the way we know it from pre-WPF times
  • Layout, trough panels
  • Controls, set of basic controls is available (free grid from XCeed)
  • Templates, The controls don't know what they look like, but ask the parent instead. If nothing specified then a default is being used.

Demo "Allscripts Patient Monitoring" shows WPF in Full power. It can be found at the PDC2005 page of Rob Relyea

"Power of Design, use design for better User Experience."

WPF is targetted to be used by 3 roles:

  • Developer
  • Designer
  • Integrator

http://www.notstatic.com/
http://www.loveyoursoftware.com/

-----------------------------------------------------

What can be animated:

  • Size
  • Position
  • Rotation
  • Color
  • ...

Why do you need animation? Animation fits the way the Human Brain works!

What technology should be chosen?

  • HTML: Online browser based, multiplatform, simple UI
  • WPF/e: Online browser based, multiplatform, (Flash alike) (small download, like Flash, targetted around 2 MB or so)
  • WPF in browser: Online browser, single platform, 3D etc. (requires .NET 3.0)
  • WPF locally: Installed locally with or without online capbilities (requires .NET 3.0)
  • Microsoft Blend (designer for XAML) visual design tool for designing UI.

WPF Examples WPF Application Portofolio

Datatemplate is a piece of XAML (segments) that describes how te represent the data. Switching at runtime of datatemplate is possible!!!

Demo cancer application: www.interknowlogy.com

Demo (from Microsoft site):
ExpenseIT, WPF/e demo, extension is .xbap

Demo
Evolution Media Center

Demo
UniveRSS A cool Reader!

Best reference book at the moment:
WPF Unleashed

Windows forms is at it's end-of-life. It will not being taken very further more.
WPF is in the early stages and will be primarly focussed by Microsoft to improve.

On BIG teams a dedicated developer for creating designs.

Some answers to questions from the audience:

  • XNA for gaming.
  • Deploying WPF is simple, the problem is the integrated video card.
  • XPS is killer for PDF.

-----------------------------------------------------

ASP.Live track: Building a Custom Membership and Role Provider

It's posible to use all the standard ASP.NET controls for login, loginstatus and so forth by implementing your own Custom Membership Provider. By also implementing a Custom Role Provider even the ASP.NET Web Site Administration tool works for managing users and roles.

By default ASPNET.MDF contains the user info. However what to do if you already have a database with user and/or role info. The following figure shows that the Proider Model allows you to replace an existing default provider with your own one in order to accomplish this:


Source: Building a Custom Membership and Role Provider, presented by Chris Franz at VSLive

Override every single method. The following methods are most important:

  • ValidateUser
  • CheckPassword
  • GetUser
  • CreateUser

All "MemberShip Provider Properties" must be overriden.

What about Password protection:

  • Hashed is most secure, other options are Encrypted or Clear.
  • Use Password SALT (this attaches a known string to the password, before encryption and therefore increasing the password length to a fixed length)
  • It requires a Machine Key within the Web.Config. This can not be autogenerated, because of webfarms where each machine needs the same key ...

4GuysFromRolla has a very good book about customizing the Membership with additional information for the user (like address, telephone, ...)

Role Provider Properties and Methods needs to be implemented (more needs to be implemented as with Membership Provider, but not all)

Web.config can exists per directory!

Microsoft provides an example provider: Introduction to the Provider Model on MSDN

Writing a Custom Membership Provider for the Login Control in ASP.NET 2.0, by Dina Fleet Berry

--------------------------------------------------------------

Plain Old Windows Forms tricks:

The tricks being presented by
Billy Hollis were:

  • Tooltips containing custom drawing including images
  • Implementing dynamic resizing without 1 line of code, by using the TableLayoutPanel and FlowLayoutPanel
  • Oval buttons
  • A tutorial form within a grid, trough the controls collection that every control (including grid) has.
  • Field-level security with one line of code.
  • Checking for unsaved data with 2 lines of code, through the DirtyChecker

All examples and sheets will be made available trough www.dotnetmasters.com/VSLifeSF.htm.

Tuesday, March 27, 2007

VSLive, Day 3, .NET 3.0

Some tools that make life easier for editting XML and XSLT
XMLEditor integrated into Visual Studio
  • Create dataschema from example XML
  • Associate schema to XML file enables template insertion of xml fragments

XSLT Debugger

  • Use breakpoints in the XSLT and watch variables.
  • Use breakpoints in the source XML file also.
  • Step into XSLT debugging from a normal code.

Future XSD Designer (availble within "Orcas")
Features including:

  • XML Schema Explorer
  • Entity Data Model (EDM) Wizard:
    Generates class model from existing database
    Drag and drop fields onto a windows form
  • Future EDM Designer:
    This is really cool stuff!!!
    Drag and drop database table onto the Entity Modeler.
    Drag another table over the first and the object combines the related tables into one object.
    Refactor database, while the objectmodel stays intact.
    Is going to work with ADO.NET
    New query language (Entity SQL)
    New Provider (Entity Client)

Data Interaction - LINQ to Entities

  • Query is an database language independent part of the code syntax instead of a database dependent string. It is being checked at compiletime.

Service Oriented Architectur (SOA) Design Patterns with Windows Communication Foundation (WCF)
When metadata is turned on then the WSDL. The URL of WSDL ends typically with <
url>?WSDL. This returns the top document that has a hierarchy of other WSDL documents describing each method or property on the interface. These can be viewed trough url?WSDL=, where reference can be found within the root WSDL.

Next to the WSDL an XSD schema is available also.

It's possible to extend (not change) the contract with an amendent. When a client uses an older proxy then the current service implements the response object has a filled ExtensionData element where the amendent can be found.

Breaking changes should be created within a new namespace. Nothing new here ...

Windows Presentation Foundation (WPF)
All possibilities from gaming engines made available within the .NET Framework.

WPF can call on GPU tools:

  • Transforms
  • Rotate
  • Scale
  • Gradients

Handles for windows nog longer exists. WPF renders controls within the main WPF window, which is the only window.

Since I have some experience with OpenSceneGraph, which is an excellent engine for 3D visualisation, I automatically compare WPF with the OSG. XAML is a declarative way of describing a scene, in some way this can be compared to a "scene graph" stored in an .OSG file. XAML however has the advantage that it can be verified against a scheme. I do not know whether both can be fully compared and hope to find that out within the next couple of days.

WPF uses style (wich can be compared to stateset in OSG???). Templates are more powerfull styles.

WPF uses scRGB values. -scRGB(0.5, 0.75,1.0).

Windows Communication Foundation (WCF)
Use Patterns & Practices for setting up Windows Communication Foundation. Visual Studio integrated CTP does a bad job for any more complex than very simple configurations.

WCF can be used for any layer (or better tier) that you want to implement for your solution. WCF can be scaled up (network boundary) or down (appdomain cross) later on, i.e. by implementing another protocol.

WCF Gives you:

  • Hosting
  • Instance Management
  • Asynchronious calls
  • Reliability
  • Transaction Management
  • Disconnected Queued Calls (i.e. trough MSMQ)
  • Security
  • An extensibility model for customizing nearly every aspect of its behavior.
  • Easy Interoperability (i.e. with Java by using basicHttpBinding, and JAX see ...)

Directly addresses .ASMX (and general Web Service) deficiencies:

  • Performance
  • Security
  • Transactions

So use WCF instead of .NET Remoting or .ASMX Web Services. These last 2 are deprecated. WCF fully replaces them, and offers a lot of other options more.

VSLive, Day 2, .NET Day

Today various speakers held several presentations and demos. This post summarizes the interesting things I heard today over all these presentations.

Visual Studio next generations
Codename "Orcas". CTP has been launched in March 2007. RTM is scheduled for late 2007.
Codename "Rosario". Will build further upon Orcas, featuring even more Team productivity trough their Team System.

WPF Demos that Rocks
Fabrikam. A virtual webseller of clothing, an example that uses SharePoint Server and WPF. Can not find it on the internet.
Family explorer by Vertigo. Will be made public by the end of this week.
WPFWonderland is all about WPF and WPFe

Vista compatibillity
User Account Control (UAC) is a new feature (note that a feature is not always an improvement) that influence applications running on Windows Vista. UAC is responsible for blocking access to functionality that requires admin priviliges.


When a user (even with local admin rights) starts an application, it will normally start without the admin privilige.

There are two ways to deal with admin tasks within an application:

  • Use a manifest that specifies that an application needs the admin privilige.
    This results in an application that upon starting notifies the user that the priviliges are being elevated to the admin level.
  • Elevate privilige "just in time" to the admin privilige within a running application, that started with normal privilige.
VSTO Rocks!
Visual Studio Tools for Office is an SDK that enables you to write fully blown Add-Ins for all office applications. This enables you to combine the power of .NET custom applications that are fully integrated into i.e. Excel or Powerpoint. With a few lines of code it's possible to add items to a custom ribbon. These add-ins can be document based or application based.

The document and Add-In can exist locally on the PC or somewhere remotely on the network.
3 scenario's for these customizations exist:

  • Local document, local Add-In
  • Local document, remote Add-In
  • Remote document, remote Add-In

One remark must be made that the full functionality of VSTO only works under VS 2005 Team System Edition. Some functionality will not work under VS 2005 Pro.

Database
Schema can be placed under source control trough the use of scripts. Every obejct within the database gets it's own script, like table, index and so on.

Developing a database project with Visual Studio looks very similar to devloping source code within a project. A live database can be imported and brought under source control. Check in and check out is very similar as with code. DBA Developers can change the database offline. When ready the DBA can review and update the live database.

Just renaming a field or so leads to "compile errors", because the field could be referenced. "Rename Refactoring" is capable of updating a field and all the places where it is referenced. This is very powerfull. This comes (optionally) with a "preview changes" dialog and it's also possible to use undo.

Database build, deployment and data generation can be integrated into MSBuild. Two types of deployments exist:

  • Full
  • Incremental
    This only deploys the difference between the target and the project.

Unit testing is now available, so you're existing code does not break upon changes.

PowerTools will be distrubuted trough the web. These include:

  • Move Schema Refactoring
  • Disambiguate Schema Refactoring
  • sp_rename Generation
  • Data & Schema Compare Build Tasks
  • SQL Script Pre-Processor
  • Dependency Tree Viewer
  • API Access to Schema View

ASP.NET
Brian Randall from MCWTech

"There is NO MAGIC to make your applications run faster"

Tools:

  • Process Explorer by Sysinternals, can be dragged over the application.
  • Process Monitor by Sysinternals.
  • Performance Monitor
  • Visual Web Developer 2005 Express Edition

    $$$
  • VS 2005 TE for Software Testers

    $$$$$
  • VS 2005 Team Test Load Agent

Tips:

  • Use Release Builds! If the release item is unavailable it could be that this option can be found in the web.config under the compilation tag.
  • Minimize Exceptions, because they are expensive.
  • Optimize Data Access.
    Avoid using unmanaged classic ADO. Use
    stored procedures for complex functionalities.
  • Design for Caching
    Output caching (caching a whole page hat has been requested)
    Fragment Caching (caching regions of a page)
    Cache API

Visual Studio Team Test lets you easily create repeatable tests, that can be adjusted to generate random requests to the ASP.NET page under test. These tests can be used within a load-test scenario. Performance counters help in determining where bottlenecks can be found.

Monday, March 26, 2007

VSLive, Day 1, Pre-Conference workshop (CSLA)

Build Distributed OO Apps in .NET 3.0

Speaker: Rockford Lhotka

Most important things heard today:


N-Tier is not the same as N-Layer.
N-Layer is always good, especially to structure your code, which makes it maitainable.
N-Tier involves a process-boundary, or even a network boundary. Therefore a tradeoff must be evaluated from the following:

  • Performance
  • Scalability
  • Fault tolerance
  • Security

Formula to calculate the Concurrent Transactions Per Second (ctps):
ctps = (NrOfUsers / UserThinkTime) * TransactionDuration

Split up Business Logic Layer in Client and Server.
In order to use business logic close to the UI for a rich UI feeling and close to the data layer for multi-object logic, one could split the business layer.

The splitted layer could be conneced using a DataPortal, which encapsulates the underlying mechanism (Remoting, WCF, Webservice, etc) of transfering the business objects from the client to the server and back. The DataPortal is an implementation of the Channel Adapter Design Pattern.

Using event and (binary) serialization.
Be careful with events and serialization, because you might serialize more than expected, depending on the serializer being used. Serializers that serialize (private) fields will also try to serialize the class that has an event subscription on the class, because it's referenced in the list of subscribers. 3 possibilities from here:

  • This is planned to happen.
  • This is not planned, but the subscriber class is serializable. This results in a larger performance and/or memory footprint hit, then expected.
  • This is not planned and the subscriver class is not serializable. This will result in an exception being thrown.

Solution for preventing the subscriber class from being serialized is to implement your own implementation of AddHandler, RemoveHandler and RaiseHandler.

The CSLA Framework.

"Rockford Lhotka’s CSLA .NET framework is an application development framework that reduces the cost of building and maintaining applications.

The framework enables the use of object-oriented design as the basis for creating powerful applications. Business objects based on the framework support many advanced features to simplify the creation of Windows Forms, Web Forms and Web Services interfaces." (copied from CSLA website)

The CSLA Framework combines (when needed) the best of object orientation and databinding, by providing a set of base-classes for objects that already common functionality for implementing IBindable.

Als it provides a method for defining Validation and Authorization rules. One can add (static) methods that add rules to a rules collection. For Authhorization each getter, setter and method must start with an additional call to a generic validation method to determine whether the current user may access the getter/setter/method in question. For Validation the setter must add an additional call to a generic validation method. Important here is that a "bad value" must be accepted and no exception may be thrown. The databindable components or errorprovider must examine an object to determine whether it has valid values for each property.

This framework could really enforce a jumpstart when implementing an object oriented design, that needs to be coupled preferably by standard .NET databinding.

LINQ, Language Integrated Query.

LINQ is a Microsoft Project that adds a native quering syntax to .NET Framework programming languages, therfore reducing the roughly 20 lines of code needed to fetch data back to 3 lines.

Additional CSLA resources:

Friday, March 23, 2007

Hello world!

These are the famous words for an application written with a new technology (at least for the developer in question). And blogging is new to me.

So here's my blog.

I don't know whether I'm going to feed this a lot, but at least it gives me some space on the internet, where I can leave my toughts about software development.