microsoftgraph / msgraph-beta-sdk-dotnet

The Microsoft Graph Client Beta Library for .NET supports the Microsoft Graph /beta endpoint. (preview)
Other
96 stars 32 forks source link

Using this reference throws runtime error because a dependency is not strongly named #444

Closed SebastianAtWork closed 1 year ago

SebastianAtWork commented 2 years ago

Hi Team, I have a very unfortunate Exception thrown when trying to use this SDK. When i try to call a User endpoint in a Test, it throws the following exception: System.IO.FileLoadException: 'Could not load file or assembly 'Tavis.UriTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)' Originally my projekt was also strongly named, but i removed that and still got the error. Signing it myself with ildasm ilasm does not work because it is referenced with publickeytoken=null I´m using Windows 10 with Net Framework 462. Any idea why this happens?

andrueastman commented 2 years ago

Hey @SebastianAtWork,

Thanks for raising this.

Any chance you can share the contents of the csproj file to help us replicate and investigate?

SebastianAtWork commented 2 years ago

Yep, i tried replicating it in a minimal environment and here : https://github.com/SebastianAtWork/Microsoft.GraphApi.Beta.Test . Same Error. Maybe I´m missing something obvious.

SebastianAtWork commented 2 years ago

The Error comes when running the Unit Test

ssdevref commented 2 years ago

I have the same issue when I call EducationSynchronizationProfileCollectionResponse profiles = await graphServiceClient.Education.SynchronizationProfiles.GetAsync();

I believe it's because the Tavis.UriTemplates.dll assembly is not signed, where as the Microsoft.Kiota.Abstractions.dll is strongly named. I've tried using ildasm to disassemble the assembly and then ilasm to reassembly and sign with a new key, but the reference in Microsoft.Kiota.Abstractions.dll does not specify a public key for the assembly so this doesn't load. If I disassemble and resign the Microsoft.Kiota.Abstractions.dll assembly, I'd need to do the same for everything that depends on that - not ideal.

ssdevref commented 2 years ago

The call to the endpoint may be inconsequential, it happens to be the first thing I invoke after creating the client using an implementation of IAccessTokenProvider in the constructor.

incureforce commented 2 years ago

Error occurs with .net 4.7 and nuget microsoft.graph.beta from version: 5.3.0-preview & 5.7.0-preview - 5.10.0-preview (5.4.0-preview - 5.6.0-preview has a different enumeration modified error)

This error also occurs in Microsoft.Graph 5.0.0-preview.10.

Same Error with a Simple Project:

ConfidentialClientApplicationBuilder for IAuthenticationProvider.AuthenticateRequestAsync as only argument for GraphServiceClient.

The file or assembly "Tavis.UriTemplates, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or a dependency on was not found. An assembly with a strong name is required. (Exception from HRESULT: 0x80131044)

   at Microsoft.Kiota.Abstractions.RequestInformation.get_URI()
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetRequestMessageFromRequestInformation(RequestInformation requestInfo)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<GetHttpResponseMessage>d__24.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.<SendAsync>d__14`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Graph.Beta.Users.Item.UserItemRequestBuilder.<GetAsync>d__195.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at IKH.Core.Graph.GraphManagement.<GetMgUserAuthenticationPhoneMethod>d__14.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at IKH.Core.Graph.TestApp.Program.<GetPhones>d__5.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at IKH.Core.Graph.TestApp.Program.<Main>d__1.MoveNext()
wilsonmfg commented 2 years ago

any updates? I'm also getting this with dotnet 4.7.2 and 4.8 with 5.10.0-preview. I'm using IAccessTokenProvider based on https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/feature%2F5.0/docs/upgrade-to-v5.md so I can use AcquireTokenByIntegratedWindowsAuth

SergiyStoyan commented 2 years ago

Can anybody hint a workaround for this bug? To get it work, I had to downgrade to Microsoft.Graph 4.45.0

wilsonmfg commented 2 years ago

there is no workaround. Microsoft either needs to sign the dependent libraries or remove the strong name requirement from the graph libraries

colinhqgit commented 2 years ago

Would love this to be fixed as well. As @sergeystoyan , I had to downgrade. Thank you.

bmacombe commented 1 year ago

I'm getting this error also with net 4.8 and running from a unit test. It's blocking for sure.

sopelt commented 1 year ago

This is quite the frustrating showstopper when trying to use the preview in projects with mutliple target frameworks :-/
Any ETA on a fix?

andrueastman commented 1 year ago

Thanks for your patience with this issue.

This should now be resolved with the latest 5.14.0-preview version after the dependency was republished with a strong name,

sopelt commented 1 year ago

Looks good to me @andrueastman . The same code that previously failed with 5.13 and net472/net48 works in 5.14.

Thanks!