1

I'm trying to work with Microsoft's Graph API at my company, and I'm following the online documentation to get this done. I'm working in VB .NET and I am importing the Microsoft.Graph.Auth package as it says, and when I build the code, I get the error above. Please see screenshot below too.

I'm unable to find a solution for this online. I cannot tell if it's something to do with the fact that it's a preview package? It's strange since this is what Microsoft instructs us to do...

Imports Microsoft.Identity.Client
Imports Microsoft.Graph
Imports Microsoft.Graph.Auth

Public Class Graph
    Private clientId As String = System.Configuration.ConfigurationManager.AppSettings("GraphClientId")
    Private redirectUri As String = System.Configuration.ConfigurationManager.AppSettings("RedirectUri")
    Shared tenantID As String = System.Configuration.ConfigurationManager.AppSettings("GraphTenant")
    Private clientSecret As String = System.Configuration.ConfigurationManager.AppSettings("GraphSecret")
    Public authProvider As ClientCredentialProvider = Nothing
    Public Sub Initialize()
        Dim confidentialClientApplication As IConfidentialClientApplication = ConfidentialClientApplicationBuilder.Create(clientId).WithTenantId(tenantID).WithClientSecret(clientSecret).Build()
        authProvider = New ClientCredentialProvider(confidentialClientApplication)
    End Sub

    Public Sub GetAllUserTasks()
        Initialize()
        Dim graphClient As New GraphServiceClient(authProvider)
        Dim tasks = graphClient.[Me].Planner.Tasks.Request().GetAsync()
        Debug.Print(tasks.Result.Item(0).Title)
    End Sub
End Class

Would greatly appreciate the help!

enter image description here

shmob
  • 198
  • 2
  • 17
  • Rather than updating the project-based NuGet.exe in the .nuget dir, this SO answer can help remove it to use Visual Studio's built-in package restore functionality instead: https://stackoverflow.com/questions/8713616/remove-nuget-package-restore-from-solution – pete May 01 '20 at 13:30

1 Answers1

6

What version of nuget.exe are you using? You can get the version number by executing . C:\cps2\.nuget\NuGet.exe in a console window.

If the version number is lower than 4.3.0, then download the latest version from https://www.nuget.org/downloads, and replace the current C:\cps2\.nuget\NuGet.exe with the new one. This is because Microsoft.Graph.Auth uses SemVer v2.0.0 which is not compatible with NuGet clients older than 4.3.0. This is documented here https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#semantic-versioning-200.

Peter Ombwa
  • 211
  • 1
  • 3
  • Thanks so much, I did not realize that I had to replace the .exe file manually. I tried this, and now get errors for every nuget package I have ever installed. For each one, it says `could not find a part of the path C:/cps2/ /packages/{package_name}`. I'm not sure what this means, and could not find much help online. – shmob Nov 11 '19 at 19:14
  • Nuget can update itself given the right command line arguments. – Andy Nov 11 '19 at 19:14
  • what might this "right command" be? just tried `Install-Package NuGet.Client -Version 4.2.0` and it didn't update that .exe file in `cps2/.nuget` – shmob Nov 11 '19 at 19:19
  • I also tried `Install-Package NuGet.Client -Version 4.3.0-beta1-2418` - also did not update the `.exe` and still got errors for Microsoft.Graph.Auth – shmob Nov 11 '19 at 19:27
  • I am in the same boat now. I updated all my NuGet packages using Visual Studio Package Manager and updated nuget.exe too. However now every single project fails to build with the same error! – Nikhil Dec 04 '19 at 07:59