SharepointListSource adapter: Got InvalidCastException when building package programmically and executing

Nov 10, 2011 at 2:49 AM

Hi guys,

I am trying to pull data from sharepoint list to oledbdestination. while I got success when manually building the package and execute, I got the following error when programmatically doing same thing. Any helps?


Error at {1F4DC6AC-00F0-419C-9AAF-06BEBD4DA735} [SharePoint List Source [1]]: System.InvalidCastException: Specified cast is not valid.

at Microsoft.Samples.SqlServer.SSIS.SharePointListAdapters.SharePointListSource.Validate()

at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostValidate(IDTSManagedComponentWrapper100 wrapper)

Error at {1F4DC6AC-00F0-419C-9AAF-06BEBD4DA735} [SSIS.Pipeline]: component "SharePoint List Source" (1) failed validation and returned error code 0x80004002.


Error at {1F4DC6AC-00F0-419C-9AAF-06BEBD4DA735} [SSIS.Pipeline]: One or more component failed validation.


Error at {1F4DC6AC-00F0-419C-9AAF-06BEBD4DA735}: There were errors during task validation.

 I am using sql server 2008 SP1 and VS 2008 SP1. Following is the corresponding code:

Package m_p = new Package();
Executable ex = m_p.Executables.Add("STOCK:PipelineTask");
MainPipe pipe = (MainPipe)(((TaskHost)ex).InnerObject);
IDTSComponentMetaData100 src = null;
ConnectionManager cm = m_p.Connections.Add("SPCRED");
cm.Name = "SharePoint Credential _" + (Guid.NewGuid().ToString());

IDTSComponentMetaData100 comp = this.MetadataCollection;
CManagedComponentWrapper dcomp = comp.Instantiate();

// Set SP custom properties
foreach (KeyValuePair<string, object> prop in spsrc.CustomProperties.CustomPropertyCollection.InnerArrayList)
    dcomp.SetComponentProperty(prop.Key, prop.Value);

/*Specify the connection manager for Src.The Connections class is a collection of the connection managers that have been added to that package and are available for use at run time*/
if (comp.RuntimeConnectionCollection.Count > 0)
    comp.RuntimeConnectionCollection[0].ConnectionManagerID = cm.ID;
    comp.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.GetExtendedInterface(cm);