News
WinForms Team Details VB.NET on .NET 5: 'A Huge Challenge'
Two members of Microsoft's Windows Forms dev team appeared in a Channel 9 video on "Supporting VB.NET" in .NET 5," a task that in some ways poses "a huge challenge."
Specifically, one such aspect is getting the WinForms designer to act the same in VB.NET projects as it does in C# projects because of the idiomatic differences between the two languages.
But before getting into the nitty-gritty details of such coding challenges, Merrie McGaw and Klaus Loeffelmann explained to host Rich Landers why they were appearing on his ON.NET show show to discuss VB.NET support in .NET 5.
"Well, we know that a lot of customers were really excited when Windows Forms went to.NET Core and we started seeing a lot of migration, but we didn't have support for Visual Basic.NET," McGaw said. "The information that we get shows that VB customers make up a large proportion of the WinForms customers. We knew we were leaving them out and we didn't want to leave them out anymore. We added that capability in.NET 5."
Indeed, Microsoft announced way back in March 2020 that VB support was planned for .NET 5, specifically for:
- Class Library
- Console
- Windows Forms
- WPF
- Worker Service
- ASP.NET Core Web API
A subsequent post detailed how VB in .NET 5 was ready for WinForms apps.
"I'd like to add to that," said Loeffelmann after McGaw's comments in the new video. "We don't need to forget that Visual Basic handles a couple of things really differently than C#, especially in WinForms. For example, when it comes to hooking up events and stuff like that. It's not that we getting Visual Basic out of the box when we implement all the C# features, there's really dedicated work to do, and this is what we are doing actually.
"First, classically, a big challenge for us when we're writing or rewriting actually a Core designer is in C# when you are hooking up events like a mouse-click event or something like that, then everything goes into inter code that's hosted initially as a component in WinForms, classically. In Visual Basic, that's completely differently from C#. We don't use ad handler in Visual Basic. We have the Handles clause and the Handles clause is something that is on the actual method that handles the event. That is completely different from C#, and it just has to be addressed differently in the designer. It's a huge challenge to do that."
The WinForms designer was a thorny problem even with C# code in the transition from the old, proprietary .NET Framework to the open source, cross-platform .NET Core framework, which switched to a .NET 5, .NET 6 and so on naming scheme with the advent of .NET 5 last November.
For example, "For developers the .NET Core Windows Forms Designer (when we will release the GA version) will look and feel the same as the .NET Framework Windows Forms Designer," said Olia Gavrysh, program manager, .NET, way back in September 2019 in discussing a preview. "But for us it is a huge technical challenge to bring the designer to .NET Core because it requires the design surface that hosts the live .NET Core form to run outside the Visual Studio process. That means we need to re-architect the way the designer surface 'communicates' with Visual Studio."
With VB.NET support, such problems were apparently compounded.
"The other thing is that Visual Basic has the application framework, so supporting API for a couple of things that are tailored to the Visual Basic audience," Loeffelmann continued. "Also that needs a lot of work around the project designers so when you call the properties of your project, so these are the big differences."
Lander replied, "Right. What I hear you saying is there is an idiomatic difference between C# and VB as it relates to WinForms." He also brought up the My namespace in Visual Basic, which exposes frequently used information about an application, the computer being used and so on. "What about My? That's one of the things that people think of when they think about VB, where we're at with that, My Dial."
Loeffelmann replied: "We have support for that, but classically not everything in the My namespace that was pointed in the [.NET] Framework is supported now, and this is also something where we actually want to have feedback from Visual Basic developers. What do you need? What do you think is missing? That's something that we're looking at for.NET 6 or for upcoming versions. The support is there, but it's definitely not there completely at the moment."
Even though Microsoft last year announced, "Going forward, we do not plan to evolve Visual Basic as a language," the .NET team last year said it was supporting the aforementioned application types in VB.NET "to provide a good path forward for the existing VB customer who want to migrate their applications to .NET Core. This allows Visual Basic customers to take advantage of new platform features like side-by-side deployment, cross platform support, performance and new API improvements."
To show the benefits of leveraging those platform features, the WinForms devs ran through a couple of demos, one of which was presented in a March .NET Conf 2021 virtual event, in a "What's New in Visual Basic on .NET 5?" session.
In yesterday's video, Loeffelmann compared a .NET Framework VB.NET app compared to a .NET 5 VB.NET app, noting that the latter appeared in crisper detail because of high-quality DPI modes used by default in .NET 5 for WinForms. While that may be dismissed as just "eye candy" not worthy of a migration effort, the other demo compared an identically coded app that scans photo files for duplicates. There was marked increase in speed in the .NET 5 app compared to the .NET Framework app. "I think this is one of really the big motivational reasons to migrate your app from Framework to.NET 5."
In conclusion after much more technical discussion about Windows 10 device sensors, APIs and more, McGaw said: "We're really excited with the changes that have already been put in for VB.NET users. We are looking forward to helping more and more developers migrate to .NET rather than staying on .NET Framework so that you can take advantage of accessibility. You can take advantage of performance. You can take advantage of new devices. It's all there for the VB customer."
"Right," replied Lander, a Principal Program Manager on the .NET Core team. "That's also what our team is most focused on, and we want people to be able to enjoy the fruits of that labor."
Yesterday's 20-minute video can be seen here.
About the Author
David Ramel is an editor and writer at Converge 360.