As the new versions .Net Framework is released, most of us also migrate our existing application to take the benefit of the new version. With each new version, some or the other existing coding methodoloy is changed. Though Microsoft provides the utility within the newer VS IDE to migrate the solution/project, we still require to manual remove all the error/warning, which occurs due to the migrations.
Following are the steps/procedures which need to be followed for easily migrating existing web projects from VS 2003 to VS 2005.
Following are the step which needs to be executed before the migration process is initiated:
MS Visual Studio 2005 Installation:
- VS 2005 should be installed
- Delete the virtual directory path specified in IIS for the selected web project. This is required only if you are going to create a new folder for the migrated code.
Latest Source Code from Source Safe:
- Open the which ever source safe you are using for you product.
- Take the latest version on you machine. Preferably, make a new folder for migrating the application.
- Read-only Attribute setting: Select all files/folders for the project and remove the 'read-only' attributes. Make the entire file writeable.
- If possible, remove the source safe related files, if any.
- Once the source code is copied to the new folder, we need to reset/create the virtual directory in IIS for the website. The physical path should point to the folder created in the above step (Latest Source Code from Source Safe)
MS VS 2005 provides us with the wizard for converting VS 2003 web application to VS 2005. Following the steps laid down below for migrating the VS 2003 web application to VS 2005:
VS Migration wizard is a simple tool which helps us in migrating the code to VS 2005.
Following are the steps to start the migration wizard
Open windows explorer and select the folder, where the latest source is copied.
Right click on the project solution file (.sln) and select Open With -> Microsoft Visual Studio Version Selector. In case the version selector does not open the solution in VS 2005, then open VS 2005 IDE and then select File->Open->Project File
This version selector option will open the project solution in VS 2005 and will start the migration wizard.
Wizard Welcome : Click Next
Choose to create backup: Normally, we have the code in source safe. Thus we can select "No" for creating backup file. If you still wish to store the backup before conversion, you can select "Yes" and set the path, where the backup files should reside.
Ready to Convert : Click Finish
This should take few second depending on the size of the project.
This is the Step I of migration.
On successful conversion, VS 2005 IDE will display the following message. This message requests you to complete the step II of the migration process by clicking "Convert to Web Application" in Solution Explorer.
Conversion Complete: Select the "Show the conversion log when the wizard is closed" if you wish to view the conversion log.
- Right click Solution in Solution Explorer and select "Covert to Web Applications"
Manual Project Migration Steps
The migration wizard does most of the migration activity for converting VS 2003 project to VS 2005. At this point if we view the "Error List" windows in the VS 2005 IDE, we can see many error and warnings. All these error/warning needs to be rectified manually. Most of the error/warning is due to the referencing, obsolete class etc.
Following is the list of the error/warning and their resolution steps:
Assembly Referencing: As we migrate the application, few of the assembly reference needs to be reconfigured. We can get list to the missing reference assembly by right clicking Solution Name ->Properties. In the properties window, select the Reference tab.
The Reference tab will list all the assemblies referenced by the application. Along with these assembly list, we can find the few assemblies with the Path specified as <The system cannot fine the referenced specified>. These are the assemblies whose reference is missing. We need to reconfigure the reference for these assemblies.
- Not down the assemblies whose path is missing
- Remove all these assemblies whose path is missing.
- Add the assembly reference for all the missing assemblies by selecting the correct path.
After adding the missing referenced assemblies, re-build the solution. The error count would be reduced after completion.
Unused Local Variable: During the course of development, we declare variables which are never used within the code. All such variables would be marked as "unused variables" by the VS 2005 IDE. We can get the list of unused variables in the warning tab of Error List window.
- Remove all unused variables.
- After removing all unused variables.
- Save the solution.
Variable Used before value assignment: During the course of development, we declare the variables/objects, but do not initialize them, and thus this is a potential for exception - NullValueException. To eliminate such exception, we need to initiate the variables/object before they are used.
- Get the variables which are not initialized from the warning tab of Error list.
- Initialize the variables wherever it is declared.
Member Variable Name: As per the CLS-complaint, no class or class member name can start with underscore (-). Thus all the member which start with underscore (-) needs to be changed.
- Locate the warning(s) "Name '_%MemberName%' is not CLS-compliant."
- Rename the variable by removing the underscore (-).
Shared Member Access: VS 2003 allowed a class objects to access the shared members of its class. But VS 2005 disqualifies reference to shared members of a class through its object. Instead we are supposed to access the shared members using the class name.
- Locate the warning(s) "Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated."
- Access the shared member of a class using the class name instead of the object.
Function Not Returning Value: VS 2003 allowed defining functions which does not return value. Such function is marked as warning in VS 2005.
- Find the warning(s) " Function '%%Function Name%%' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used."
- If the function is not suppose to return value
- Change it from Function to Sub
- If the function suppose to return value
- Return the value from all the code path.
Obsolete Components/Function: Few VS 2003 .NET Library components have been marked as obsolete and newer components have been provided in VS 2005. All these obsolete components need to be replaced with the newer components.
Following is the list of the components which are marked obsolete:
This component is marked as obsolete and thus needs to be replaced with System.Configuration.ConfigurationManager
- Add reference to System.Configuration.dll .
- Note: The System namespace does have the System.Configuration namespace. But its does not include the ConfigurationManager class. In order to reference this class we need to add the reference to System.Configuration.dll
- Change System.Configuration.ConfigurationSettings with System.Configuration.ConfigurationManager
- VS 2003 : System.Configuration.ConfigurationSettings.AppSettings.Item("SiteScope")
- VS 2005 : System.Configuration.ConfigurationManager.AppSettings.Item("SiteScope")
- Replace the above change through out the application, wherever System.Configuration.ConfigurationSettings is used.
- Save the solution.
System.Data.SQLClient.SQLParameter.Add(parameterName As String, value As Object) :
The method System.Data.SQLClient.SQLParameter.Add(parameterName As String, value As Object) is deprecated in VS 2005 and thus need to be changed with System.Data.SQLClient.SQLParameter.AddWithValue(parameterName As String, value As Object)
- Locate the warning(s) "Public Function Add(parameterName As String, value As Object) As System.Data.SqlClient.SqlParameter' is obsolete: 'Add(String parameterName, Object value) has been deprecated. Use AddWithValue(String parameterName, Object value)."
- Change System.Data.SQLClient.SQLParameter.Add(parameterName As String, value As Object) with System.Data.SQLClient.SQLParameter.AddWithValue(parameterName As String, value As Object)
- VS 2003 : System.Data.SQLClient.SQLParameter.Add(parameterName As String, value As Object)
- VS 2005 : System.Data.SQLClient.SQLParameter.AddWithValue(parameterName As String, value As Object)
- Save the Solution.
The System.Web.UI.Page.Title property is marked as overridable. Thus if is any of the web forms which is inherited from System.Web.UI.Page is using Title as its public property, then it needs to be marked as "overloads".
- Locate the warning(s) "property 'Title' shadows an overloadable member declared in the base class 'Page'. If you want to overload the base method, this method must be declared 'Overloads'."
- Mark the Property as "Overloads"
- Save the solution.
The method Page.IsClientScriptBlockRegistered(key as String) is marked as obsolete in VS 2005 and thus need to be changed with ClienScript.IsClientScriptBlockRegistered(key as String).
- Locate the Page.IsClientScriptBlockRegistered(...) and replace it with ClientScript.IsClientScriptBlockRegistered(...)
- Save the Solution.
The method Page.RegisterStartupScript(...) is marked as obsolete in VS 2005 and thus need to be changed with ClienScript.RegisterStartupScript( Type , key as String, script As String).
- Locate the Page.RegisterStartupScript(...) and replace it with ClientScript.RegisterStartupScript(GetType(%%ClassName%%>, %%key%%, %%script%% )
- Save the Solution.
The method Page.RegisterOnSubmitStatement(...) is marked as obsolete in VS 2005 and thus need to be changed with ClienScript.RegisterOnSubmitStatement(...).
- Locate the Page.RegisterOnSubmitStatement(...) and replace it with ClientScript.RegisterOnSubmitStatement(...)
- Save the Solution.
The method Page.RegisterClientScriptBlock(...) is marked as obsolete in VS 2005 and thus need to be changed with ClienScript.RegisterClientScriptBlock(...).
- Locate the Page.RegisterClientScriptBlock(...) and replace it with ClientScript.RegisterClientScriptBlock(GetType(%%ClassName%%>, %%key%%, %%script%% )
- Save the Solution.
Note: If the above scripting functions is used in UserControls then, we needs to reference these scripting functions as : Me.Page.ClientScript.%%ScriptingFunction%%
The System.Web.Mail class have been marked as obsolete in VS 2005, instead we need to use System.Net.Mail. Along with the namespace change, there are few new objects been introduced in the System.Net.Mail class:
The System.Web.Mail.MailMessage is marked as obsolete in VS 2005; instead we need to use System.Net.Mail.MailMessage.
- Locate warning System.Web.Mail.MailMessage' is obsolete: 'The recommended alternative is System.Net.Mail.MailMessage.
- Change the Import statment as following:
- VS 2003 : Imports System.Web.Mail
- VS 2005 : Imports System.Net.Mail
The MailMessage class is used to send the mail. The mail properties like From, To, CC, BCC are string variable in VS 2003. But in VS 2005, these properties are of type 'MailAddress'. The 'MailAddress' is a new class introduced in VS 2005. This class is used to store the email address.
- Locate the error: Value of type 'String' cannot be converted to 'System.Net.Mail.MailAddress'
- Change the setting of email address for From, To, CC, BCC properties of System.Net.Mail.MailMessage object.
- Property To :
- VS 2003 : .To = %%String%%
- VS 2005 : .To.Add(New MailAddress(%%String%%))
- Property From :
- VS 2003 : .From = %%String%%
- VS 2005 : .From = New MailAddress(%%String%%)
For sending the mail using the SMTP, SMTPMail object is used in VS 2003. This class has been marked as obsolete, instead we need to use System.Net.Mail.SmtpClient class.
- Locate warning : System.Web.Mail.SmtpMail' is obsolete: 'The recommended alternative is System.Net.Mail.SmtpClient
- Declare a variable of type SMTPClient
- Dim clientMail AS SmtpClient
- Remove the following lines from the code, which were used to send the mail
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SMTPServer")
- Add the following lines to the code for sending the mail
clientMail = New SmtpClient
- In step -3 above, we have removed the line which was reading the SMTPServer address from the config file and setting it to the SMTPMail class. We still need to configure the SMTPServer address for sending the mail. In VS 2005, the SMTPServer is configured in config file, but in a seperate XML tag
The above process should eliminate most of the error/warnings from the application. If there are any other errors/warnings which are not mentioned above, please let me know, so that I can update the document accordingly.
After successfully resolution of errors/warnings, run the application and check each and every page for correct functioning.