Поделиться через


Deploy a BDC Model project to SharePoint Foundation 2010 using Visual Studio 2010

Business Connectivity Services (BCS), one of the key components of SharePoint 2010, helps you to access external line-of-business (LOB) data. The SharePoint team posted a blog entry which demonstrates how to create your first BDC (Business Data Connectivity) model using Visual Studio 2010. As indicated in the post, you can use Visual Studio 2010 to deploy your BDC model to Microsoft SharePoint Server 2010.

However, if you are using Microsoft SharePoint Foundation 2010 on yourdevelop machine, or you want to make the model deployable to Microsoft SharePoint Foundation 2010 on other machines , you will need to write a Feature Event Receiver to enable the deployment of BDC models from within Visual Studio 2010. In this blog post, I’ll show you how to create a Feature Event Receiver to do so.

Here are the detailed steps:

  1. In Visual Studio 2010, create a BDC project (read this post to learn how) or open your existing BDC project (e.g. “BdcModelProject1” ) .

  2. Add Feature Event Receiver to BDC project. In Solution Explorer, add a new Feature Event Receiver by right clicking on the feature (Feature1 in this sample) under Features folder and selecting Add Event Receiver.

  3. Write code for the Feature Event Receiver. In the generated code file (the default name is Feature1EventReceiver.cs/vb), replace the code with the sample code (Download here).

  4. Add reference.

    1. Copy Microsoft.BusinessData.dll assembly out of GAC. To do so: Start->Run, type in C:\Windows\assembly\gac_msil. Find Microsoft.BusinessData folder, and then copy Microsoft.BusinessData.dll to folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.
    2. Add the following two assembly references to your project:
      1. In .Net tab, select Component Name = System.Web, Version=2.0.0.0.
      2. In Browse tab, navigate to folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI, and then add Microsoft.SharePoint.dll and Microsoft.BusinessData.dll.
  5. Set BDC SPI (SharePoint item) property. In Solution Explorer, select the SPI folder (e.g. “BdcModel1”), open Properties Window and update the following two Feature Receiver properties:

    C# Project -
    - Assembly = $SharePoint.Project.AssemblyFullName$
    - Class Name = BDCModelReceiver.Features.Feature1.ImportModelReceiver

    VB Project –
    - Assembly = $SharePoint.Project.AssemblyFullName$
    - *Class Name = BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver
    * Replace “BdcModelProject1” with your own project name

  6. Set Feature property. In Solution Explorer, expand Features\Feature1 folder, double click on Feature1.Feature and open Properties window and update the following Feature property:

    C# Project -
    - Receiver Class = BDCModelReceiver.Features.Feature1.ImportModelReceiver

    VB Project -
    - *Receiver Class = BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver
    * Replace “BdcModelProject1” with your own project name

  7. Now you can deploy the BDC project (Project->Deploy) or debug the BDC project (F5) to SharePoint Foundation 2010. You will find the external content type being deployed to the metadata store.

For more information about Business Connectivity Services, please also check out BCS Team blog.

Rong Lu

Comments

  • Anonymous
    April 26, 2010
    Why the Feature Event Receiver is required for BDC feature deployment on SharePoint Foundation?

  • Anonymous
    May 02, 2010
    After following instructions for setting up SharePoint 2010 on Windows 7, following the first BDC Project instructions and following this blog about Fearure Event Receiver, I get 500 - Internal Server Error at the "Adding Solution" step of deployment process. Any suggestions?

  • Anonymous
    May 03, 2010
    Hi, You should try adding the EnableDiagnostics registry key (http://blogs.msdn.com/vssharepointtoolsblog/archive/2010/01/07/how-to-get-more-information-about-the-exceptions-that-can-happen-in-sharepoint-2010-projects.aspx) and in case you get any errors during deployment you will see the actual exception which makes it easier to troubleshoot. Peter

  • Anonymous
    May 04, 2010
    Hi James, To answer your question: BDC deployment relies on feature event receiver to take care of actions like model import/feature activation. Unfortunately the assembly where the feature event receiver lives does not ship with  SharePoint Foundation. And the reason for that is same assembly has other functionalities that we decided not to ship in Foundation and we couldn’t find a cost-effective way to support the receiver in Foundation. Hope this helps. Rong Lu Program Manager, Visual Studio team

  • Anonymous
    September 09, 2010
    Hi!.. i've tried your solution but when i try to deploy it it gives me Error occurred in deployment step 'Add Solution': Failed to create receiver object from assembly "BdcModelProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6f4926deb40cae08", class "BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver " for feature "BdcModelProject1_Feature1" (ID: a8a480c6-f1f0-4a5a-a37c-2259a0118919).: System.ArgumentNullException: Value cannot be null. Parameter name: type   at System.Activator.CreateInstance(Type type, Boolean nonPublic)   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() Do you have any clue?

  • Anonymous
    September 12, 2010
    Hi nego.tk, From the error it looks like SharePoint failed to instantiate your receiver class. There is a possibility this happens because the feature receiver assembly/class settings do not match the receiver class name which is defined in Feature.EventReceiver.cs/vb file. Can you please check the property settings in step5 and 6, and make sure the receiver assembly and class properties in both places match the feature event receiver name exactly in code file? Please note that the settings in vb project is slightly different than C# project. Please let us know how this works out. If you still see the error, can you send your project to me (ronglu at microsoft.com) so we can help identify the problem? Best regards, Rong Lu Program Manager, Visual Studio team

  • Anonymous
    September 13, 2010
    Excellent - just what I wanted to learn. Following the first BDC Project instructions and following the blog entry about Fearure Event Receiver, I get 500 - Internal Server Error at the "Adding Solution" step of deployment process (in your video, when you press F5). I use Windows 7 Any suggestions?

  • Anonymous
    September 14, 2010
    Hi MSSAP, Can you check if your SharePoint site can be accessed directly without using VS? i.e. open internet browser and type in your local SharePoint site address directly. I'm guessing you're seeing the error because VS is unable to communicate to your SharePoint server when F5. Let me know what you find out. If the SharePoint site is fine and you still see the error, I can't think of other possibilities at this moment, but if you can send me (ronglu at microsoft.com) your project, we should be able to help identify. Best regards, Rong Lu Program Manager, Visual Studio team

  • Anonymous
    October 07, 2010
    Hi! I'm having a similar problem to nego.tk where I receive the following error message: Error occurred in deployment step 'Add Solution': Failed to create receiver object from assembly "BdcModelProject1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6f4926deb40cae08", class "BdcModelProject1.BDCModelReceiver.Features.Feature1.ImportModelReceiver " for feature "BdcModelProject1_Feature1" (ID: a8a480c6-f1f0-4a5a-a37c-2259a0118919).: System.ArgumentNullException: Value cannot be null. Parameter name: type  at System.Activator.CreateInstance(Type type, Boolean nonPublic)  at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() I also find it strange that I've upgraded my development environment from Sharepoint Foundation to Sharepoint Server Standard and I still have to manually develop this feature event receiver.  I thought I shouldn't have to do so for Sharepoint Server? Please Help! Thanks, KBW

  • Anonymous
    October 10, 2010
    Hi KB Weeks, You should be able to deloy BDC model to SharePoint Server from within VS without having to manually add feature event receiver. It's strange you can't do so. What's the error message you see? I got your email that has your project and I'll try to get back to you as soon as possible. Sorry I'm caught in various things right now. Thanks for your patience. Best regards, Rong Lu Program Manager, Visual Studio team

  • Anonymous
    October 16, 2010
    The comment has been removed

  • Anonymous
    January 21, 2011
    Hi After following your instructions I get the following errors Error 1 Error occurred in deployment step 'Add Solution': Failed to load receiver assembly " BdcModelProject2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=359091437b6defd0" for feature "BdcModelProject2_Feature1" (ID: ed9d4d9b-bfe9-4778-8a8f-d24381fffa83).: System.IO.FileNotFoundException: Could not load file or assembly 'BdcModelProject2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=359091437b6defd0' or one of its dependencies. The system cannot find the file specified. File name: 'BdcModelProject2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=359091437b6defd0'   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)   at System.Reflection.Assembly.Load(String assemblyString)   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLMSoftwareMicrosoftFusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLMSoftwareMicrosoftFusion!EnableLog]. 0 0 BdcModelProject2 Any help would be appreciated

  • Anonymous
    January 25, 2012
    Perfect! I had a problem with DLL and followind this steps it was fixed!

  • Anonymous
    April 12, 2012
    I've got the same error as Tiklu Ganguly Please help.   Error 3 Error occurred in deployment step 'Add Solution': Failed to load receiver assembly "BCSFileConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=584c9b9842ffd739" for feature "BCSFileConnector_Feature1" (ID: c5a860c0-78d5-4a90-a237-d8a9143c890d).: System.IO.FileNotFoundException: Could not load file or assembly 'BCSFileConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=584c9b9842ffd739' or one of its dependencies. The system cannot find the file specified. File name: 'BCSFileConnector, Version=1.0.0.0, Culture=neutral, PublicKeyToken=584c9b9842ffd739'   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)   at System.Reflection.Assembly.Load(String assemblyString)   at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject() WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLMSoftwareMicrosoftFusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLMSoftwareMicrosoftFusion!EnableLog].

  • Anonymous
    May 10, 2012
    Nice! If you need to move the feature to several environments you can get the URL for the Web Application by using SPWebService:            SPWebService webService = properties.Feature.Parent as SPWebService;            SPWebApplication webApp = webService.WebApplications["SharePoint 80"];            properties.Definition.Properties["SiteUrl"].Value = site.Url;

  • Anonymous
    August 12, 2012
    i m getting this error i follow all instruction but getting error Error 1 The Feature "Feature1" has conflicting event receiver settings from the following items: BdcModel1, Feature1. D:BdcModelProject1FeaturesFeature1Feature1.feature BdcModelProject1

  • Anonymous
    December 19, 2012
    Hi Rong Lu, Really a great time saver and is there any other work around. Really appreciate for your effort and time...

  • Anonymous
    February 07, 2013
    The comment has been removed

  • Anonymous
    March 07, 2014
    Hi Rong Lu,I followed all the steps you mentioned in your blog and deployed the solution. My deployment was successful. But I am not able to see this in the metadata store. Can you please help? Thanks in advance.

  • Anonymous
    September 03, 2014
    Hi The link does not work. CAn anyone leave the Feature1EventReceiver.cs again? thanks

  • Anonymous
    December 18, 2015
    Hi, the link (Download here) not function