I have been working with the Commerce Server 2009 RTM (Mojave) codebase. While upgrading a site from the previous Mojave CTP I came across an interesting error. It appeared the .net reflection subsystem was not able to find the constructor on my CustomOrderForm object. This had always worked in the past, so I reflected on the Commerce Server 2009 API and found the offending method in the Microsoft.Commerce.Providers.Utility.CommerceServerClassFactory object:
public static TBaseCommerceServerClass CreateInstance <TBaseCommerceServerClass>(string mojaveModelName, CommerceServerArea? commerceArea, object[] args) where TBaseCommerceServerClass: class { ParameterChecker.CheckForNullOrEmpty(mojaveModelName, "mojaveModelName"); EntityMapping mapping = CommerceEntityMetadata.Get(mojaveModelName, commerceArea) .EntityMappings.Items<EntityMapping>().Single<EntityMapping>(); Type type = Type.GetType(mapping.CommerceServerClass + ", " + mapping.CommerceServerAssembly, true); TBaseCommerceServerClass local = Activator.CreateInstance(type, args) as TBaseCommerceServerClass; if (local == null) { throw new InvalidCastException(ProviderResources.ExceptionMessages .GetMessage("InvalidClassToInstantiate", new object[] { type, typeof(TBaseCommerceServerClass) })); } return local; }
The args array contained a single “default” string member. This didn’t make sense because I knew that Commerce Server Orderform base class has no constructor which accepts a type string. After spending considerable time reviewing the code in the stack trace I thought I might have uncovered a bug. It turns out that this was implemented by design. So what this means is you now have to add a new constructor which accepts a string to all your types which inherit from Orderform. The really strange thing is that the string serves no purpose in the CustomOrderForm type.