❔ Migration from .NET Framework 4.8 to .NET7, Need .NET Standard?

We have a project that is using LINQ-To-SQL and .NET Framework 4.8. The DAL is a separate Class Library project to the UI. We have been tasked with getting this DAL into a .NET 7 API to use with a desktop app that is being rewritten in .NET 7 (Possibly Blazor or React). So the 2 systems will talk to the same API however 1 DAL will be EFCore .NET 7 and 1 will be LINQ-TO-SQL (for now, until we re-write this in EFCore too). I thought the approach might be .NET Core API > .NET Standard 2.0 > .NET Framework 4.8 However when trying to access the .NET Framework 4.8 DataContext I get Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0 from my .NET Standard 2.0 Class Library .NET 7
[HttpGet]
public void GetDevices()
{
_deviceBridge.GetDevies();
}
[HttpGet]
public void GetDevices()
{
_deviceBridge.GetDevies();
}
.NET Standard 2.0
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
.NET Framework 4.8
public void GetDevies()
{
ProjectDataContext dc = this.Session.NewProjectDataContext();
}
public void GetDevies()
{
ProjectDataContext dc = this.Session.NewProjectDataContext();
}
When I reference System.Data.Linq (in .NET Standard or .NET 7) I get BadImageFormatException: Cannot load a reference assembly for execution. at runtime. I've also tried "Mindbox.Data.Linq" which is "A clone of Microsoft System.Data.Linq to allow multi-DLL extensibility and EF compatibility." Sadly still doesn't work. Am I approaching this all wrong? I've read .NET 7 might not even need .NET Standard however I'm getting a similar problem with System.Data.Linq when using just the .NET 7 > .NET Framework 4.8 in regards to System.Data.Linq.
13 Replies
mtreit
mtreit2y ago
https://stackoverflow.com/questions/45935148/system-data-linq-in-netstandard20 It looks like the problem is that System.Data.Linq is not part of .NET Standard.
Stack Overflow
System.Data.Linq in netstandard20
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. FileNotFoundExc...
WibblyWobbly
WibblyWobbly2y ago
Yeah which is why I tried "Mindbox.Data.Linq" which apparently is "A clone of Microsoft System.Data.Linq to allow multi-DLL extensibility and EF compatibility." to use in .NET Standard. However when I try to access the .NET Framework 4.8 code in the .NET Standard
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
public void GetDevies()
{
DeviceFrameworkLogic deviceFramework = new DeviceFrameworkLogic();
deviceFramework.GetDevies(); // <- exception thrown on this line.
}
I continue to get the exception. So I'm unsure how too approach this.
mtreit
mtreit2y ago
You get BadImageFormatException? That is almost always a mismatch between 32-bit and 64-bit binaries.
WibblyWobbly
WibblyWobbly2y ago
No that's only when reference System.Data.Linq directly When I use Mindbox.Data.Linq I get Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0 Well that makes sense. However I though .NET Standard could be used to "join" .NET Core and .NET Framework together
mtreit
mtreit2y ago
Yes, that's what it's typically used for.
WibblyWobbly
WibblyWobbly2y ago
Which is great, so Im basically using a .NET 7 API to call a .NET Framework 4.8 Data Context with Standard as the middle man. However it says it requires System.Data.Linq
mtreit
mtreit2y ago
I'm not really familiar with System.Data.Linq. Never used that. I have a lot of experience porting projects to .NET Core and sharing libraries between .NET Framework projects and .NET Core projects. Let me ask this: if you weren't trying to share this code between .NET Framework and .NET 7, and were purely going to use it from .NET 7, what would you be referencing to make it work? Wait a second. You can't do that. You can have .NET Framework project call code in .NET Standard, but you can't have that code in .NET Standard call a .NET Framework project. It only goes one way.
WibblyWobbly
WibblyWobbly2y ago
Hmmm ok. So I'm not sure what the best approach might be then. This is where I was going in circles. The DAL written in .NET Framework is huge and our first steps into migrating everything to core, was we wanted to put it behind an API. We were hoping it could be a .NET Core API that could reference the .NET Framework 4.8 DAL (by means of .net std), query the data context etc. But thats not possible ?
mtreit
mtreit2y ago
It's not possible, no. But can the .NET 4.8 project be built as .NET Standard instead?
WibblyWobbly
WibblyWobbly2y ago
Well all the data context in written using LINQ-To-SQL which i'm guessing is what system.data.linq is used for. It also references another .NET 4.8 class library.
mtreit
mtreit2y ago
The rule is: convert all of your class libraries to .NET Standard 2.0 if possible. Then the top-level project that consumes it can be .NET Framework or .NET 7 or whatever. I have a hard time believing LINQ to SQL is not a thing in .NET Standard, but we don't use LINQ to SQL for our database stuff so I've never used it.
WibblyWobbly
WibblyWobbly2y ago
Well according to the article you posted above the Mindbox.Data.Linq library allows you to use the system.data.linq name space so maybe this could work. So then porting into a .NET Standard class library is also possible, so I'll give it a go. Thanks for your help 🙂
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.