Wednesday, February 13, 2008

Fix for "Known Bug" when Creating ADO.NET Data Services with Visual Basic and a Web Application

My ASP.NET 3.5 Extensions Preview Released post of December 10, 2008 included a "Data Services (Project Astoria)" topic that contains the following details for creating an ADO.NET Data Service:

The Creating ADO.NET Data Services QuickStart instructions for ASP.NET Data Services show you how to get an Entity Framework-based data service up and running.

Note: There is a typo and an error in the QuickStart instructions for the "Create the Data Service" topic.

  • In "When the Add New Item window appears, select SimpleDataService," replace SimpleDataService with ADO.NET Data Service.
  • The following instruction doesn't work for VB services. "In this example, the database was called Northwind so the namespace is NorthwindModel," you must replace NorthwindModel with SimpleDataService.NorthwindModel in the Imports statement to make NorthwindModel visible.
  • The VB version then fails with an "The member with identity 'NorthwindModel.Categories' does not exist in the MetadataCollection" error message written to Default.aspx.

It turns out that the VB version of this ADO.NET Data Services CTP fails due to a known—but apparently unreported—bug when starting with an ASP.NET Web Application, which I reported in the Creating a New ADO.NET DataService with VB Fails, C# is OK post of February 12, 2008 in the ADO.NET Data Services (Pre-release) forum. According to Microsoft's Pratik Patel:

This is a known bug. For the time being, just clear the root namespace in the VB project. [Emphasis added.]

It turns out that you also must clear the namespace prefix, which was NwindDataServiceVB for my project, from the Imports directive (Imports NwindDataServiceVB.NorthwindModel) and the Service attribute in the

<%@ ServiceHost Language="VB" Factory="Microsoft.Data.Web.DataServiceHostFactory, Microsoft.Data.Web, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" Service="NwindDataServiceVB.Northwind" %>

directive of the Northwind.svc file. (Open it with the HTML editor for editing).

It behooves the ADO.NET team to be proactive in reporting named bugs in the appropriate blog (Astoria Project Team Blog for this example), rather than mystifying CTP pilgrims.