azure-sdk-for-net
azure-sdk-for-net copied to clipboard
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1
I have created an Azure Function App with .NET Framework 4.71 and I'm receiving the following exception.
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Function1 ---> System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.\r\n at System.MemoryExtensions.AsSpan(String text)
var resourceIdentifier = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000");

I have also set this up in a Console App .NET Framework 4.7.1 without any issues.

What can I do to resolve this issue?
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Thank you for reaching us, @archerzz please check if this is the mgmt issue.
@jrockfl ResourceIdentifiter is from Azure.Core, did you add it in your project dependency?
Yes, I added Azure.Core. It was in the nuget package. Loading Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 is something different.
I was able to get this to work with a console app but not Azure Function.
-----Original Message----- From: "Mingzhe Huang" @.> Sent: Wednesday, March 2, 2022 2:25am To: "Azure/azure-sdk-for-net" @.> Cc: "jrockfl" @.>, "Mention" @.> Subject: Re: [Azure/azure-sdk-for-net] Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 (Issue #26987)
@jrockfl ResourceIdentifiter is from Azure.Core, did you add it in your project dependency? — Reply to this email directly, view it on GitHub , or unsubscribe . Triage notifications on the go with GitHub Mobile for iOS or Android . You are receiving this because you were mentioned.Message ID: @.***>
Hi, I have exactly the same issue after migrating from Microsoft.Azure.ServiceBus to Azure.Messaging.ServiceBus. When I run my solution locally, it executes. However deploying the solution onto a Windows Server 2019 it fails with the following:
Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Threading.Tasks.ValueTask`1.get_IsCompleted() at Azure.Messaging.ServiceBus.Amqp.AmqpReceiver.<ReceiveMessagesAsync>d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Azure.Messaging.ServiceBus.ServiceBusReceiver.<ReceiveMessagesAsync>d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Azure.Messaging.ServiceBus.ReceiverManager.<ReceiveAndProcessMessagesAsync>d__13.MoveNext()
Not sure if its related or helps resolve...
Thanks
I had this exact error message when I tried to use Azure in my project. I searched for the .dll on my computer and found the correct version. Added it to the GAC using gacutil -i . Seemed to solve that issue but then it threw the same error with a new assembly name.
@jrockfl @DomCotton @jfeller403 This should be a binding redirect problem. Try to explicitly upgrade Unsafe to latest version, or try binding redirect as indicated here.
Hi @jrockfl. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Hi @jrockfl, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!