添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

When I run .net core api project "6.0" on mac I got this error

usr/local/share/dotnet/sdk/7.0.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssemblyInfo.targets(5,5): Error MSB4018: The "WriteCodeFragment" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'System.CodeDom, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
File name: 'System.CodeDom, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
 ---> System.IO.FileLoadException: Could not load file or assembly 'System.CodeDom, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyBinder, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>g__TryLoadAssembly|3(AssemblyName assemblyName)
   at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.<RegisterMSBuildPath>b__2(AssemblyLoadContext _, AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.Build.Tasks.WriteCodeFragment.GenerateCode(String& extension)
   at Microsoft.Build.Tasks.WriteCodeFragment.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) (MSB4018) (Redis_Demo)

" I had many version of .net core on my mac ,please I need your support

dotnet --list-sdks
dotnet --list-runtimes

the build error implies you are building with net sdk 7.0.302 (same as my Mac) but the target runtime is missing some files.

see the latest runtime version net 6 (my Mac its 6.0.16). be sure your have a matching set of the latest:

Microsoft.AspNetCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

the fix is install the latest net 6. (you might delete any existing .net 6 runtimes)

more more help, show the output of the lists and the project file.

dotnet --version
dotnet --list-sdks
dotnet --list-runtimes

Thank you for your help :)

I tried to download latest version of runtime for .netcore 6 which is 6.0.18 alongside with sdk 6.0.410 ,but still have this error

when I created api with core v 7.0 ,i'm still facing same issue although it was working before

using Redis_Demo.Models; // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace Redis_Demo.Controllers [Route("api/[controller]")] [ApiController] public class ProductController : ControllerBase private readonly AppDbContext _dbContext; private readonly ICacheService _cacheService; public ProductController(AppDbContext dbContext, ICacheService cacheService) _dbContext = dbContext; _cacheService = cacheService; [HttpGet("products")] public IEnumerable<Product> Get() var cacheData = _cacheService.GetData<IEnumerable<Product>>("product"); if (cacheData != null) return cacheData; var expirationTime = DateTimeOffset.Now.AddMinutes(5.0); cacheData = _dbContext.Products.ToList(); _cacheService.SetData<IEnumerable<Product>>("product", cacheData, expirationTime); return cacheData; [HttpGet("product")] public Product Get(int id) Product filteredData; var cacheData = _cacheService.GetData<IEnumerable<Product>>("product"); if (cacheData != null) filteredData = cacheData.Where(x => x.ProductId == id).FirstOrDefault(); return filteredData; filteredData = _dbContext.Products.Where(x => x.ProductId == id).FirstOrDefault(); return filteredData; [HttpPost("addproduct")] public async Task<Product> Post(Product value) var obj = await _dbContext.Products.AddAsync(value); _cacheService.RemoveData("product"); _dbContext.SaveChanges(); return obj.Entity; [HttpPut("updateproduct")] public void Put(Product product) _dbContext.Products.Update(product); _cacheService.RemoveData("product"); _dbContext.SaveChanges(); [HttpDelete("deleteproduct")] public void Delete(int Id) var filteredData = _dbContext.Products.Where(x => x.ProductId == Id).FirstOrDefault(); _dbContext.Remove(filteredData); _cacheService.RemoveData("product"); _dbContext.SaveChanges(); After Removing all SDKs , .NetRunTime and only install .Net core 7.0 now it works:).