You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Question Using developer proxy with Microsoft Graph .NET Client Library 5.x #346
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.
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
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
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
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();
}
}
}
I've just ran your code and I can see proxy intercept it as expected:
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?
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...
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
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):
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!
Thank you for your help and keep on doing what you doing,
Regards
Christian
Reacted by Waldek Mastykarz, Gavin Barron and Sébastien Levert
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.
Activity
waldekmastykarz commentedon Sep 17, 2023
Thanks for reaching out! What operating system are you working on?
procioadmin commentedon Sep 17, 2023
Thank you very much for your help and fast response!
Thats what I am developing on:
Regards
Christian
waldekmastykarz commentedon Sep 17, 2023
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
procioadmin commentedon Sep 17, 2023
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
Code
waldekmastykarz commentedon Sep 18, 2023
Thank you so much, I'll try to repro it asap
waldekmastykarz commentedon Sep 18, 2023
I've just ran your code and I can see proxy intercept it as expected:
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?
procioadmin commentedon Sep 18, 2023
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
procioadmin commentedon Sep 18, 2023
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.
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
waldekmastykarz commentedon Sep 19, 2023
Cool, thanks for sharing. I'll try to repro on .net 4.8. I suspect I can use the same code as-is?
waldekmastykarz commentedon Sep 19, 2023
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
waldekmastykarz commentedon Sep 19, 2023
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
netshcommand (run as admin):When you're done, you can reset the WinHTTP settings by calling:
netsh winhttp reset proxyHope this helps.
@garrytrinder we should add this to our docs
/cc: @gavinbarron @sebastienlevert
procioadmin commentedon Sep 19, 2023
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!
Thank you for your help and keep on doing what you doing,
Regards
Christian
waldekmastykarz commentedon Sep 19, 2023
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.
procioadmin commentedon Sep 19, 2023
It was great working with you! Using your tool together with MSGraph Client library is a pleasure!
waldekmastykarz commentedon Sep 19, 2023
Thank you for the kind words, it means a lot 😊