Author Topic: Migrating from C# and .NET Framework to C# 12 and .NET 8  (Read 2308 times)

0 Members and 1 Guest are viewing this topic.

57gmc

  • Bull Frog
  • Posts: 372
Migrating from C# and .NET Framework to C# 12 and .NET 8
« on: January 05, 2024, 04:44:19 PM »
Ive been sick, so I had some time to watch some episodes from .NET conf. I found a nice overview of C#. Its a lot to learn if you haven't been keeping up with the progress of .NET because you were able to keep working on the AutoCAD api. This speaker came up with the idea of "everyday C#" (30 min), meaning that you may not use a lot of the new features and you can just add them as you have a need. That means that you don't have to spend a huge amount of time up front just to catch up before you can work in .NET 8. I thought that this was a balanced view. You can read up on the new features of C# here.

I used the Upgrade Assistant in VS. to upgrade my AutoCAD Project (without referencing the new api's) and there weren't any huge changes. At least, not from the .NET perspective. I still have to update my project to point to 2025's api's.
Post here if you have any other upgrading tips.

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #1 on: January 07, 2024, 03:27:07 AM »
We don't just need to learn what's new in C# 12, but everything that's new since C# 7 (see this history of C#), especially these (for me):
  • Pattern matching
  • Nullable reference types
  • Records
  • Collection expressions
  • Lambda expression enhancements
« Last Edit: January 09, 2024, 01:10:29 AM by gile »
Speaking English as a French Frog

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2165
  • class keyThumper<T>:ILazy<T>
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #2 on: January 07, 2024, 03:36:45 AM »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #3 on: January 07, 2024, 04:19:40 AM »
Yes the Guard class looks interesting, but for the most current cases we can use, without the need of Community Toolkits extension, the ArgumentNullException.ThrowIfNull, ArgumentException.ThrowIfNullOrWhiteSpace, ArgumentOutOfRangeException.ThrowIfGreaterThan, ... methods.
« Last Edit: January 09, 2024, 03:43:45 AM by gile »
Speaking English as a French Frog

57gmc

  • Bull Frog
  • Posts: 372
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #4 on: January 08, 2024, 04:47:04 PM »
We don't just need to learn what's new in C# 12, but everything that's new since C# 7 (see this history of C#), especially these (for me):
  • Pattern matching
  • Nullable reference types
  • Records
  • Collection expressions
  • Lambda expression enhancements
Hi Gile, your link doesn't do anything. Perhaps you meant the History of C#? It is a subset of the link I posted. It just starts with version 12. I like your list. It's helpful to see what you thing is most useful. There's a lot of history to catch up on.

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #5 on: January 09, 2024, 01:27:28 AM »
Hi Gile, your link doesn't do anything. Perhaps you meant the History of C#?
That's it. I repaired the link.
Speaking English as a French Frog

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2165
  • class keyThumper<T>:ILazy<T>
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #6 on: January 09, 2024, 02:29:30 AM »
Gilles, Post Reply #3 has broken links too.
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

gile

  • Gator
  • Posts: 2522
  • Marseille, France
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #7 on: January 09, 2024, 03:45:31 AM »
Gilles, Post Reply #3 has broken links too.
Thanks for reporting, repaired.
Speaking English as a French Frog

Atook

  • Swamp Rat
  • Posts: 1031
  • AKA Tim
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #8 on: January 09, 2024, 03:48:10 PM »
Any recommendations for structuring a VS Solution for the transition to .NET 8?

Can we use the new C# features and maintain backwards compatibility with Framework?

57gmc

  • Bull Frog
  • Posts: 372
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #9 on: January 09, 2024, 03:58:32 PM »
No, the .NET Framework is no longer supported. AutoCAD 2025 will use .NET 8. There shouldn't be much to restructure though. Use the Migration Assistant that I mentioned in the first post. If you need to maintain compatibility with older versions of acad, I recommend keeping the 2024 version too. The Migration Assitant can upgrade your solution in place or upgrade to a copy. Choose the latter to retain the 2024 version. Depending on what features you are using, you might be able to keep just one solution and compile to different dll's using compile directives. But in the end, you will still need 2 dll's. One for 2024 and lower and one for 2025.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2165
  • class keyThumper<T>:ILazy<T>
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #10 on: January 09, 2024, 04:01:27 PM »
Hi Tim,

Any recommendations for structuring a VS Solution for the transition to .NET 8?

There is little difference to currently, in principle. The differences are in the details of language and API references.
Do you have access to the Beta site ? I'm wary of posting specifics ( perhaps unnecessarily so )


Quote
Can we use the new C# features and maintain backwards compatibility with Framework?

Essentially No.

.NET 8+  and Framework 4.8+ are different beasts.
Pre ac2025 requires Framework,
 ac2025=> requires  .NET


added:
backup and archive skills are recommended  :wink:
Initially we don't 'need' to use the C#12 new functionality. ( just use C#12 compiler )
The post by 57gmc covers the essential process.

Regards,
« Last Edit: January 09, 2024, 04:10:20 PM by kdub_nz »
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

Atook

  • Swamp Rat
  • Posts: 1031
  • AKA Tim
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #11 on: January 09, 2024, 11:51:19 PM »
There is little difference to currently, in principle. The differences are in the details of language and API references.
Do you have access to the Beta site ? I'm wary of posting specifics ( perhaps unnecessarily so )

I do have access, just been head down working on other things. Looking forward to the update though, fingers crossed it's pretty smooth.

MickD

  • King Gator
  • Posts: 3684
  • (x-in)->[process]->(y-out) ... simples!
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #12 on: January 10, 2024, 01:10:54 AM »
In my experience working with web tech (ASP.net) moving from Framework to Core was mainly library references, there was only very minor API changes, you just have to know where things got moved to but Intellisense and the compiler help you out here.
They have essentially moved MS specific stuff (WinForms for example) into new/different lib's but the .Net stuff (i.e. C# and others) is now cross platform bringing it more in line with Java.

As kdub_nz pointed out, good old C# the language will still 'just work', no need to stress about the language update :)
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Everything that is possible demands to exist"
- Gottfried Wilhelm von Leibniz

huiz

  • Swamp Rat
  • Posts: 919
  • Certified Prof C3D
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #13 on: January 10, 2024, 02:51:50 AM »
There is little difference to currently, in principle. The differences are in the details of language and API references.
Do you have access to the Beta site ? I'm wary of posting specifics ( perhaps unnecessarily so )

I do have access, just been head down working on other things. Looking forward to the update though, fingers crossed it's pretty smooth.


I shared a document with my experiences, might be helpful. You can find the document in this location:


AutoCAD Customer Council > User Forums > ObjectARX API > First experiences with porting code to AutoCAD 2025 and .NET8
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

retsameht

  • Newt
  • Posts: 22
Re: Migrating from C# and .NET Framework to C# 12 and .NET 8
« Reply #14 on: March 12, 2024, 04:10:58 AM »
Yes the Guard class looks interesting, but for the most current cases we can use, without the need of Community Toolkits extension, the ArgumentNullException.ThrowIfNull, ArgumentException.ThrowIfNullOrWhiteSpace, ArgumentOutOfRangeException.ThrowIfGreaterThan, ... methods.

Both the ExceptionXxx.ThrowIfXxxx() methods and the Guard class rely on the CallerArgumentExpression Attribute to communicate better.

I adapted it into my existing RuntimeExtensions

Code - C#: [Select]
  1.    public static class RuntimeExtensions
  2.    {
  3.  
  4.       public static void ThrowIf(this AcRx.ErrorStatus es,
  5.          bool condition,
  6.          [CallerArgumentExpression("condition")] string message = null)
  7.       {
  8.          if(condition)
  9.             throw new AxRx.Exception(es, message);
  10.       }
  11.    }
  12.    
  13.    public static class Test()
  14.    {
  15.       void Run()
  16.       {
  17.          Document doc = Application.DocumentManager.MdiActiveDocument;
  18.          ErrorStatus.NoDocument.ThrowIf(doc is null);
  19.          blah blah blah
  20.       }
  21.        
  22.    }
  23.  
  24.  

If the above Run() throws, the exception message will contain "doc is null".