I have developed a Windows Forms application using .NET 4.8, and it is functioning well with all the required components available in .NET 4.8.
Now, I have a new requirement to enable internet-based communication between two computers. Specifically, I want to change a variable on one computer (PC1) and have the same variable update on the other computer (PC2). I am open to implementing this functionality through an API.
However, I am facing compatibility issues with different .NET versions. I would like to incorporate my Windows Forms project into an ASP.NET Core project, which uses .NET 8.0.
Unfortunately, when I add the Windows Forms project as a reference in the .NET 8.0 project (Dependencies > Add Project Reference), I encounter difficulties running the .NET 8.0 project. Is it possible to have two projects with different .NET versions within a single solution?
For instance, in my second project (an online communication app using .NET), I have written the following code:
using WindowsFormsApplication4;
Form1 form1Instance = new Form1();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () =>
{
string vari1 =
form1Instance.ReferenceNumericUpDownValue.ToString();
return vari1;
});
app.Run();
my error when I run my app:
System.BadImageFormatException: ‘Could not load file or assembly ‘C:Usersdrive3sourcereposremote2remote2binDebugnet8.0WindowsFormsApplication4.exe’. Format of the executable (.exe) or library (.dll) is invalid.’
2
Answers
Without adding it as reference just use ASP.NET as separate project and send request through API and get response
I think there are several approaches that you can attend to .
to run so you can’t just build and run API method within your
winform application . you can implement your API in separated
ASP.NET API project alongside library that targets ".net standard
2.0 " ( you can’t use .net framework alongside .net 8) .
same local network) .
signalR to pass data .