SharePoint 2010 BCS model deploy errors

Today I again faced an annoying SharePoint BCS deployment bug. I encountered it before in the beta but figured it would be solved in the release version so I forgot about it. Today it bit me in the rear again.

What's the issue?

As soon as you deploy a BCS solution from VS2010 and changed the model to much from the previous version you deployed, you get all sorts of errors. If you look closely to them, you'll notice they are caused by SharePoint trying to compile previous versions. If you however retract your solution and view Central Admin there are no models defined at all! Somehow these previous versions are stored somewhere we can't view or delete them!

The solution

Sometimes the solution can be very simple. Don't trust the UI, don't trust VS2010 but try the Object Model. After I ran the following code I could find a lot of left over models and entities.

 

using(var site = new SPSite("http://siteurl")){
    var parentFarm = site.WebApplication.Farm;
    var businessDataServices = parentFarm.Services.GetValue();

    var context = SPServiceContext.GetContext(site);
    var catalog = businessDataServices.GetAdministrationMetadataCatalog(context);

    Console.WriteLine("Models:");
    var models = catalog.GetModels("*");
    foreach (var model in models) {
        Console.WriteLine("\t{0}", model.DefaultDisplayName);
    }

    Console.WriteLine("\nEntities:");
    var entities = catalog.GetEntities("*", "*", false);
    foreach (var entity in entities) {
        Console.WriteLine("\t{0}", entity.DefaultDisplayName);
    }               
}
            
Console.ReadLine();

After verrifying all models and entities were indeed left overs I adjusted the code a little bit to delete them.

 

using(var site = new SPSite("http://siteurl")){
    var parentFarm = site.WebApplication.Farm;
    var businessDataServices = parentFarm.Services.GetValue();

    var context = SPServiceContext.GetContext(site);
    var catalog = businessDataServices.GetAdministrationMetadataCatalog(context);

    Console.WriteLine("Models:");
    var models = catalog.GetModels("*");
    foreach (var model in models) {
        Console.WriteLine("\t{0}", model.DefaultDisplayName);
        model.Delete();
    }

    Console.WriteLine("\nEntities:");
    var entities = catalog.GetEntities("*", "*", false);
    foreach (var entity in entities) {
        Console.WriteLine("\t{0}", entity.DefaultDisplayName);
        entity.Delete();
    }               
}
            
Console.ReadLine();

After running the code I could deploy my solution again and all worked fine!

Cheers,

Wes

No Comments