Monday, June 01, 2009

Some funnies with BizTalk property schemas

I haven't blogged for a couple of weeks, and I have been doing loads of interesting stuff recently, but so little time to blog about it.

So, just as a little nugget, I have been creating an ESB solution using BizTalk (mainly messaging) and I have created a property schema that I want to use for my routing in my ESB.  Because I wanted to share my property schema I put it into a separate assembly.  Let's say it's default namespace and assembly name is of this form:


Let's say that I have a single property in the property schema (out of pure laziness because I'm replaying this in a sample app) - and called it Property1.  I signed built and then built the assembly.  So far so good. If I want to use the property it will be MyCompany.MyApplication.Integration.Schemas.Routing.Property1.

I then created another schema assembly and started to add schemas to it.  Again, let's say that the default namespace of the assembly is in this form:


I added a schema to the file with a couple of fields under the root element.  I signed and built it.  So far so good.

I then referenced my property schema assembly and promoted some fields by referencing the property schema from the referenced assembly.  Again, so far so good, it all builds.

I then decided that I wanted the namespace of the property so that it is shorter (as it is to be shared).  Let's say that I want it to be MyApplication.Property1.  In order to achieve this Iclick on the property schema file, view the properties and then change the namespace to MyApplication.  I then try to build the project and - BANG - I get the following error:

Error 1 The type or namespace name 'Routing' does not exist in the namespace 'MyCompany.MyApplication.Integration.Schemas' (are you missing an assembly reference?) C:\_projects\Solutions\Integration.Schemas.Routing\Integration.Schemas\Schema1.xsd.cs 43 68 Integration.Schemas

This may not be too unexpected because I didn't change the reference of the property schema in my schema, so I thought I'd remove the reference for the property schema and re-add it.  When I add the property schema everything seems to be OK, but I still get the same error!  Even though the property schema builds OK and the property schema can be added to the schema OK, but when it builds it fails.  

Ho-ho I thought.  What's going on here?  I then tried changing the default namespace in the assembly to be the same as the namespace for my file.  Same error.  I then tried changing the default and file namespaces to be something completely different (Badgers) and then it builds!

After some chasing up, it appears that there is a known issue with BizTalk references that means you can't include part of a namespace inside a reference because it can't resolve the namespace.  You either have to keep the original namespace which is fully qualified from the root namespace as per your naming conventions, or you have to choose something that will not clash at all.  You can't abbreviate with just part of the namespace.  That's just the way it is.  If you're reading this and it's saved you from tearing out some of your hair then let me know :)

1 comment:

Priyadarshini said...

Can a schema have more than 1 property schema?