user1961169
user1961169

Reputation: 799

COM interop returns ERROR_FILE_NOT_FOUND

I have a C++ non-managed program calling into a C# DLL using COM interop to access a sharepoint server using SharePoint CSOM.

Here is the C# function I am calling...

public class SharePointUpload : ISharePointUpload
{
    public void Testing()
    {
        MessageBox.Show("Testing4");

        using (var context = new Microsoft.SharePoint.Client.ClientContext("https://mysharepointsite.com/sites/mysite"))
        {
           MessageBox.Show("3");
        }
    }
}

... and the calling code in C++ is...

CoInitialize(NULL);
CComPtr <ISharePointUpload>     pISharePointUpload;
HRESULT hr = pISharePointUpload.CoCreateInstance(__uuidof(SharePointUpload));
if (hr == S_OK) {
    hr = pISharePointUpload->Testing();
    // returns hr == ERROR_FILE_NOT_FOUND
}
CoUninitialize();

As noted, calling Testing() returns hr == ERROR_FILE_NOT_FOUND, and none of the MessageBoxes are shown. If I remove the "using (var context..." line, then I can call the Testing() function, and I see the message boxes.

I can still call other functions in the C# DLL. I also have a C# test program that calls the same DLL, and that works fine - I can connect to the sharepoint server and upload files.

I'm thinking maybe I need to add something to my C++ application. I have used the NuGet Console to "Install-Package Microsoft.SharepointOnline.CSOM", and I can see that this has created a packages.config file in the solution with the package, but this did not help.

Upvotes: 0

Views: 69

Answers (0)

Related Questions