Linq to SQL tools - How to use it with ASP .NET CORE 2.1 project?

4

We have an ASP.NET MVC5 website, I am redesigning it by creating a WebAPI using ASP.NET Core 2.1. We used Linq to SQL tools in the old project. So, I created a Class Library(.NET Framework) as a separate project, and I generated the .dbml file, then referenced it in the WebAPI. When I build the solution, I got this error

Severity Code Description Project File Line Suppression State Error CS0012 The type 'Table<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Blockquote

I added the Reference Assembly to the project (using add Reference > Browse), and the build finished successfully. When I started debugging and tried to call a GET method, I got this error.

Blockquote "Something went wrong please try again. Error: System.BadImageFormatException: Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)\r\nFile name: 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.\r\n at ProjectName.API.Common.Connectors.Connector..ctor(String userName)\r\n at ProjectName.API.ApiModels.APIViewModel.GetMethod(String userName) in C:\Users\xname\source\folder\ProjectFolder\ProjectName.API\ApiModels\APIViewModel.cs:line 73\r\n at ProjectName.API.Controllers.NameController.Method(String userName) in C:\Users\xname\source\folder\ProjectFolder\ProjectName.API\Controllers\NameController.cs:line 37\r\n\r\n" Blockquote

I went through the internet to solve both of them, but so fare nothing could solve the problem. Where am I wrong ? How to make it work ?

Is it wrong to reference .NET Framework project in a .NET Core project ? If yes, what Should I be using instead?

Edit: The main entities mapping is done by EF core 2.1. The mapping with Linq to SQL tools is just for 2 views where we have read only privilege.

c#
asp.net
.net
asp.net-core
linq-to-sql
asked on Stack Overflow Aug 3, 2018 by Mohamed Sahbi • edited Aug 3, 2018 by Mohamed Sahbi

1 Answer

2

Simple. YOu do not. Linq To SQL is ancient, was abandoned WAY before the whole netstandard discussion started. As it is not netstandard it is not working on dotnet core. And as it was abandone like 15 years ago or so (yes, seriously), there is exactly zero chance of Microsoft stepping up and updating it. You should literally have moved away from that many many years ago.

answered on Stack Overflow Aug 3, 2018 by TomTom

User contributions licensed under CC BY-SA 3.0