Filter on Guid for AppRoleAssignedTo.PrincipalId does not seem to work as expected

Charles Laymon 25 Reputation points
2024-01-29T10:42:53.76+00:00

See: https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2306

Describe the bugUsing C# SDK nuget package Microsoft.Graph 5.40.0. Any time we try to create a filter like


var userId = "<GUID VALUE>";
 if(!Guid.TryParse(userId, out var userGuid))
 { 
     return false; 
 }

var appRoleAssignments = await graphClient.ServicePrincipals[ObjectId]
                     .AppRoleAssignedTo
                     .GetAsync(cfg => {
                         cfg.QueryParameters.Filter = $"principalId eq '{userGuid}'";
                         cfg.QueryParameters.Count = true;
                         cfg.Headers.Add("ConsistencyLevel", "eventual");
                     }, cancellationToken: cancellationToken)
                     .ConfigureAwait(false);
It returns the error:
Invalid filter clause: A binary operator with incompatible types was detected. Found operand types 'Edm.Guid' and 'Edm.String' for operator kind 'Equal'.

We looked at the PrincipalId and it looks to be a Guid type. So, we removed the single quotes from the filter around the userGuid value and we get the following error:
Links to EntitlementGrant are not supported between specified entities.

Are we missing some kind of grant of permissions? Our App Registration currently has Directory.Read.All that has admin consent turned on. Are we missing something?

Any guidance or links to docs for this would be greatly helpful.

Thanks!

To Reproduce
Steps to reproduce the behavior:
Use the sample code above and see if this fails for you.

Expected behavior
The code above to work with no error.

Desktop (please complete the following information):

OS: Windows 11 lates patches
Browser Edge
Version Version 120.0.2210.144 (Official build) (64-bit)
Additional context
Microsoft Visual Studio Enterprise 2022
Version 17.9.0 Preview 2.1
VisualStudio.17.Preview/17.9.0-pre.3.0+34511.98
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Enterprise

Visual C++ 2022 00476-80000-00000-AA741
Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.9.153.1332
ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.9.153.1332
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.9.153.1332
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.9.0-2.23613.5+47b0a1e0ab831076eda00bb1e24b9d042d256e17
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Entity Framework Core Power Tools 2.6
Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu.

Extensibility Message Bus 1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.9.0 (b3bca6f)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.9.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core) 17.9.2.2357901+dfac5e3cec112dd38af95d899f85347f2e64411a
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.9.39.0
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0
Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor 1.0
Hosting json editor into a tool window

TypeScript Tools 17.0.21025.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.9.0-2.23613.5+47b0a1e0ab831076eda00bb1e24b9d042d256e17
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.8.0-beta.23570.1+e9491ad27f8c9399cdd68e2308e906851a6db84f
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0
Information about my package

VisualStudio.Mac 1.0
Mac Extension for Visual Studio

VSPackage Extension 1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin 17.9.0.62 (main@1a123c3)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.9.2.9 (remotes/origin/d17-9@dba677e96e)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.9.0 (38e87ba)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: d9a6e87
Java.Interop: xamarin/java.interop@149d70fe
SQLite: xamarin/sqlite@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools@ca1552d

Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,248 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,571 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vasil Michev 99,126 Reputation points MVP
    2024-01-29T17:59:52.2933333+00:00

    Afaik $filter is not supported for this query. In fact, only a handful of relationships for service principal objects support $filter, as detailed for example here: https://learn.microsoft.com/en-us/graph/api/resources/serviceprincipal?view=graph-rest-beta#relationships For your scenario, get the full set of results, then filter them client-side.