Can you call a .net 5.0 core project from a .net 4.8 ?

iqworks Information Quality Works 331 Reputation points
2022-04-19T15:41:15.297+00:00

Hi, I thought I saw some place that this can be done. Should I call .net 5.0 API’s from .net 4.8? Can you call a .net 5.0 MVC project from .net MVC? I am looking for examples today if this can be done.
Thanks for any advice or suggestions

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2022-04-19T17:13:48.613+00:00

    Use HttpClient to invoke an MVC Action. HTTP is platform agnostic.

    https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-6.0

    0 comments No comments

  2. Bruce (SqlWork.com) 77,926 Reputation points Volunteer Moderator
    2022-04-19T20:41:11.043+00:00

    not directly. you have a couple options

    1) the .net 5.0 project targets .netstandard instead of .net5. this will limit the api's available to .net 5 project. you can also share common code between the projects with .netstandard projects.

    2) as suggested above, a .net 5 webapi hosts the .net 5 code, and the 4.8 uses httpclient to call the methods.

    0 comments No comments

  3. iqworks Information Quality Works 331 Reputation points
    2022-04-19T22:56:48.97+00:00

    thanks guys for getting back. I think I am just confused.
    I am a lot less seasoned as you two guys. I appreciate that HTTP is agnostic agavejoe. but bruce sql work are you saying i can use .net standard to call projects between .net 4.8 and .net 5.0?
    Here is my scenrio.
    I have a .net 4.8 MVC project in visual studio 2019. I created a project in visual studio 2022 that is .net 5.0 core. Then i installed the Entity Frame work 5.0 core and directed it to the same database I am using in my MVC .net framework 4.8 project.
    It was successful and i got this entity framework 5.0 to successfully add the classes from my database to the .net 5.0 project.
    Now i have an existing .net 4.8 MVC project that adds data to my SQL database. But, i need to create a program with angular that displays this data so the user can update this data.
    I ran the migration analysis tool in visual studio and at the very end of the report i probably was seeing things, but i sware I saw something like "dont be an idiot, this migration would be TO messy".
    This is why i thought it would be better to create new projects with .net 5.0 and entity framework 5.0 that are projectes (or even API's) that could still be called from my .net 4.8.
    I am also thinking that .net5 is different from .net 5.0? from what i have read it looks like these are actually the same, but they changed the name from .net 5.0 to .net 5 to avoid confustion?

    thanks for any advice or suggestions

    0 comments No comments

  4. Anonymous
    2022-04-20T07:41:08.89+00:00

    Hi @iqworks Information Quality Works ,

    i can use .net standard to call projects between .net 4.8 and .net 5.0?

    You can create a class library with .Net Standard 2.0 or .Net Standart 2.1

    194565-image2.png

    Then, in the class library, you can install the Entity Framework package, add classes and dbcontext.

    After that, in the .Net 4.8 and Asp.net 5 application, you can add the class library reference and use the relates class, method and dbcontext.

    In this scenario, the class library contains the shared classes, dbcontext and methods, if you want to call the .Net 4.8 and Asp.net 5 project's method from another project, as AgaveJoe said, you have to send the http request via HttpClient.

    Finally, about the difference between .Net framework and Asp.net, see Choose between ASP.NET 4.x and ASP.NET Core and .NET vs. .NET Framework for server apps.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

  5. iqworks Information Quality Works 331 Reputation points
    2022-04-20T17:25:28.43+00:00

    Thank you guys! it will take me a little while to check all of this out. but, i will get back to you all.
    thanks again!!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.