Web publishing warning: "No element in the source document matches '/configuration/hibernate-configuration'"
I created web.config transform that changes NHibernate configuration for Windows Azure projects. When building publishing package I get the following warning: "No element in the source document matches '/configuration/hibernate-configuration'" and transformed configuration doesn’t contain expected changes. In this posting I will show you how to solve this problem.
Problem
Here is NHibernate config from my original web.config file:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">CONNSTR</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
And here is the transform that should replace connection string:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property
xdt:Transform="Replace"
xdt:Locator="Match(name)"
name="connection.connection_string">
CONNSTR
</property>
</session-factory>
</hibernate-configuration>
Warning is shown here:
Web.Cloud Debug.config(7,4): warning : No element in the source document matches '/configuration/hibernate-configuration'
Transformed Web.config using Web.Cloud Debug.config into obj\Cloud Debug\TransformWebConfig\transformed\Web.config.
Seems like transformer gets into trouble.
Solution
Solution is simple: we have to remove namespace from NHibernate configuration in web.config file like shown here:
<hibernate-configuration>
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">CONNSTR</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Now the transform will be applied correctly and publishing package contains connection string given in web.config transform that is applied.