User Controls and Microsoft Graph

Eigo, Gerry 21 Reputation points

I am attempting to create a user control in Visual Studio 2019 using C#. Place the authentication portion of my code into the <control>_load.
On attempting to drag the control to my form, I get a "Failed To Create Component...". In a form or in dll it seems to work. Is using Microsoft Graph in a user control something we should not do?

Here a snippet of the control code:

 private async void UserControl1_Load(object sender, EventArgs e)  
            confidentialClientApplication = ConfidentialClientApplicationBuilder  
            authProvider = new ClientCredentialProvider(confidentialClientApplication);  
            NoteBookHandler = GraphClientFactory.CreateDefaultHandlers(authProvider);  
            OutlookHttpClient = GraphClientFactory.Create(authProvider);  
            OutlookClient = new GraphServiceClient(OutlookHttpClient);  
            object MyFolders = await OutlookClient.Users[""].MailFolders.Request().Top(100).GetAsync();![73499-msgrapherror1.jpg][1]  

Also, attached is an image of the error.


Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,864 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,068 questions
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,487 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,621 Reputation points

    Hi EigoGerry-5512,
    I am afraid that Microsoft Graph is not yet supported in user control.
    And here are some useful links you can refer to.
    Windows Graph Controls
    Microsoft Graph: Developer Blog
    Best Regards,
    Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Viorel 113.8K Reputation points

    Try using if(!DesignMode) to exclude portions of code that cannot be executed at design stage.

    0 comments No comments