Thursday, March 8, 2007

HRESULT -2147012867, Native Error 28037 on Merge Replication

When using a handheld device emulator to perform merge replication, you may receive this error when trying to synchronize. The reason might be very simple: the emulator may not have its network card turned on. It is not enabled by default for the PocketPC 2003 emulator.

For identification, the full managed error description is:
System.Data.SqlServerCe.SqlCeException was unhandled HResult=-2147012867 Message="A request to send data to the computer running IIS has failed. For more information, see HRESULT." NativeError=28037 Source="Microsoft SQL Server Compact Edition" StackTrace: at System.Data.SqlServerCe.NativeMethods.CheckHRESULT() at System.Data.SqlServerCe.SqlCeReplication.Synchronize() at SQLMobile.Form1.Synch() at SQLMobile.Form1.Form1_Load() at System.Windows.Forms.Form.OnLoad() at System.Windows.Forms.Form._SetVisibleNotify() at System.Windows.Forms.Control.set_Visible() at System.Windows.Forms.Application.Run() at SQLMobile.Form1.Main()

Wednesday, January 24, 2007

If GridView doesn't update data on Update command

Suppose you have set all parameters and the UPDATE statement properly, databound all controls, but the data is still not updated. In that case, you should check the DataKeyNames property of the GridView component to ensure that the property is not blank. This can occur if you are customizing the GridView datasource without using the wizard.

Input validation can't be reused in GridView templates

In the GridView, it's possible to define a blank template and another template will be used in place, e.g. if InsertItemTemplate is empty, the EditItemTemplate is used instead. Therefore, if they are supposed to be the same, just make sure EditItemTemplate is blank.

However, one thing to note is that the input validation control will not be duplicated. Therefore, if input validation is required (which it usually is), then, the control must be duplicated.

Tuesday, January 23, 2007

Solving error Code 2714 for Windows Installer

If you receive this error while running a built installation package:

"The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2714."

..it means that the path specified for the installation package is incorrect. There is nothing the user can do about this since it's a problem with the package itself. Basically, ensure that the DefaultLocation property is correctly set to the full path of the directory to create and that the path is valid. The '(Name)' property is actually not used to name the folder on the target computer, it is rather an internal name used in the installer.

Monday, January 22, 2007

Solving Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon' error

I uncovered yet another strange behavior of ASP.NET which was mentioned by Alex Thissen at http://www.alexthissen.nl/blogs/main/archive/2005/05/31/asp-net-2-0-need-to-know-thingies-for-beta2.aspx.

Although Alex mentioned this to be a problem with Beta2, it can also occur on the relase version, e.g. Microsoft .NET Framework Version:2.0.50727.91; ASP.NET Version:2.0.50727.210.

I got this error:
Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon'.
[InvalidCastException: Unable to cast object of type 'ProfileCommon' to type 'ProfileCommon'.] MasterPageCls.get_Profile() +67
MasterPageCls.SetDefaultZoningSystem() in c:\inetpub\...\MasterPage.vb:33
MasterPageCls.InitZSID() in c...\MasterPage.vb:152
MasterPageCls.Page_Load1(Object sender, EventArgs e) in ...\MasterPage.vb:186
System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

The resolution? Simply making a simple change in web.config for the application and saving it again, which worked. Referring to an earlier post on my blog, this time, clearing the temporary folder did not resolve the problem.

I find this error strange and a bit confusing. If the type has the same name, why can't I cast it? And what does an invalidated web.config have to do a class in the membership provider anyway?

Clearing up ASP.NET temporary file

Sometimes you may be getting unexpected error caused by configuration changes on the web server on pages that have been working correctly before. These errors may be due to the fact that the precompiled ASP.NET pages are out of date and that the temporary files have not been updated as they should automatically, which can, and does happen sometimes.

It can therefore help to clear the temporary folder:
C:\windows\microsoft.net\framework\v2.0.50727\temporary asp.net files
(Note: must be on the web server, not the local computer if your dev box is not on the iis box).

If you are unsure, move all subfolders and file out of the folder and test your site before deleting. These are not primary files created by the user so deleting them does not affect the source files of the site. However, deleting them will slow down access since compilation has to happen again for the site.

An example of this happened when I was installing FrontPage 2002 server extensions on W2K3 server, IIS 6.0. Then I suddenly got the error (asp.net error) access to the path ... \web.config is denied. No relevant source lines, source: web.config in wwwroot, line 0. Very odd indeed! And the error was pretty far from a security error, in fact, just clearing the temporary folder mentioned above solved the problem. Likewise, the uninstallation of FP2002 S.E. caused the error to occur again. Again, clearing the asp.net temp folder was the solution.

I'd say this is something you may try if "nothing else makes sense" and the "errors don't make sense" with asp.net..

Powerful input checking

Perhaps one of the most flexible and powerful ways to validate user input in any ASP.NET page is regular expressions.

If you have not heard about it yet, visit
http://msdn2.microsoft.com/en-us/library/ms998267.aspx

Fixing ASP.NET error BC30456

Ever got error BC30456?

Server Error in ... Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30456: 'MasterPageFile' is not a member of 'ASP.area_areamasterpage_master'.
Source Error:
Line 1: <%@ master language="VB" inherits="userpage_UserMasterPage, App_Web_oa_obube" masterpagefile="~/MasterPage.master" %>
Line 2:
Line 3:
Source File: ...AreaMasterPage.master Line: 1


The symtom is that pages run fine as long as being executed with dynamic compilation-in-place, but fails when running after being precompiled.

The fundamental problem is a collision of class names. In the same folder, two classes can't have exactly the same name. So, either of the classes would have to be renamed so that no two instances of classes exists with the same names.

Let's go back to definitions a bit though. A class "exists" here in the sense that we have a codebehind file with a line saying Partial Class userpage_UserMasterPage where userpage_UserMasterPage is in fact the class name.
This name is also replicated in the aspx file. As usual, the aspx and codebehind class names must match. This gives us a set of truths to maintain:
(1) define class name in codebehind file
(2) define class name in aspx file
(3) class name in aspx and codebehind file name must match
(4) class name must be unique (within application/namespace presumably)
Error BC30456 will likely occur if 1,2,3 is true but 4 is not true.

One simple cause of the error is that a page, including its codebehind file, has been copied to a new file, renamed and edited, but the name has not been changed. The result would be that the precompiled site compiles correctly but the page cannot be visited if there is an internal duplicate. It is therefore tough to spot these error until deployment compilation happens, as it doesn't show as a warning.

In a particular case I experienced here, the error occured in the case where there was an unused nested master page with the same class name, e.g.:

1. Root masterpage
2. Child masterpage of root masterpage (e.g. child of page in (1)).
3. Copy of child masterpage of root masterpage (e.g. copy of page in (2)).

The resolution was to rename the class name in the copied page. Although the copied page was not in use, the child page in use (e.g. in point 2) could not be visited, and as a result, all aspx pages using the child masterpage could not be visited, which were several!

Resolution: fixing one of the master pages (preferably the unused, to reduce the need for slowing-down recompilation on-the-fly) by
(1) opening two files of the master page: the codebehind and aspx
(2) devising a new unique name, e.g. by appending a suffix to the current name
(3) renaming class in codebehind
(4) renaming class in aspx
(5) saving
(6) recompiling

By the way, it is fine if there are similar class names but in different folders of the application.

Official Opening

Welcome to my new blog! This blog is intended to be a collection of my experiences on development using Microsoft's ASP/ASP.NET web development technologies and related development tools and techniques.

The purpose of this blog is mainly to provide readers and myself a searchable knowledge base archive of not-so-obvious answers to questions of general interest, and links to material on the web I'd like to highlight.

I am currently working as a developer at Tectön Ltd., Hong Kong, developing software for architects, property developers and construction companies.


Before we start, I'd like to add a short disclaimer regarding the content on this blog:

(1) The opinions on this blog are my own and my own only and represents my personal thoughts only, not any company, other individual or organization.

(2) Any advice given on this blog to you is given "as is" without any warranty or guarantee of fit for purpose. The fact that a solution I recommend works for me does not mean that it will work for you. Some solutions may also have side effects. Development environments and API:s are complex systems and more often than not, seemingly unrelated aspects of the system may interact unexpectedly.

(3) As a precautionary measure, I would advise you to keep an up-to-date backup of all data and settings before making changes to your system.

Feel free to comment on my posts in case. I hope you will find the posts on my blog useful.