Roland Oldengarm - Independent IT Contractor

Living in the coolest little capital Wellington, New Zealand!

Error deploying BDC feature

When deploying e.g. an external content type through a feature, everything could look fine on your development machine. However, when installing on another server, you could run into the following error:

Error occurred in deployment step ‘Add Solution’: The default web application could not be determined. Set the SiteUrl property in feature “your feature Name” to the URL of the desired site and retry activation.

Parameter name: properties

An option is to provide the SiteUrl feature property, but that is not an option in a multifarm environment.

The problem is that SharePoint tries to find a default web application when SiteUrl is not provided by looking at web applications at port 80 and comparing the number of dots or the presence of www in the URL… Really.
Some solutions found on Google replace the default feature receiver with a new version, where the code of the default receiver is provided (decompiled) and solving the error. E.g.

I don’t like doing that. A much better solution is creating a derived class:

public class EventReceiver : ImportModelReceiver
 /// <summary>
 /// Feature is activated
 /// </summary>
 /// <param name="properties">The properties.</param>
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 SPFarm farm = SPFarm.Local;
 SPSolution solution = farm.Solutions[properties.Definition.SolutionId];
 var webApplication = solution.DeployedWebApplications[0];
 var url = webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri;
if (properties.Definition.Properties["SiteUrl"] == null)
 properties.Definition.Properties.Add(new SPFeatureProperty("SiteUrl", url));
 properties.Definition.Properties["SiteUrl"].Value = url;

I decided to take the URL where the WSP is deployed to. If it is a globally deployed WSP, you could try e.g. the first web application, or something else.

Don’t forget to remove the feature receiver from your Module, by going to properties of your Module and clearing the Feature Receiver property (right click and choose properties).

1 Comment

  1. Hey, I saw u mentioned my blog post. Cool :). I must admit I have been using this solution in several big projects and they work like a charm. But I do understand your point in deriving from it instead of creating a new one… It might be better, tho my solution will do what you want aswell. Cool post man 🙂

Leave a Reply

Your email address will not be published.