Is it possible to use both Microsoft.Graph and Microsoft.Graph.Beta in the same app?

1.7k Views Asked by At

I'm writing some C# code targeting .NET 4.8, which needs to use Microsoft Graph. It works OK with Microsoft.Graph SDK (V1), however when I try to switch to Beta, I'm getting compilation errors like

Error CS0433    The type 'GraphServiceClient' exists in both 'Microsoft.Graph.Beta, Version=0.29.0.0 <...>' and 'Microsoft.Graph, Version=1.19.0.0 <...>'

The reason being that one other nuget I'm using, namely SharePointPnPCoreOnline, unfortunately depends on Microsoft.Graph 1.19.

It would seem that there should be no problem using both assemblies, as - according to the current documentation (https://learn.microsoft.com/en-us/graph/sdks/use-beta) - Beta should use its own namespace:

using Microsoft.Graph.Beta;

Unfortunately it is wrong, both libraries share the same namespace Microsoft.Graph. The code above results in

Error CS0234    The type or namespace name 'Beta' does not exist in the namespace 'Microsoft.Graph' (are you missing an assembly reference?)

I'm trying to use compiler options to resolve the assembly, but it's extremely convoluted under VS2019 - so far no luck.

But I'm wondering why can't I find anything on this issue, I'm surely not the only one - can it be that I miss something obvious? Please help :)

1

There are 1 best solutions below

3
On

Not sure if you solved this, but I solved this by adding an alias to Microsoft.Graph.Beta package. Then when referencing, add this to be able to reference your beta-endpoints or resources. Change MSGraphBeta to whatever you added as an alias to your package.

extern alias MSGraphBeta;
using GraphBeta = MSGraphBeta.Microsoft.Graph;