System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Memory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Source=Microsoft.Extensions.Fil

Harshalkumar Jain 0 Reputation points
2024-02-10T05:42:08.4433333+00:00

We are upgrading our azure functions - .NET core - from version 6 to 8

Getting below error when solution is run from visual studio 2022

System.IO.FileNotFoundException

HResult=0x80070002 Message=Could not load file or assembly 'System.Memory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Source=Microsoft.Extensions.FileProviders.Physical Below is the complete stack trace

System.IO.FileNotFoundException

HResult=0x80070002 Message=Could not load file or assembly 'System.Memory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Source=Microsoft.Extensions.FileProviders.Physical StackTrace: at Microsoft.Extensions.FileProviders.Physical.Internal.PathUtils.HasInvalidFilterChars(String path) at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter) at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer) at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source) at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at JohnsonControls.FireStorm.WorkspaceService.AzureFunctionsAppStartup.Configure(IWebJobsBuilder builder) in C:\XXXXXXXXXXXXXXX\App\AzureFunctionsAppStartup.cs:line 55 at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.ConfigureAndLogUserConfiguredServices(IWebJobsStartup startup, WebJobsBuilderContext context, IWebJobsBuilder builder, ILoggerFactory loggerFactory) at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseWebJobsStartup(IWebJobsBuilder builder, Type startupType, WebJobsBuilderContext context, ILoggerFactory loggerFactory) at Microsoft.Azure.WebJobs.WebJobsBuilderExtensions.UseExternalStartup(IWebJobsBuilder builder, IWebJobsStartupTypeLocator startupTypeLocator, WebJobsBuilderContext context, ILoggerFactory loggerFactory) at Microsoft.Azure.WebJobs.Script.ScriptHostBuilderExtensions.<>c__DisplayClass7_0.<AddScriptHostCore>b__1(HostBuilderContext context, IWebJobsBuilder webJobsBuilder)

What I have done so far?

Upgraded visual studio to 2022 Version 17.8.6

Installed .NET SDK 8.0.101 (x64)

Installed .NET SDK 8.0.101 (x64) - from visual studio

Updated global.json as below

{

"sdk": { "version": "8.0.101" } } In the code .csproj files - replaced references from version 6.0.0 to 8.0.0

  Upgraded nuget packages for which build in Visual studio was failing to latest stable version

Such as – Azure.Identity, Microsoft.Identity.Client and a few more   Installed a few additional nuget packages

Thus with these changes & a few more, and few trials / errors,  - the build/rebuild is successful in Visual studio

But now when I run the solution - getting below error

System.IO.FileNotFoundException HResult=0x80070002 Message=Could not load file or assembly 'System.Memory, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified. Source=Microsoft.Extensions.Fil......

   This issue happens in AzureFunctionAppStartup class in – configure() method while creating ConfigurationBuilder()

 

Below code snippt of my .csproject file <ItemGroup>   <PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.2" />   <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.0" />   <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />   <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="5.1.2" />   <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">     <PrivateAssets>all</PrivateAssets>     <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>   </PackageReference>   <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />   <PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />   <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />   <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />   <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />   <PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />   <PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />   <PackageReference Include="Microsoft.Graph" Version="4.43.0" />   <PackageReference Include="Microsoft.Identity.Client" Version="4.59.0" />   <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />   <PackageReference Include="AutoMapper" Version="12.0.0" />   <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />   <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">     <PrivateAssets>all</PrivateAssets>     <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>   </PackageReference>   <PackageReference Include="System.Memory" Version="4.5.5" />   <PackageReference Include="System.Memory.Data" Version="8.0.0" /> </ItemGroup>   FYI - We have microservices architecture and are using Refit

We have not even tried to deploy the function in azure portal, we are getting issues on local system in visual studio

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,935 questions
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | Visual Studio | Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.