6

I want to get data from SharePoint list by CSOM library on .Net Core MVC application. There are absolutely no problem to achieve that on .Net Framework aplication because Microsoft.SharePoint.Client library contains ExecuteQuery method. Unfortunately .Net Core equivalent not.

I've made Async function

public async Task<ActionResult> GetRequests()
    {
        ClientContext context = new ClientContext("https://xxx/sites/xxx/");
        List certificatesList = context.Web.Lists.GetByTitle("Items");
        CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
        ListItemCollection items = certificatesList.GetItems(query);
        context.Load(items);
        Task spTask = context.ExecuteQueryAsync();
        await Task.WhenAll(spTask);
        var result = items;
        ...

    }

but it seems like it also won't work on .Net Core because it throws

Exception thrown: 'System.InvalidOperationException' in >System.Private.CoreLib.ni.dll

Additional information: Cannot find platform service library. For Windows Store application, please include Microsoft.SharePoint.Client.Runtime.WindowsStore.dll in the application package. For Windows Phone application, please include Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll in the application package. For Windows application, please install Microsoft.SharePoint.Client.Runtime.Windows.dll in the GAC (Global Assembly Cache) or make it available for the Windows application.

Does someone use CSOM in .Net Core or should I use REST Api instead?

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }
3
  • I would be more then surprised if it would support it .NET Standard at all. Did you do some.... "funky" stuff in your project.json like playing/abusing the imports section? Or including the Microsoft.SharePoint.Client.Runtime.WindowsStore.dll (if it targets portable-net451+win81? Make post your project.json or .csproj if you are on VS2017 Commented Feb 12, 2017 at 11:47
  • I've attached project.json "Imports" node. The problem is that Microsoft.SharePoint.Client reference is quite different on .Net Core application than on .Net Framework application. All dll's are similar but contain "Portable" in name so i don't have Microsoft.SharePoint.Client.Runtime.dll but Microsoft.SharePoint.Client.Runtime.Portable.dll Commented Feb 12, 2017 at 12:08
  • And adding Microsoft.SharePoint.Client.Runtime.WindowsStore doesn't help? It's not on nuget, at least no official package, so I can't see the exact targets it supports. But if Microsoft.SharePoint.Client.Runtime.WindowsStore doesn't use any WindowsPhone specific apis (and only targets portable-net451+81 profile, it should still work). portable-net451-win81 is a profile for Portable Class libraries which run on desktop and windows mobile/uwp Commented Feb 12, 2017 at 12:13

1 Answer 1

0

I had this issue. For some reason when you reference the Microsoft.SharePointOnline.CSOM nuget package it used the .net framework dlls rather than the netcore45 dlls. Here's what I did to work around this:

  1. Download the nuget package https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
  2. Extract it to a subfolder in your project eg; Dependencies
  3. Reference the correct assemblies

    netcore45\Microsoft.SharePoint.Client.Portable.dll netcore45\Microsoft.SharePoint.Client.Runtime.Portable.dll net45\Microsoft.SharePoint.Client.Runtime.Windows.dll netcore45\Microsoft.SharePoint.Client.Runtime.WindowsStore.dll

Oh and if you already have that nuget package do an uninstall-package on it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.