User Controls and Microsoft Graph

Eigo, Gerry 21 Reputation points
2021-03-02T22:26:12.677+00:00

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  
                .Create(ClientId)  
                .WithTenantId(Tenant)  
                .WithClientSecret(cSecret)  
                .Build();  
            authProvider = new ClientCredentialProvider(confidentialClientApplication);  
  
  
            NoteBookHandler = GraphClientFactory.CreateDefaultHandlers(authProvider);  
            OutlookHttpClient = GraphClientFactory.Create(authProvider);  
            OutlookClient = new GraphServiceClient(OutlookHttpClient);  
  
            object MyFolders = await OutlookClient.Users["gerry.eigo@cga.ct.gov"].MailFolders.Request().Top(100).GetAsync();![73499-msgrapherror1.jpg][1]  
       }  

Also, attached is an image of the error.

Gerry

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

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,616 Reputation points
    2021-03-03T06:48:36.117+00:00

    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 112.5K Reputation points
    2021-03-03T09:19:27.717+00:00

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

    0 comments No comments