Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.MissingMethodException "Microsoft.Kiota.Http.HttpClientLibrary.KiotaClientFactory" .NET 4.8 #2694

Closed
bfany365 opened this issue Oct 3, 2024 · 5 comments
Labels
Status: No recent activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close

Comments

@bfany365
Copy link

bfany365 commented Oct 3, 2024

Hi

I have already read similar questions but they did not help me:

#2520
#2533
dotnet/runtime#28826

The error:

Method not found: 'System.Net.Http.HttpClient Microsoft.Kiota.Http.HttpClientLibrary.KiotaClientFactory.Create(System.Net.Http.HttpMessageHandler)'.

Stack Trace:

at Microsoft.Graph.Communications.Calls.CommunicationsClientExtensions.<>c__DisplayClass0_0.b__0()
at Microsoft.Graph.Communications.Client.CommunicationsClient.GetOrAddResourceCollection[T](Boolean maintainState, Func`1 valueFactory)
at Microsoft.Graph.Communications.Calls.CommunicationsClientExtensions.Calls(ICommunicationsClient client, Boolean maintainState)

Here is my cs project structure:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{0E6D95B1-E968-4ED4-B2C4-5B53EAB9B68F}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
    <RuntimeIdentifier>win</RuntimeIdentifier>
  </PropertyGroup>

And the dependencies:

<ItemGroup>
    <PackageReference Include="Azure.Identity">
      <Version>1.13.0-beta.2</Version>
    </PackageReference>
    <PackageReference Include="LiteDB">
      <Version>5.0.15</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph">
      <Version>5.59.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph.Communications.Calls">
      <Version>1.2.0.10563</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Graph.Core">
      <Version>3.1.22</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory">
      <Version>3.19.8</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect">
      <Version>6.7.1</Version>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json">
      <Version>13.0.2</Version>
    </PackageReference>
    <PackageReference Include="Ninject">
      <Version>3.3.4</Version>
    </PackageReference>
    <PackageReference Include="Nito.AsyncEx">
      <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="Polly">
      <Version>5.9.0</Version>
    </PackageReference>
    <PackageReference Include="Stateless">
      <Version>4.2.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Owin.SelfHost">
      <Version>4.0.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Owin.StaticFiles">
      <Version>4.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNet.WebApi.Owin">
      <Version>5.2.6</Version>
    </PackageReference>
    <PackageReference Include="System.IdentityModel.Tokens.Jwt">
      <Version>6.5.1</Version>
    </PackageReference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>

I use resharper to dig into to the referenced library and I can see the KiotaClientFactory exists:

 public static class KiotaClientFactory
    {
        /// <summary>
        /// Initializes the <see cref="HttpClient"/> with the default configuration and middlewares including a authentication middleware using the <see cref="IAuthenticationProvider"/> if provided.
        /// </summary>
        /// <param name="finalHandler">The final <see cref="HttpMessageHandler"/> in the http pipeline. Can be configured for proxies, auto-decompression and auto-redirects </param>
        /// <returns>The <see cref="HttpClient"/> with the default middlewares.</returns>
        public static HttpClient Create(HttpMessageHandler? finalHandler = null)
        {
            var defaultHandlers = CreateDefaultHandlers();
            var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), defaultHandlers.ToArray());
            return handler != null ? new HttpClient(handler) : new HttpClient();
        }
public static ICallCollection Calls(this ICommunicationsClient client, bool maintainState = true)
    {
      IInternalCommunicationsClient internalClient = (IInternalCommunicationsClient) client;
      return (ICallCollection) internalClient.GetOrAddResourceCollection<StatefulCallCollection>(maintainState, (Func<StatefulCallCollection>) (() =>
      {
        BaseBearerTokenAuthenticationProvider authenticationProvider = new BaseBearerTokenAuthenticationProvider((IAccessTokenProvider) new AccessTokenProvider());
        HttpClient httpClient = KiotaClientFactory.Create((HttpMessageHandler) null);
        httpClient.BaseAddress = new Uri(internalClient.BaseUrl);
        CallsRequestBuilder calls = new GraphServiceClient(httpClient, (IAuthenticationProvider) authenticationProvider, (string) null).Communications.Calls;
        internalClient.NotificationDispatcher.RegisterDispatcherGetOrAdd(calls.ToGetRequestInformation((Action<RequestConfiguration<CallsRequestBuilder.CallsRequestBuilderGetQueryParameters>>) null)?.URI.ToString().SanitizeResource(client.BaseUrl), (Func<INotificationDispatcher>) (() => (INotificationDispatcher) new NotificationDispatcher(internalClient.GraphLogger, 3, doesNotificationRequireSyncResponse: new Func<NotificationEventArgs, bool>(CommunicationsClientExtensions.ShouldProcessNotificationInSync))));
        return new StatefulCallCollection(internalClient, internalClient.GraphClient, calls, maintainState);
      }));
    }

The error happens when using trying to add event handler for incoming call:

                var builder = new CommunicationsClientBuilder(_config.AppName, BotConfig.MicrosoftAppId, GraphLogger);
                builder.SetAuthenticationProvider(AuthenticationProvider);
                builder.SetNotificationUrl(SignalingUrl);
                builder.SetServiceBaseUrl(new Uri(BotConfig.TeamsPlaceCallEndpointUrl));

                TeamsClient = builder.Build();

                TeamsClient.Calls().OnIncoming += BotEndpoint_OnIncoming;
@bfany365 bfany365 added the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Oct 3, 2024
@andrueastman
Copy link
Member

Thanks for raising this @bfany365

I suspect the issue here is that that the Microsoft.Graph.Communications.Calls package is referencing an old/incorrect version of the kiota http package here.

Do you get a different result if you drop the Microsoft.Graph.Core and the Microsoft.Graph dependency and let the compiler resolve the version the Microsoft.Graph.Communications.Calls dependency?

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Oct 4, 2024
@bfany365
Copy link
Author

bfany365 commented Oct 7, 2024

Hi @andrueastman

I dropped the "Microsoft.Graph.Core" and "Microsoft.Graph" and did not work.

I made a new .net 4.8 project from scratch and just added the required dependencies one by one and here is the list that worked for the new project:

Azure.Core | 1.36.0.0
Microsoft.Bcl.AsyncInterfaces | 7.0.0.0
Microsoft.CSharp | N/A
Microsoft.Extensions.Logging.Abstractions | 2.2.0.0
Microsoft.Graph | 5.38.0.0
Microsoft.Graph.Communications.Calls | 1.2.0.10574
Microsoft.Graph.Communications.Client | 1.2.0.10574
Microsoft.Graph.Communications.Common | 1.2.0.10574
Microsoft.Graph.Communications.Core | 1.2.0.10574
Microsoft.Graph.Core | 3.1.3.0

However, I need to figure out how to make it work in the old project and will let you know after trying.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Oct 7, 2024
@bfany365
Copy link
Author

bfany365 commented Oct 7, 2024

These are the packages that worked:

Microsoft.Graph, 5.38.0
Microsoft.Graph.Communications.Client, 1.2.0.10563
Microsoft.Graph.Communications.Common, 1.2.0.10563
Microsoft.Graph.Communications.Core, 1.2.0.10563
Microsoft.Graph.Core, 3.1.3
System.Net.Http.WinHttpHandler, 6.0.0

@andrueastman
Copy link
Member

Thanks for confirming this @bfany365

At the end of the day, I believe, the Microsoft.Graph.Communications.Core libraries will need to release a new version that targets later version of the library here https://www.nuget.org/packages/Microsoft.Kiota.Http.HttpClientLibrary.

As this library is not maintained by us, would you be willing to create an issue for this at this repo? https://github.com/microsoftgraph/microsoft-graph-comms-samples

@andrueastman andrueastman added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels Oct 9, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: No recent activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close
Projects
None yet
Development

No branches or pull requests

2 participants