Reputation: 21
I am new to .NET Core and trying to write a web service using .NET Core Web API in a project. The other sub projects are written in .NET Framework 4.5. There is a project for Repository layer. I need to get all records by using repository in .NET Core Web API project. I added Repository project reference to .Net Core Web API project. So, for dependency injection; in Startup.cs ConfigureService sevent, I've added the following:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSingleton(typeof(IRepository<>), typeof(RepositoryBase<>));
}
I tried to list all records with the following method in the related controller;
[HttpGet]
[Route("Book/GetAll")]
public IActionResult GetAllRecords()
{
return Ok(_bookRepository.GetAll());
}
When I call this action via web browser, I got the following error message;
> System.IO.FileLoadException: Could not load file or assembly
> 'System.Core, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089'. The located assembly's manifest
> definition does not match the assembly reference. (Exception from
> HRESULT: 0x80131040) File name: 'System.Core, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b77a5c561934e089'
> at BookApi.Startup.ConfigureServices(IServiceCollection services) --- End of stack trace from previous location where
> exception was thrown ---
> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
> at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection
> services)
> at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
> at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Could you please help me about what it means? I've checked GAC dll with the following command ;
C:\Windows\System32>gacutil /l | find /i "system.core"
> System.Core, Version=3.5.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
> System.Core.resources, Version=3.5.0.0, Culture=tr,
> PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
> System.Core, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
> System.Core.resources, Version=4.0.0.0, Culture=tr,
> PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
It seems like System.Core.dll with 4.0.0.0 version exists. I am using Visual Studio 2017 Version 15.2. Also, I am not sure if appsettings.json file contains the required declarations. Could you also explain appsettings.json format?
Upvotes: 1
Views: 489
Reputation: 139
I suggest you to check a few points.
I hope it works.
Upvotes: 0