Блогът на Людмил Тинков. Ludmil Tinkov's Blog

Validation (): Element ‘<elementname>’ is not supported.

Contents

The Problem
The Cause
The Solution
Recap: How To Fix Broken IntelliSense


The Problem

Intellisense suddenly stops working for a whole namespace (registered as a tag prefix) of your custom ASP.NET web controls.

When you press Ctrl-Space or Tab, the auto-complete feature of Visual Studio does not suggest your custom control’s properties. Seems like Visual Studio does not recognize your control at all.

I’ve been experiencing this odd behavior for quite some time while working on an ASP.NET demo application prototype, and none of the solutions I’ve been able to find on the Internet seemed to resolve this issue.

Here’s how I’ve registered the “my” tag prefix in web.config:

The “__code” directive specifies that the namespace is located in an assembly that is generated dynamically as a result of the compilation of the App_Code folder. Placing all my custom controls in a separate class library and specifying a fixed assembly name for the tag prefix didn’t help.

Here’s the code for the MyTextbox custom control:

There’s nothing wrong with the code above. The culprit was elsewhere, as I found out later.

My first shot was to try and purge the ReflectedSchemas folder, as described in this thread at the ASP.NET forums. Unfortunately, this didn’t solve the problem in my case. I had also noticed that copying some of my controls to a new project (ASP.NET Website) temporarily resolves the issue until I copy the rest of the old website’s pages and custom controls. So I started a project-wide witch-hunt to find out the offending control or page. After a few hours of struggle, I managed to isolate the custom control that was causing the problem. Excluding the control from the project seemed to resolve the issue. When I included it back, those squirly green lines reappeared in the web-page markup for any of the custom controls defined in the MyControls namespace. So far, so good. I only had to find out the reason why a single custom control was screwing up an entire namespace registered as a tag prefix.


The Cause


The first thing that caught my eye here is the default value attribute that assigns char.MinValue, which is actually the null-terminating character used in C/C++ to designate the end of a string. (Actually, it is also used internally by .NET to mark the end of an underlying unmanaged string but the wrapping System.String class takes care of this automatically and C# developers would rarely come across such issues.) Since Visual Studio uses reflection to generate schemas for intellisense, I could imagine how this null character goes directly into the text content of the schema file. I opened the last generated reflected schema with Notepad++ and here’s what I found:

I made an educated guess that while reading in the reflected schema to generate intellisense information for the MyControls namespace, Visual Studio was unable to read further than this null-terminating character, hence anything that comes after is omitted and the whole schema is either discarded, or somehow rendered invalid.

To prove this concept to myself, I created a simple test application:




The Solution

What I did next is globally search and replace char.MinValue with another, less dangerous character (e.g. ’0′):

After rebuilding the project, intellisense was finally back:



Recap: How To Fix Broken IntelliSense

If you have problems with intellisense and auto-complete in ASP.NET projects:

  1. Close Visual Studio.
  2. Delete all files under

    C:\Documents and Settings\[Username]\Application Data\Microsoft\VisualStudio\9.0\ReflectedSchemas

  3. Delete all files under

    C:\Documents and Settings\[Username]\Application Data\Microsoft\VisualStudio\9.0\ReflectedTypeLibs

  4. Delete all files under

    C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

  5. Make sure none of your custom controls has a property attributed with a default value of char.MinValue (null-terminating character).

Comments (4)

How to schedule automatic daily backups of MySql databases

Today, I fiddled a bit with the good old MS-DOS batch files in order to create a parameterized script that backs up some of my MySql databases, appending the current date (in ODBC format) to the filename of the resulting backup file. The target database is passed in as a command-line argument:

C:\>backup database_name

Here’s the script of the backup.bat file:

@echo off
if "%1" == "" goto error
REM The line below assumes your date format is MM.dd.yyyy (e.g. 08.26.2009)
REM If your regional date format is different, change the offsets below to fit yours
set fname=C:\BACKUP\"%1"-%date:~6,4%-%date:~0,2%-%date:~3,2%.sql
REM The resultant filename would be "dbname-2009-08-26.sql"
REM where "dbname" is the first argument passed in to this BAT file
mysqldump --user=root --password=pass1234 "%1" > %fname%
goto end
:error
echo missing argument!
:end

You can replace C:\BACKUP with a folder of your choice, where you want your backup files placed. In the code above, don’t forget to replace pass1234 with your real MySql user password. For security reasons, you may also want to replace root with another, less-privileged user.
To create a user with read-only privileges that is able to backup all databases, use something like:

GRANT SELECT ON *.* to 'backup'@'localhost' IDENTIFIED BY 'pass1234';
GRANT LOCK TABLES ON *.* to 'backup'@'localhost';

Now you can replace “root” with “backup” in the batch file script.

The screenshots below show how you can use backup.bat to schedule automated daily backups of your databases. To create a scheduled task:

1. Open Task Scheduler from Administrative Tools (Control Panel). Click on “Create Task”.
2. Type in some descriptive name for the task and select other options as shown below:
Image 01
3. Click the Triggers tab and then click the New button to create a new trigger:
Image 02
4. Choose Daily and specify at what time of day the task should be triggered:
Image 03
Click OK to close the New Trigger window.

5. Click the Actions tab and then click the New button to create a new Action:
Image 04
6. Type in the location of your backup.bat file or click Browse to browse for it. In the Arguments box, enter the name of the database that should be backed up when this action is triggered.
Image 05
7. Repeat steps 5 and 6 for each additional database you wish to be backed up.
Image 06
Click OK to create the scheduled task.
8. Enter your Windows account password, when prompted:
Image 07
9. Before closing Task Scheduler, run the task manually to see if it works. To do so, in the Task Scheduler Library, right-click the newly created task and choose Run from the context menu:
Image 08
If the task works as expected, you should be able to see backup files in the backup folder you specified in your batch file (C:\BACKUP in my case).

Leave a Comment

How to dial your Internet connection automatically and keep it active

I’ve been wondering for days if there is a way to keep my Internet connection always alive. My first shot was to write a little proggie to do the job. I wrote it in C# and it worked just fine but soon I realized it takes about 40 megs of RAM just to start-up and ensure my Internet connection is active, which was a rather inefficient approach. (It was scheduled to run every 5 minutes or so). So I gave it up and decided to seek a better way to achieve this.

The RASDIAL command-line utility

After googling around for a few hours, I discovered a neat way to activate any pre-configured dial-up connection via a single command-line in Windows XP/Vista (and any NT-based Windows):

rasdial connection-name username password

where connection-name is the name of your dial-up connection as seen in Network Connections (this is how you named your dial-up connection when you created it), username is your dial-up networking username (the login name your ISP gave you for your ADSL/PPPoE/dial-up connection) and password is the password your ISP gave you.

I tried this manually first in a command prompt, in order to verify it works as expected. Then I created a Scheduled Task to execute this command line on a regular basis to ensure my computer is always online – even after unplanned system restarts and/or when I’m not logged in.


Creating a scheduled task

The easiest way to make rasdial execute on a regular basis is to create a scheduled task:

  1. Open Administrative Tools → Task Scheduler
  2. On the General tab, enter a descriptive Name for the task and select the Run whether user is logged on or not option.
    Image 1

  3. On the Triggers tab, click the New button to create a new trigger for the task.
  4. In the New Trigger dialog box, select the Daily option, check the Repeat task every: check box, and choose “5 minutes” from the drop-down list next to it. From the drop-down list named for a duration of:, select “Indefinitely”.
  5. Image 2

  6. On the Actions tab, click the New button to create a new action for the task.
  7. In the New Action dialog box, type in “rasdial” into the Program/script text box. In the Add arguments text box, type in the connection name, the username and the password, separated by spaces. [As The Offspring sing: You gotta keep'em separated]
  8. Image 3

  9. Click OK and provide your Windows account password, when prompted
  10. Image 4
    [Note: These have nothing to do with the username/password your ISP gave you]

Before closing Task Scheduler, you can test the task: Disconnect from the Internet and then manually run the newly created task (from within Task Scheduler), to see if you will get connected.


If you’re reading this post, it’s because my home computer is online at the moment, most probably due to the fact that this scheduled task is keeping my Internet conection active (almost) all the time.

Comments (9)

Installing WordPress on a 64-bit IIS7

Today, I successfully installed WordPress 2.8.4 on one of my home machines (running PHP via FastCGI on a 64-bit IIS7). At first, I anticipated there would be lots of issues but eventually it turned out to be much easier than expected.
I followed the instructions provided by Dave Lawlor in his post Installing WordPress on IIS 7 – Part 1 and everything went almost smoothly, except for when I tried to install a different wordpress theme.

 

The Problem

WordPress admin panel asked me to provide Connection Information (FTP hostname, username and password) but it didn’t say why. The message said:

To perform the requested action, connection information is required.

While googling for a possible cause and solution to this problem, I came across Chris Abernethy’s post: Why WordPress Asks for Connection Info and it all started to make sense (although his post was actually for WordPress on Apache on Linux).

 

The Cause

I had installed WordPress under c:\inetpub\wwwroot, where it was restricted by Windows Vista’s User Account Control (UAC), which I didn’t want to turn off. Even after I gave full permisions to the NETWORK SERVICE account, WordPress still refused to install a custom theme and continued to ask for Connection Information, which implied that it was still unable to access the underlying folder structure.

 

The Solution

I just copied the whole wordpress folder to a path that is outside the c:\inetpub\wwwroot folder (e.g. c:\myweb\wordpress) and edited the Basic Settings of the Web Site in IIS Manager to point to this new folder. To be on the safe side, I also dropped the existing wordpress database, created an empty one with the same name, re-granted all user privileges as necessary, and installed wordpress anew. Since PHP refused to start, I also had to modify my php.ini file like this:

open_basedir = c:\myweb

So, now I’m enjoing a fully-functional WordPress blogging system with the Vistalicious theme installed. I’ll just have to figure out a way to keep my PPPoE connection to the Internet always active, so that my blog be always online — even after unplanned system restarts.

Comments (7)