0

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

  • Calling from C++ returns hr == ERROR_FILE_NOT_FOUND.
  • Calling the same DLL function from a C# test program works successfully.

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.

4
  • It's probably a deployment issue. The Microsoft.SharePoint.Client.ClientContext misses something in the context of the C++ client to be instantiated properly. Have you called CoInitialize(Ex) in your C++ code? Otherwise use a tool such as Procmon from sysinternals filter by file access and you should see what files are missing learn.microsoft.com/en-us/sysinternals/downloads/procmon Commented Sep 8, 2023 at 16:26
  • Thanks. Procmon is getting me there - my program is looking for the SharePoint Client 16.1, to match the NuGet package, but the latest available download of the Sharepoint Online Client Components SDK is 16.0. I can't find 16.1 anywhere. Is it recommended for my install package to install the NuGet command line and package(s) on users' computers, or do I need to grab any relevant .dll files out of the package directory, and package them with my install? Commented Sep 11, 2023 at 5:40
  • Usually nugets are only for developpers. How it will all run elsewhere is entirely dependent on the nuget/technology involved. This is a pure Sharepoint client issue. Commented Sep 11, 2023 at 5:46
  • Thanks for confirming. That's what I thought, but it was odd that the Nuget package for CSOM is using a later version of Sharepoint client than is actually available. I will take the necessary DLLs from the Nuget package, and wrap them into my own install script. As for the C++ interop issue, I tried many variations, with different versions of Sharepoint clients, and older CSOM Nuget packages, and could not get anything to work. I've re-architected my software to use an independent C# program for the Sharepoint interface, and run this program in the background. All good now, thanks. Commented Sep 12, 2023 at 6:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.