kind of farewell to .Net Framework

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,711
Location
Norway
Programming Experience
10+
Finally took the time to upgrade all my projects to .Net 8. A few were .Net 6/7 and easy, but most from .Net Framework 4.8. Upgraded around 50 projects in a week.
I didn't like the upgrade assistant when I tested that before so I just started new projects and copied in classes, and made necessary changes.

For winforms projects (yes, they're nice and easy to use for my quick "tools" with consistent GUI controls) I found that I could just copy the three files (code, designer, resx) in and they mostly were good to go.

Issues were Settings and Resources mostly, espescially settings with control bindings in designer file. The settings file I added in project properties first, copied in the old and "Run Custom Tool" on it, then moved any control bindings to user code.

There were some issues with xsd files and typed datasets, I had to add and run custom tool MSDataSetGenerator to get rid of a warning about a constructor supporting out-of-support BinaryFormatter. I don't actually use databases and just had used xsd for convenience databinding a few places, so this was not a case of "should move to EF or something like that".

Couldn't get the new resource designer to work in current VS 2022 (17.11.5), so I just set the resource files as Embedded Resources and used Assembly.GetManifestResourceStream to load them, I didn't have many cases though.
ImageLists containing some images in a form were also trouble with BinaryFormatter serialization from resx, same here I moved the code to user file and loaded the images from Embedded Resources.

I got quite a few new code improvement suggestions, a lot of the projects were very old, some more than 10 years old and just up'ed Framework versions before. Minor improvements, but I did them all.
  • Apparently I have "always" used Count extension rather than Length property, "Count" reads better than "Length", but oh well, I fixed 300 occurrences anyway.
  • Dictionary.TryGetValue has escaped me, now I have learned I should not "guard" with ContainsKey and later lookup.
  • In VB projects vbNewline is deprecated, use vbCrLf (also less readble IMO) - or Environment.NewLine.
  • Lots of ToLower and Contains/Equals got the StringComparison upgrade for case insensitivity, often for checking file extensions.
  • Many "does not access instance data and should be marked static"
  • Many "use char literal for a single character lookup" (instead of single char string)
  • Many "mark readonly fields"
  • A few "don't use Count when Any can be used"
  • Use Array.Empty instead of empty array (zero length array allocations)
  • and so on...
Noticed in forms projects the before default MS Sans Serif 8.25pt font is now Segoe UI 9pt. Expands everything a bit.

Lots of Nuget packages were updated, several versions in some cases, but very few required code changes.

Got to discard a few projects that were just lying around and no longer had any use, made some quick code cleanups along the way, and merged a couple of projects too.

I all, it took less time than I thought, with less troubles, all worth the spare time hours last week. Now I can kind of relax for a couple of years, and easier move on from .Net 8 later. (.Net 9 is up in November already I see 😯)

Still have a couple of Office VSTOs and a VB windows service in .Net Framework, other than that it is .Net only here now. 🤘
 
Be glad that you don't have any encrypted web.config files to deal with.
 
Now on to tracking all uses of Encoding.Default where files are not UTF8.
 
Back
Top Bottom