Kian Farooghi
Kian Farooghi

Reputation: 46

Using .net4.8 project in .net8 based project

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:\Users\drive3\source\repos\remote2\remote2\bin\Debug\net8.0\WindowsFormsApplication4.exe'. Format of the executable (.exe) or library (.dll) is invalid.'

Upvotes: 1

Views: 2738

Answers (2)

Hamid Razeghi
Hamid Razeghi

Reputation: 69

I think there are several approaches that you can attend to .

  1. As you might know , API needs Webserver (such as Kestrel Or IIS) 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) .
  2. You can use share DB to pass value between two computers (if they are in a same local network) .
  3. You can use real-time tools such as signalR to pass data .

Upvotes: 1

MohanYadavKommindala
MohanYadavKommindala

Reputation: 11

Without adding it as reference just use ASP.NET as separate project and send request through API and get response

Upvotes: 1

Related Questions