System.Data.Linq in netstandard20
Asked Answered
S

2

24

I have a netstandard20 project that references a .Net 4.6 Project, all compiles and runs except where I call any functionality in the .Net 4.6 project, I get the following error.

FileNotFoundException: Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

In VS 2017, in the project explorer under Dependancies / SDK / Microsoft.NETCore.App I can see System.Data.dll and System.Data.Common.dll but no reference to System.Data.Linq.dll, I am assuming this is my problem and it has not been pulled in.

How do I get my project to include System.Data.Linq.dll?

If I include C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.Data.Linq.dll I get the following error

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)

Sloatman answered 29/8, 2017 at 9:16 Comment(0)
A
11

System.Data.Linq is not part of .NET Standard 2.0 and .NET Core 2.0 and therefore cannot be used on that platform.

Even tough you have been able add a reference to a .NET 4.6 project via the compatibility shims, it fails at runtime because of a feature that is not available on the target runtime

Athletics answered 29/8, 2017 at 9:48 Comment(0)
A
31

I was able to solve my need to use System.Data.Linq in a .NET Standard 2.0 library by using the Mindbox.Data.Linq NuGet package.

After installing it you should be able to use the System.Data.Linq namespace just like you could when writing for .NET Framework!

April answered 5/6, 2019 at 21:7 Comment(4)
Thanks you, this project probably saved me weeks of work! Still need to move off Linq-to-SQL one day but at least it doesn't block the migration to Core anymore :).Dwight
If this works you will have saved the day, week and maybe the month. I still think LinqToSql was the superior ORM for those who like to get things done and know how they are doing them. I guess I'll join the lemmings and leap into the sea.Eller
On 2018-05-29, Microsoft published System.Data.DataSetExtensions which "Provides extensions to form LINQ expressions and method queries against DataTable objects."Mcgowan
You can find the source of the Mindbox.Data.Linq package here github.com/mindbox-cloud/data-linqTimmytimocracy
A
11

System.Data.Linq is not part of .NET Standard 2.0 and .NET Core 2.0 and therefore cannot be used on that platform.

Even tough you have been able add a reference to a .NET 4.6 project via the compatibility shims, it fails at runtime because of a feature that is not available on the target runtime

Athletics answered 29/8, 2017 at 9:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.