VS 2005 (RSS)

Visual Studio 2005

InteropForm Toolkit - .NET - VB6 bridge part 2

Ok, as promised, I finished C# project and item templates to be used with Interop Form Toolkit. In addition I extended Interop Wrapper Add-In to support C# code generation. You can download template, Add-In and full source code from here. I be glad to here what do you think.

Cross-Posted from here

InteropForm Toolkit - .NET - VB6 bridge

Do you have existing VB6 system?
Would you like to gradually migrate them into .NET world?
Can you afford "all or nothing" migration?

After a long period of talking and expectation Interop Form Toolkit is finally released. It is VS2005 Add-In together with project template and documentation, which allows to easy creating mixed VB6/VB.NET application. Toolkit automates interop objects generation and provides an easy way of VB6 - .NET communication through events and shared state. Toolkit is surprisingly fare documented and came with two sample project.

After couple of hours playing with new toy, one thing I could not understand is "why it supports VB.NET only?" It happens that I personally prefer C# these days... So with a little help of my File Disassembler buddy I translated project template into C#. Existing Add-In generates wrapper classes in VB.NET, and it should be translated also. Now I have simple, fully functioning, combined C#-VB6 sample. It is about 2:30 in the morning on my clock, so I'll recreate Add-In tomorrow (and will, hopefully, post it along with C# project template).

Cross-Posted from here

Visual Studio Express Editions will Stay Free

If you missed it here, it is a great news. Originally Express edition were announced as free for on year. After 5 million downloads, Microsoft decide to make those editions permanently free. You can consult this comparison table to decide if Express edition is good enough for you.

Cross-Posted from here

Client Side ''onsubmit'' Action

There are two ways to add some client-side processing before ASP.NET 2.0 page submitted.
1. Add onsubmit attribute to Form tag in aspx file
2. Use this.Page.ClientScript.RegisterOnSubmitStatement method
Is there any difference?
The answer is processing order.
When aspx page being processed internal collection (_registeredOnSubmitStatements) created which holds all submit statements in order of RegisterOnSubmitStatement calls. Value of onsubmit attribute from aspx added at the end. Client side script created from this collection as statements of WebForm_OnSubmit function.
Now, when the order is particulary importemnt? It will be if we will use validator controls. Validator controls that allows client side script also register submit statement (through BaseValidator class) at PreRender stage. If client side validation fails, any submit statement that follows will not be executed. This behavior is very useful in some scenarios but unwanted in others.
The suggestion is:
- If you need to execute client script on page submit regardless of validation result (submit attempt), use RegisterOnSubmitStatement method before PreRender (for example in Page_Load).
- If you want to execute script only after successful validation, use onsubmit attribute.

HowTo Change Master Page Dynamically at Runtime

Changing MasterPage dynamically is a simple task, but there is a catch. MasterPage can be changed in PreInit page or earlier. At this stage control tree is not constructed yet. The question is: "How can we use postback event to change MasterPage?" Usual solution for this problem is to save selected MasterPage file name into session, reload page and in PreInit set MasterPage according to persisted value. This works but requires additional roundtrip. Another solution is to intercept postback events in PreInit and process it, so here it is:


ASPX:
@ Page MasterPageFile="~/MasterPage.master" Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<asp:DropDownList ID="MasterSwitch" runat="server" AutoPostBack="true">
<asp:ListItem Text="Simple Layout" Value="MasterPage.master">asp:ListItem>
<asp:ListItem Text="Complex Style" Value="MasterPageComplex.master">asp:ListItem>
asp:DropDownList>
div>
asp:Content>


Codebeside:

using
System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page
{
   protected void Page_PreInit(object sender, EventArgs e)
   {
      switchMaster();
  
   protected void Page_Load(object sender, EventArgs e)
   {
      if (!IsPostBack)
      {
         Session[
"MasterSwitch"] = this.MasterSwitch.UniqueID;
      }
   }
   private void switchMaster()
   {
      if (IsPostBack)
      {
         // Get control that fire postback event
         string eventTarget = Request.Form["__EVENTTARGET"];
         if (String.IsNullOrEmpty(eventTarget))
            return;
         // At this stage we don't have control tree yet,
         // so we'll use previosly saved control ID
         string switchControlName = (string)Session["MasterSwitch"];
         if (String.IsNullOrEmpty(switchControlName))
            return;
         if (String.Compare(eventTarget, switchControlName, true) != 0)
            return;
         setMaster(Request.Form[eventTarget]);
      }
   }
   private void setMaster(string masterName)
   {
      if (String.IsNullOrEmpty(masterName))
         return;
      // In real implementation some logic to convert
      // selected value into real MasterPage File Name should be here
      if (String.Compare(this.MasterPageFile, masterName, true) != 0)
         this.MasterPageFile = masterName;
   }
}

ASP.NET 2.0 Client Callback bug

Client Callback is one of cool and a bit overlooked features of ASP.NET 2.0. A few minutes ago, when trying to prepare demo based on Client Callback I found a nice bug. When Client Callback defined following javascript code rendered to client (skeleton):
function WebForm_CallbackComplete(){
    for (i = 0; i < __pendingCallbacks[i].length; i++) {
    // Not important
    WebForm_ExecuteCallback(callbackObject);
    // Not important
    } 
}
WebForm_ExecuteCallback method invokes callback function which is defined on WebForm. The problem appears when you have global variable named i in your WebForm.  For example another "for loop": for (i = 0; i < 100; i++). In this case loop variable in WebForm_CallbackComplete receive unpredictable value and cause uexpected behavior.
Simple fix immediately solves the problem: "for (var i=0…" instead of "for (i=0..."


Conclusions:
1. Do not use global variable named i in client callback function.
2. More important: never use undeclared (global) variables in javascript, unless you are absolutely sure what are you doing.

ASP.NET 1.x to 2.0 Upgrade Center

ASP.NET 1.x to 2.0 Upgrade Center on MSDN finally lunched. This site will serve as the single content point for all upgrade related collateral to help customers who are already using ASP.NET today easily move forward onto ASP.NET 2.0. If you are interesting in other migration related issues you can still visit Migration Center.

Using Non-Default Database to Store ASP.NET 2.0 Application Settings

In beta1 of ASP.NET 2.0 there were two providers available to access application management data database. MS Access provider was default one. Access mdb file was created on demand and stored in Data application folder. In beta2 things were changed. Now we have only one AspNetSqlProvider. Personally I love single radio button configuration touch in ASP.NET website configuration tool :-) :
   
Still, default application configuration database behaves pretty much the same way. SQLEXPRESS database file is created by demand in App_Data folder. It is not best solution for all deployment scenarios.
I have been asked couple of times lately how to setup ASP.NET 2.0 application to store settings in non-default database. Let's say we want to use centralized MS-SQL server instead of CQLEXPRESS files in App_Data directory for each application. With beta2 we can easily achieve this. Management database connection string is defined by "LocalSqlServer" entry in connectionStrings section of config file. We can add following section to Web.config to access database of our choice:

<connectionStrings>
   <
remove name="LocalSqlServer"/>
   <
add name="LocalSqlServer" 
             connectionString="Data Source=SqlServerName;Initial Catalog=aspnetdb;Integrated Security=True" 
             providerName="System.Data.SqlClient"/>
</
connectionStrings>

Note: You can use aspnet_regsql GUI driven utility to setup new or configure existing configuration database. This simple utility installed with .NET 2.0 SDK and can be accessed from Visual Studio 2005 Command Prompt.

ASP.NET 2.0 Deployment Without Source Code

I was asked couple of times recently about deployment of ASP.NET 2.0 application without source code.
New compilation model of ASP.NET allow immediate application update, including changes in codebehind files (ASP like “JUST SAVE” behavior). You are no longer required to compile Web Application before accessing it. It is very convenient behavior for development and even testing environment, but what about production? We, usually, do not want to upload source code to production server to be JIT compiled. It is not so good for intellectual property protection and allows dangerous accidentally code altering.


In VS2005 we have a lot of options to deploy Web Site:

  1. xcopy deployment
  2. Copy Web Site Wizard - provide nice GUI for copying/synchronization of files to/from destination server
  3. Web Setup Project
  4. Publish Web Site Wizard
  5. aspnet_compiler SDK utility

You can not use first two options to copy application without sources because normally compiled assembly stored in ASP.NET Temporary directory and not under application root. Only last two options will allow you to deploy precompiled Web without source code.

Notes:
Web Setup Project
• In beta2 this option was moved from Website to Build menu.
• It is not present in Web Express edition.
• Uncheck “Allow this precompiled site to be updateable“ option to remove markup from aspx files
aspnet_compiler
• You can only compile Web Site or compile and deploy it in single step
• Can not deploy to remote computer. You will have to deploy locally and copy output to remote server.

Visual Studio 2005 Team System Suite June CTP

Visual Studio 2005 Team System Suite June CTP along with Team Foundation Server and VS Professional  is available now for MSDN Subscribers. Couple of important points about this build:

  1. It supports double server installation mode only
  2. It doesn't support Go-Live License
  3. It has improved documentation, a lot of bugs are fixed
  4. It suppose to be less stable than beta2

Read more from Rob Caron's post.

Microsoft Web Services Benchmarks for.NET 2.0

Microsoft has released a new version of the Web Service and XML benchmark tests originally developed by Sun. The new version implemented using .NET 2.0 Beta 2 and show a nice improvement in performance both of Web Service Requests processing and XML manipulation.

Unable to Update Default User Database from ASP.NET 2.0 site, published to IIS

In VS2005 beta2/MS-SQL EXPRESS if you are publishing your site to IIS virtual directory, attempt to access default user database (App_Data\aspnetdb.mdf) will fail. You will likely receive error message similar to this:

Failed to update database "D:\WebSites\ASPNET20CC\App_Data\ASPNETDB.MDF" because the database is read-only.

To reproduce the problem:
  1. Create simple web site with LoginControl and CreateUserWizard
  2. Publish site to IIS
  3. Browse login page from IIS virtual directory instead of Casiny
  4. Try to create new user or login with existing one
To fix the problem:
  1. Detach aspnetdb database from SQLEXPRESS using sseutil.exe utility.
  2. Remove *.mdf and *.ldf files from App_Data application directory
  3. Grant Read/Write access on App_Data to working process identity (ASPNET for IIS5.X or NETWORK SERVICE for IIS6)
  4. Copy *.mdf, *.ldf files back into App_Data folder
  5. Run application, refresh if any connection related error received

This bug is announced and fixed in later build of SSE. You can see full description here.

C# 1.0 Conformance in VS2005

Just found out new feature of Visual Studio 2005 (thanks to tip of Juval Lowy at TechEd lecture): you can ask compiler to check and compile code for 1.0 version of C#. You will receive errors for using new (C# 2.0) features.

To use it just go to the Project Properties>Build>Advanced and select ISO-1 in Language Versio combo. Notice that compiled assembly references will be resolve to version 2.0.

In conjunction with MSBuild Toolkit it gave nice solution for legacy applications support.

Free Microsoft E-Learning Courses

Microsoft just announced 17 Visual Studio 2005 and Sql Server 2005 courses free for public access. Enjoy!

Visual Studio 2005 Launch Date

Finally!
Lunch date for SQL Server™ 2005, Visual Studio® 2005 and BizTalk® Server 2006 is announced. All these products will be formally launched during the week of Nov. 7. Read press release.

MSBuild Toolkit for Visual Studio 2005 RC Announced

If you are looking for possibility to use Class Designer, Code Snippets, Refactoring and other cool features of VS2005 and still be able to compile your application for .NET 1.1 platform, MSBuild Toolkit is a great news for you. It is major upgrade of Compatibility Toolkit, released last year. Thanks Robert McLaws.