Skip to content

Question Using developer proxy with Microsoft Graph .NET Client Library 5.x #346

Closed

Description

@procioadmin

Hi and thank you for this super cool tool!
I am using the Microsoft Graph .NET Client Library 5.x library to download/move emails around. I want to improve my error handling with help of the m365-developer-proxy but I cannot bring it to work. My App is a console app with client credentials authentication method. For example if I poll for a mail I expect that the developer proxy intercepts but nothing happens.

Here my coding:

MessageCollectionResponse mails = await graphClient.Users[user].MailFolders[boxid].Messages.GetAsync((requestConfiguration) =>
{
    requestConfiguration.QueryParameters.Top = qty;
    requestConfiguration.QueryParameters.Orderby = new string[] { "subject", "importance", "receivedDateTime asc" };
    requestConfiguration.QueryParameters.Filter = "";
});

I thought using Microsoft Graph .NET library translates the C#-Requests to HTTP calls?! What did I miss?

Thank you very much in advance,
Christian

Activity

  1. waldekmastykarz commented on Sep 17, 2023

    @waldekmastykarz
    Collaborator

    Thanks for reaching out! What operating system are you working on?

  2. procioadmin commented on Sep 17, 2023

    @procioadmin
    Author

    Thank you very much for your help and fast response!

    Thats what I am developing on:

    Edition	Windows 10 Pro
    Version	22H2
    Installed on	‎05.‎07.‎2020
    OS build	19045.3448
    Experience	Windows Feature Experience Pack 1000.19044.1000.0
    
    Device name	YMC-PC
    Processor	Intel(R) Xeon(R) CPU E3-1246 v3 @ 3.50GHz   3.50 GHz
    Installed RAM	32,0 GB (31,9 GB usable)
    Device ID	
    Product ID	
    System type	64-bit operating system, x64-based processor
    Pen and touch	No pen or touch input is available for this display
    

    Regards
    Christian

  3. waldekmastykarz commented on Sep 17, 2023

    @waldekmastykarz
    Collaborator

    Could you please share a screenshot of proxy running? Also, do you have a minimal repro setup of your app that we could use just to ensure that we're looking at the same thing? I appreciate your help in getting to the bottom of this

  4. procioadmin commented on Sep 17, 2023

    @procioadmin
    Author

    Sure, great thanks!
    I have created a test project type console-app .net Framework 4.8. I will paste the code here, otherwise tell me if you want it downloadable via github. Just let me know if I can support you in any way!

    THX's in advance
    Christian

    2023-09-17 22_23_34-

    Code

    using System;
    using System.Threading.Tasks;
    using Azure.Identity;
    using Microsoft.Graph;
    using Microsoft.Graph.Models;
    
    namespace Testm365proxy_msgraph
    {
        class Program
        {
            static async Task Main(string[] args)
            {
                string user         = "<user>";
                string tenant       = "<tenant>";
                string clientId     = "<clientid>";
                string clientSecret = "<clientsecret>";
    
                Console.WriteLine("Start of Test Program");
    
                //Client Credentials
                ClientSecretCredentialOptions credentialsClientCredentialsSeretOption = new ClientSecretCredentialOptions();
    
                ClientSecretCredential credentialsClient = new ClientSecretCredential(tenant, //Tenant
                                                                                    clientId, //Client
                                                                                clientSecret, credentialsClientCredentialsSeretOption); //Secret
    
                GraphServiceClient graphClient = new GraphServiceClient(credentialsClient);
    
                //Get one mail...
                MessageCollectionResponse mails = await graphClient.Users[user].MailFolders["Inbox"].Messages.GetAsync((requestConfiguration) =>
                {
                    requestConfiguration.QueryParameters.Top = 1;
                    requestConfiguration.QueryParameters.Orderby = new string[] { "subject", "importance", "receivedDateTime asc" };
                    requestConfiguration.QueryParameters.Filter = "";
                    requestConfiguration.Headers.Add("Prefer", "IdType=\"ImmutableId\"");
                });
    
                Console.WriteLine($"Found {mails.Value.Count} mail(s)!");
                Console.WriteLine("End of Test Program...press ENTER");
                Console.ReadLine();
    
            }
        }
    }
    
  5. waldekmastykarz commented on Sep 18, 2023

    @waldekmastykarz
    Collaborator

    Thank you so much, I'll try to repro it asap

  6. waldekmastykarz commented on Sep 18, 2023

    @waldekmastykarz
    Collaborator

    I've just ran your code and I can see proxy intercept it as expected:

    image

    When starting the proxy for the first time, have you confirmed the prompt to install the certificate, and then granted the proxy access to your network and firewall configuration?

  7. procioadmin commented on Sep 18, 2023

    @procioadmin
    Author

    Nice! Thank you for taking your time!

    When starting the proxy the first time I got the certificate prompt, I confirmed it.
    The following firewall popup I granted it with private and public network.
    I will doublecheck both of them and come back to you today...

    Regards
    Christian

  8. procioadmin commented on Sep 18, 2023

    @procioadmin
    Author

    I have news! I tested it like you with .Net7 and it works! I test again with .Net4.8 and still not working. Both
    same coding, same library versions.

    2023-09-18 21_23_12-Testm365proxy_msgraph_net7 - Microsoft Visual Studio (Administrator) - Experimen

    At the moment I have no clue where to search for...

    If you have an idea where to look into please let me know.

    Thank you for your time&
    Regards
    Christian

  9. waldekmastykarz commented on Sep 19, 2023

    @waldekmastykarz
    Collaborator

    Cool, thanks for sharing. I'll try to repro on .net 4.8. I suspect I can use the same code as-is?

  10. waldekmastykarz commented on Sep 19, 2023

    @waldekmastykarz
    Collaborator

    I can indeed reproduce the issue on .net 4.8, where the same code is issuing web requests that are not intercepted by m365proxy. Let me dig deeper. Thanks again for bringing it up

  11. waldekmastykarz commented on Sep 19, 2023

    @waldekmastykarz
    Collaborator

    OK, I think I've got it. Seems like Microsoft Graph .NET SDK on .NET 4.8 uses an older HTTP adapter, which is configured to use WinHTTP API proxy settings rather than the internet proxy settings which the m365proxy enables on startup.

    To use m365proxy with .NET 4.8, you need to configure it as proxy with the WinHTTP API. You can do that using the netsh command (run as admin):

    netsh winhttp set proxy proxy-server="http=localhost:8000;https=localhost:8000"

    When you're done, you can reset the WinHTTP settings by calling:

    netsh winhttp reset proxy

    Hope this helps.

    @garrytrinder we should add this to our docs

    /cc: @gavinbarron @sebastienlevert

  12. procioadmin commented on Sep 19, 2023

    @procioadmin
    Author

    That makes fun! Thank you for taking your time helping me out!

    I test it and as you mentioned with the setting the proxy it works flawlessly!
    The details you provided helped me to understand what the problem was. Now I am ready for using your tool extensively to bring my app in a rock-solid state!

    2023-09-19 10_59_48-C__Users_YMC_source_repos_Testm365proxy_msgraph_Testm365proxy_msgraph_bin_Debug_

    Thank you for your help and keep on doing what you doing,
    Regards
    Christian

  13. waldekmastykarz commented on Sep 19, 2023

    @waldekmastykarz
    Collaborator

    Awesome! Thank you so much for bringing this gap in our docs to our attention and working with us to get to the bottom of it. Please, never hesitate to reach out if there's anything that we can help with.

  14. procioadmin commented on Sep 19, 2023

    @procioadmin
    Author

    It was great working with you! Using your tool together with MSGraph Client library is a pleasure!

  15. waldekmastykarz commented on Sep 19, 2023

    @waldekmastykarz
    Collaborator

    Thank you for the kind words, it means a lot 😊

  16. locked and limited conversation to collaborators on Jun 4, 2025
  17. converted this issue into a discussion #1232 on Jun 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions