microsoftgraph / msgraph-sdk-dotnet

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

[Client bug]: Tavis.UriTemplates loading issue when using Microsoft.Graph@5.0.0 and net472 #1692

Closed jairbubbles closed 1 year ago

jairbubbles commented 1 year ago

Describe the bug

When using latest NuGet package, it fails to load Tavis.UriTemplates.dll:

System.IO.FileLoadException: Could not load file or assembly 'Tavis.UriTemplates, Version=2.0.0.0, Culture=neutral, PublicKeyToken=5be2d48fa8a60581' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

It seems related to #1439.

It looks like the reference is:

image

But the assembly name in package is:

image

To Reproduce Steps to reproduce the behavior:

  1. Use this .csproj:
    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net472</TargetFramework>
        <LangVersion>latest</LangVersion>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.Graph" Version="5.0.0" />
    </ItemGroup>
    </Project>

    With program.cs:

    
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.Kiota.Abstractions;
    using Microsoft.Kiota.Abstractions.Authentication;

var authProvider = new BaseBearerTokenAuthenticationProvider(new TokenProvider()); await authProvider.AuthenticateRequestAsync(new RequestInformation());

class TokenProvider : IAccessTokenProvider { public Task GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object> additionalAuthenticationContext = null, CancellationToken cancellationToken = new()) => Task.FromResult(string.Empty);

public AllowedHostsValidator AllowedHostsValidator { get; } = new();

}


2.  Run
3.  Observe the loading exception

**Expected behavior**

No exception ;-)

**Client version**

5.0.0
andrueastman commented 1 year ago

Thanks for raising this @jairbubbles

Just to confirm, any chance you can still replicate this with version 5.1.0?

jairbubbles commented 1 year ago

I'll check!

jairbubbles commented 1 year ago

Sadly yes, I can reproduce with version 5.1.0.

The package dependencies did not change so we get the exact same behavior.

andrueastman commented 1 year ago

Any chance you can share a sample repro project to help us understand this better? We are having trouble replicating this as the build works from our end.

jairbubbles commented 1 year ago

You mean in a zip file? The files in the description are enough to get it. I just hit F5 to get the exception.

andrueastman commented 1 year ago

You mean in a zip file? The files in the description are enough to get it. I just hit F5 to get the exception.

That would be helpful. As from my end, the build runs successfully.

jairbubbles commented 1 year ago

Here you go:

GraphApiTest.zip

(My dotnet version is 7.0.102)

andrueastman commented 1 year ago

Thanks for this @jairbubbles,

Unfortunately, I'm still unable to replicate this. This builds fine on my end with VS 2022 and dotnet SDK 7.0.201.

Any chance this could be resolved by deleting the contents of the bin directory? Or possibly updating the .NET version?

jairbubbles commented 1 year ago

It builds fine, the execution is problematic right ?

andrueastman commented 1 year ago

That's not the case, the code is able to execute without issue from my end.

jairbubbles commented 1 year ago

I'll check with my colleagues if they can reproduce and get back to you, thx !

jairbubbles commented 1 year ago

Ok so I finally understand what's going on, after removing Tavis.UriTemplates from my global package cache and use nuget.org as my main NuGet source I no longer have the issue.

It seems that we have a different version cached in our internal NuGet package 😰

Version on nuget.org:
image

Version on our internal Nuget server:
image

Could it be that the package was republished? I'll check if it wasn't republished internally as I've already seen that once. It shouldn't happen but you know, mistake happen 😉

Sorry for wasting your time!

andrueastman commented 1 year ago

No worries @jairbubbles,

Thanks for confirming