## Surprises Changing the Length of a Character Field in SSMS

December 14, 2013

I needed to convert a couple of CHAR and NCHAR columns to their VARCHAR/NVARCHAR equivalent, and noticed a peculiar behavior of the SSMS (2008 R2) table designer:

For example, when the original column was defined as CHAR(10), and I added the characters VAR at the beginning of the Data Type field and tabbed to the next column, the editor would not keep the resulting VARCHAR(10), but change the data type to VARCHAR(50), as is the default length for VARCHAR and NVARCHAR columns in the designer.

I found that this behavior was discussed in this SO question as occurring in SSMS 2005, confirmed in 2008, and, by personal experience, still exists in 2008R2 and 2012.

It seems that MS either does not care, or that it does not want to fix weird bugs due to “compatibility issues”.

## VS – Side-Effects of Upgrading a Project’s .Net Framework Version

September 16, 2013

The other day I was playing around with two of my applications, checktsql and SMOscript, as I was considering to include the functionality of checktsql into SMOscript.

Now, up to the current versions, both applications have been developed using Visual Studio 2008 targeting .Net 2.0. (I prefer to keep requirements to a minimum). But now I thought it was time to migrated them to VS2010/3.5 (client framework), and came across a couple of unresolved mysteries.

### Missing Exceptions in SqlCommand.Execute*()

The first mystery is that the behavior of the Execute* methods changed such that ExecuteNonQuery() and ExecuteReader() do not reliably raise exceptions any more if an error occurs in T-SQL.

Take the example

CREATE PROCEDURE TestTemp AS
CREATE TABLE #T (id int)
SELECT * FROM #T
GO

which checktsql tries to verify (with the SET FMTONLY ON option) like this

BEGIN TRAN
SET FMTONLY ON; EXECUTE [dbo].TestTemp
ROLLBACK

(Note that the transaction is actually created by SqlConnection.BeginTransaction(), but essentially it’s the same mechanism)

SSMS returns an error:

Msg 208, Level 16, State 0, Procedure TestTemp, Line 6
Invalid object name '#T'.

What I noticed after migrating the code to VS2010/.Net3.5 is that some (most?) stored procedures cause the error to be raised as an exception in .Net, and some do not. However, the behavior is consistent for each stored procedure.

Fortunately, I noticed the different behavior only when using the SET FMTONLY ON option, but still, there is a difference depending on which VS or framework version is used.

Teh internets did not really help me – I found a couple of discussions, but no documentation of the change, or how to get the original semantics back:

### SMO dependency on System.Core

When I tried to debug (and understand) above issue, and reverted the application back to .Net 2.0, but still build with VS2010, I suddenly got the error message during build:

The primary reference “Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL” could not be resolved because it has an indirect dependency on the framework assembly “System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ which could not be resolved in the currently targeted framework. “.NETFramework,Version=v2.0″. To resolve this problem, either remove the reference “Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL” or retarget your application to a framework version which contains “System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″

There was nothing I could do to get VS2010 to the original behavior (i.e.: compile successfully) targeting .Net 2.0, even though the same assemblies were referenced both in the VS2008 and the VS2010 project.

This thread on MS connect shows the “amusing” dependency zigzag that SMO assemblies implement, switch dependencies even between minor releases:

Posted by Chris Dennis on 4/20/2011 at 10:19 AM
Installing SQL Server 2008R2 Cumulative Update 7 upgrades Microsoft.SqlServer.Management.SqlParser to 10.50.1777.0 which again depends on System.Core v3.5.
Posted by Chris Dennis on 3/25/2011 at 12:50 PM
Installing SQL Server 2008R2 Cumulative Update 6 upgrades Microsoft.SqlServer.Management.SqlParser to 10.50.1765.0 which does not depend on System.Core v3.5. Only version 10.50.1750.9 has a dependency on System.Core v3.5.
Posted by Microsoft on 3/25/2011 at 11:08 AM
Your assertion is correct the Microsoft.SqlServer.Management.SqlParser took a dependency on System.Core v3.5. Any projects which reference this assembly directly or indirectly need to be targeted to .NET Framework V3.5.
This is a nightmare!

## Dealing with NHibernate System.IndexOutOfRangeException

September 4, 2013

Whenever I call SQL Server stored procedures from an NHibernate (3.2) application, I generate proxy methods that look like this

IList<T> MyProcedure<T>(ISession session
, [some parameters]
)
{
IQuery sp = session.CreateSQLQuery(@"BEGIN
EXECUTE MyProcedure
:SomeParameter
END")
.AddEntity(typeof(T));
sp.SetParameter<[datatype]>("SomeParameter", SomeParameter);
...;
sp.SetResultTransformer(Transformers.RootEntity);
//sp.SetTimeout(timeout);
return sp.List<T>();
}

and manually create the data class MyProcedureResult and the corresponding mapping class MyProcedure_Result.

The SP is invoked like this:

var result = Procedures.MyProcedure<MyProcedureResult>(session, [parameters]);

This usually works, but recently I experienced an exception when calling a specific SP:

[Data]

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: [Data]

Source Error:

Stack Trace:

[IndexOutOfRangeException: [Data]]
System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +5043194
System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +67
NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\NHybridDataReader.cs:363
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\NullableType.cs:236
NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\NullableType.cs:195
NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Type\AbstractType.cs:131
NHibernate.Persister.Entity.AbstractEntityPersister.Hydrate(IDataReader rs, Object id, Object obj, ILoadable rootLoadable, String[][] suffixedPropertyColumns, Boolean allProperties, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:2511
NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, String instanceClass, EntityKey key, String rowIdAlias, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:988
NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, String rowIdAlias, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:943
NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:875
NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:334
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:468
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:246
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1590

[GenericADOException: could not execute query
[ BEGIN
EXECUTE MyProcedure
@p0
,@p1
END ]
[SQL: BEGIN
EXECUTE MyProcedure
@p0
,@p1
END]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1599
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1497
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet1 querySpaces, IType[] resultTypes) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Loader\Loader.cs:1487
NHibernate.Impl.StatelessSessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\StatelessSessionImpl.cs:376
NHibernate.Impl.StatelessSessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\StatelessSessionImpl.cs:353
NHibernate.Impl.StatelessSessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\StatelessSessionImpl.cs:363
NHibernate.Impl.SqlQueryImpl.List() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\SqlQueryImpl.cs:160

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.547

As you can see, NH expects the column name [Data], which does not exist in the result set, causing GetOrdinal() to throw an exception.

What’s going on here?

Well, the stored procedure returns a result set containing the column name Data, but NH tries to find the column [Data].

After stepping through the source code of NH 3.2, I claim to partially understand how this happens.

When the entities and mappings are initialized, NH calls connection.GetSchema(DbMetaDataCollectionNames.ReservedWords) to check whether column names are reserved words. If a column name is found to be a reserved word, the name is flagged to be quoted and/or aliased when used in SQL.

If, however, the column name occurs in the result set of an SP, aliasing cannot be applied, and quoting is not required.

Quoting using backticks (name`) as proposed on SO did not help either.

After many experiments, my solution was to simply rename the columns in the SP (DataX), and add a column name mapping

map.Column("DataX");

to the class map.

## Visual Studio 2010: Publish hangs

May 23, 2013

I noticed something weird the last couple of days, something I had never experienced before:

Select an ASP.Net MVC application in Solution Explorer, right-click and select Publish…

The Publish dialog opens, I select publish to File System and enter the target path.

The Build process starts and completes, but the last line that is displayed in the Output Window is

Connecting to C:\path\to\publish...

Then Visual Studio hangs at 100% CPU usage (or, 25% on a quad-core machine).

You can hit Ctrl-Break, and the break is indicated, but nothing else happens, and VS is busy burning CPU cycles.

Fortunately I found this entry on Connect, and the first Workaround immediately solved my problem:

Delete the .suo file!

## DotNetNuke Error after Uploading New Skin

March 1, 2013

After uploading a new skin I developed onto a DNN 6.1.4 installation, the Host/Extensions page did not display the list of installed modules, skins, etc. anymore, but only showed the error message

Object reference not set to an instance of an object.

The current log file under \Portals\_default\Logs contained the complete stacktrace:

[date:time] [server][Thread:14][FATAL] DotNetNuke.Framework.PageBase - An error has occurred while loading page.
System.NullReferenceException: Object reference not set to an instance of an object.
at DotNetNuke.Services.Installer.Packages.PackageController.CanDeletePackage(PackageInfo package, PortalSettings portalSettings)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.extensionsGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
at System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.BindGrid(String packageType, DataGrid grid, Label noResultsLabel)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.extensionTypeRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.BindPackageTypes()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[date:time] [server][Thread:14][ERROR] System.Web.UI.Page - ~/Default.aspx?tabid=36&error=Object+reference+not+set+to+an+instance+of+an+object.&content=0
System.NullReferenceException: Object reference not set to an instance of an object.
at DotNetNuke.Services.Installer.Packages.PackageController.CanDeletePackage(PackageInfo package, PortalSettings portalSettings)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.extensionsGrid_ItemDataBound(Object sender, DataGridItemEventArgs e)
at System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem, DataGridColumn[] columns, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.BindGrid(String packageType, DataGrid grid, Label noResultsLabel)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.extensionTypeRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
at System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource)
at System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e)
at DotNetNuke.Modules.Admin.Extensions.InstalledExtensions.BindPackageTypes()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

The DNN forums contain bug reports for this error message since at least 2008 (!), but most often the entries contain no solution on how to proceed. Or at least, on how to find the offending module, skin, control, whatever that causes the CanDeletePackage() function to fail.

You’d expect that during the last 4 years, somebody would have bothered to at least log the item that’s causing the error, or fix CanDeletePackage() to handle a NULL parameter. But no.

The only useful hint I found was on this self-answered question,

2 rows in the packages table were invalid- they were pointing at packages that no longer existed.  I think maybe i renamed or deleted these skins on the file system- guess i should not do that

So I had a look at the Packages table in the DNN database, and indeed it contained a record for a skin container that I did not declare. Probably that was caused by an empty

<components></components>

section in the .dnn file? I have no idea.

I deleted the record, and was able to load the Host/Extensions page again. I uploaded and updated the previously installed skin package, and things still worked. The erroneous record did not show up again.

## Struggling with SSRS 2008 Error rsAccessedDenied on Win7

February 15, 2013

After successfully deploying a RDL report definition to SSRS 2008 running on Win7, I tried to browse the Report Server web under http://localhost/ReportServer but was greeted by the error message

Die dem Benutzer ‘machine\username’ erteilten Berechtigungen reichen zum Ausführen des Vorgangs nicht aus. (rsAccessDenied)

The permissions granted to user ‘machine\username’ are insufficient for performing this operation. (rsAccessDenied)

Navigating to the Report Manager under http://localhost/Reports/Pages/Folder.aspx gave me the message

Der Benutzer ‘machine\username’ verfügt nicht über die erforderlichen Berechtigungen. Stellen Sie sicher, dass ausreichende Berechtigungen erteilt und die Einschränkungen der Windows-Benutzerkontensteuerung (UAC) behandelt wurden.

User ‘machine\username’ does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed.

Of course, the suggested Online “help” had not only no useful information, but really contained *nothing*at*all*.

I found this blog on rcAccessedDenied but at first could not really figure out what it meant. Especially since the described workaround (run browser as administrator, also mentioned by an illustrated DBA tip) did not work for me. At least, I figured out that I needed a “real” administrator account to proceed.

So I started Control Panel, Computer Administration, Local Users and Groups and double-click the Administrator account. I activated the account and set a password.

After this, I managed to log in to the Report Server web using the Administrator’s credentials. There I could assign roles to my usual Windows user, but the user was still unable to connect to both sites.

Using the Administrator login I could at least grant rights to browse the data sources folder under http://localhost/Reports/Pages/Folder.aspx?ItemPath=%2fData+Sources&ViewMode=List and the deployed reports under http://localhost/Reports/Pages/Folder.aspx?ItemPath=%2f[SolutionName]&ViewMode=List.

By the way, I tried running the browser as administrator on another computer (SQL Server 2012, SSRS, Win7) and was immediately able to browse the Reports/Pages/Folder.aspx. I really have no idea what’s going on here

## Limitations of the T-SQL PRINT Command

October 21, 2012

One of the main functions of dbscript is to allow the user to select a set of tables and columns. This selection is used to generate T-SQL code (either a set of statements or the definition of a stored procedure) which can then be executed on a live database to generate INSERT/UPDATE statements reproducing the values of the selected tables and columns. An earlier post illustrated this functionality.

While this works in principle (at least for MS SQL Server), there are restrictions in the T-SQL command that make live harder than necessary if you want to script long text or binary values (NVARCHAR(MAX), VARBINARY(MAX):

During research I found a couple of work-arounds for the 4000/8000 byte limit:

• stored procedure LongPrint on ask.sqlservercentral
• stored procedure LongPrint on Adam Anderson’s blog

Both procedures try to find a line break in the string to be output, split the string at the line breaks and prints the substrings accordingly. However, from looking at the code, the procedures only work correctly if there is a line break found within 4000 characters, which is a problem if

• you have a list of column values without line breaks (in case of dbscript: INSERT and UPDATE values)
• you want to output binary values whose hexadecimal representation is longer than 4000 characters

With all these restrictions in place, I considered some other solutions:

The sp_executesql solution is necessary because scripts should be generated without any requirements in the target databases. The idea is to encapsulate a version of LongPrint in a TSQL variable, and invoke this code using sp_executesql and passing the string to be output.

Preparing this blog I came to the solution that the current implementation is good enough for most cases. In cases where output length exceeds certain limits, or for databases that enforce similar limits or do not support outputting text at all, a generic C# implementation in the dbscript backend may be the best solution.

To be continued…

## List Invalid Guids of Referenced Projects in VS Solution Dependency Visualizer 0.92

October 19, 2012

While preparing one of my projects for production, I came across a “funny” error:

While Visual Studio builds a solution without errors, msbuild raised the following error for an ASP.Net web application:

The type or namespace name ‘foo.bar’ does not exist in the namespace ‘foo’ (are you missing an assembly reference?)

I checked in Solution Explorer, and the project reference was clearly there, the assembly showed the namespace in ILSpy, and VS built the solution.

A little panicky, I removed the project reference and added it again. msbuild was now able to build the web application, but the build process raised solution file warnings:

c:\path\to\solution.sln : Solution file warning MSB4051: Project {Some-GUID-0001} is referencing a project with GUID {Other-GUID-0002}, but a project with this GUID was not found in the .SLN file.

Notice that the error message does NOT inform us while project contains the reference, and which other project was meant to be referenced, even though VS has all the necessary information to display the projects.

So I started another instance of VS, opened the VSSlnDep project, and added a new function, “List Invalid Guids of Project References”.

This function iterates through the project references of each project file (*.csproj, *.vbproj), and checks whether the referenced Guid is the project Guid of any project in the solution. If not, the reference is displayed using the referring and the referred project file names, along with both Guids.

To solve the invalid Guids, you need to navigate to the referring project in Solution Explorer, delete the project reference and add it again.

Conclusion 1: Visual Studio seems to resolve references using the project file name, whereas msbuild resolves using the project Guids.

Conclusion 2: Nobody knows why VS changes project Guids. Not even Microsoft.

As usual, the latest release of VS Solution Dependency Viewer is available for download here.

## Getting Started with the DotNetOpenAuth Sample Solution

August 2, 2012

For a new project, I downloaded the DotNetOpenAuth library, which is currently available in version 4.1.0.12182.

However, opening the Samples solution raises a series of Visual Studio errors:

The Web project ‘OpenIdProviderMvc’ requires missing web components in order to load.
Would you like to download and install them using the Web Platform Installer now?

The Web project ‘OpenIdProviderMvc’ requires missing web components in order to load.
Would you like to download and install them using the Web Platform Installer now?

Of course the dialog does not state which “web components” are missing!

Clicking on ‘No’, the projects simply do not load.

Clicking on ‘Yes’, the IE opens Web Plattform Installer website, but there is still no indication what will eventually be downloaded. (Well, if your URL bar is long enough, you might notice the “?appid=IISExpress” at the end of the URL).

Since my W7 installation already has IIS 7 installed, why should I bother with IISExpress?

A bug report on Connect indicates that the web projects might explicitly rely on IISExpress. Let’s have a look at the OpenIdRelyingPartyMvc.csproj file (right-click on the project that does not load, and select “Edit”)

Indeed, we find references to IISExpress in the first <PropertyGroup>:

<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />

Remove them or comment them using the XML <!–  –> comment syntax.

The next PropertyGroup contains the line

<UseIISExpress>true</UseIISExpress>

which needs to be removed. Finally, VS will balk at the IIS Url containing a port declaration:

<IISUrl>http://localhost:54347/</IISUrl>

Remove this as well, you can set the IIS URL from the project’s property page.

You can now reload the project, build, and run it.

## Fixing jQuery Validation with changing validators

July 18, 2012

Got jQuery Validation running, and now I know that it requires every input and select to have a name property; otherwise it will simply ignore your validation rules:

jquery.validate.js line 130:
staticRules[element.name] = existingRules;

It will however still apply the CSS-based rules, so finding that out was a bit tricky.

Next stop: I create a dialog with a dropdown to select some sort of object type, each object type having different attributes and different validation rules.

Of course, the validation rules have to be re-defined every time the dropdown value changes. If there is already a validator defined on the form, you need to destroy the existing validator

var form = $('#myForm).get(0);$.removeData(form, 'validator');

(found here)

Still, some mysterious bit of code still remains, as validation is still executed even though the validator had been deleted and the dropdown is ignored in the (non-existing?) validator:

Uncaught TypeError: Cannot read property 'settings' of undefined
jquery.validate.js:315

says Chrome, and IE reports

Unable to get value of the property 'settings': object is null or undefined

The culprit is the method delegate() (line 313), which does not check whether a validator exists:

function delegate(event) {
var validator = \$.data(this[0].form, "validator"),
eventType = "on" + event.type.replace(/^validate/, "");
// this fixes handling the deleted validator:
if (!validator) return;
validator.settings[eventType] && validator.settings[eventType].call(validator, this[0], event);
}