Monthly Archives: August 2011

IIS: Unknown attribute “targetFramework”.

I have got another IIS error message: “Unknown attribute ‘targetFramework'”.

<system.web>
  <compilation debug="true" targetFramework="4.0">
    <assemblies>
      <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

It seems to indicate that the site is configured to run under .NET 4 while IIS has been set up to run under an earlier version. To target .NET 4 in IIS, open the IIS Manager and expand the Application Pools node. Then find the application pool used by your web site, call the context menu and choose “Basic Settings” and then switch the target framework from 2.0 to 4.0.

IIS HTTP Error 500.19 – Internal Server Error

Today I have faced with the “HTTP Error 500.19 – Internal Server Error” after publishing my ASP.NET project.

Additional details:

HTTP Error 500.19 – Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Module IIS Web Core
Notification BeginRequest
Handler Not yet determined
Error Code 0x80070021

Solution:

The solution is to install (if it is not installed or reinstall) ASP.NET feature of IIS7.0:

Control Panel -> Program and Features -> Turn Windows Features On or Off -> Internet Information Services -> World Wide Web Services -> Application Development Features -> Check/Uncheck ASP.NET.

ObservableKeyedCollection class!

I am writing a file management application at the moment and I have the following ViewModel in the application:

public class DirectoryViewModel : ViewModelBase
{
    public SomeBindableDictionary<string, DirectoryViewModel> Directories
    {
        get;
        private set;
    }

    /// <summary>
    /// Unique name of directory.
    /// </summary>
    public string Name
    {
        get;
        private set;
    }

    // Skipped...
}

So, when a directory is removed from a physical file system, the Directories dictionary is used to perform remove the corresponding directory ViewModel by the directory name (directory name is used as an index).

Have found two collection classes that solve the problem.
* ObservableDictionary. The class represents keys and values as separate entities. It isn’t so convenient to bind to Key and Value property in HierarchicalDataTemplate. Furthermore, Items and Values collections properties do not implement INotifyCollectionChanged interface.
* ObservableKeyedCollection. The class uses the key which is a part (!) of the values you’d like to store in the collection. The collection does not separate key and value. You need just to bind to the collection as you did it before with ObservableCollection<T> class. So, this option suits the requirements very well.

Directories = new ObservableKeyedCollection<string, DirectoryViewModel>(directory => directory.Name);
Directories.AddRange(childDirectories);

The piece of code is quite self-descriptive: it creates an observable keyed collection for directories, directory name is used as a key.

To remove the directory by it’s name you just need to call:

Directories.Remove("Some directory");

The collection change will be automatically reflected on the UI.

Download

P.S. After downloading please rename .doc to .zip.