microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
704 stars 252 forks source link

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

Closed bfany365 closed 1 month ago

bfany365 commented 2 months ago

Hi

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

https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2520 https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2533 https://github.com/dotnet/runtime/issues/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;
andrueastman commented 2 months ago

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?

bfany365 commented 1 month ago

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.

bfany365 commented 1 month ago

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 commented 1 month ago

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

microsoft-github-policy-service[bot] commented 1 month ago

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.