Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


Reports and Events converted to C#

Why convert the DNN VB.net based modules to C#?

Good question.

Why would one want to convert a proven and correctly working DNN module from VB.net to C#?

  • Technically speaking: there is no need
    VB.net is as powerful as C#
  • Functionally speaking: there is no need
    The module does not gain any new functionality when it is 1 to 1 converted in another .NET language.
  • And then there is the risk
    VB.net and C# differ in details with things like strong typing, type conversion, parameter referencing and more. Do we introduce a step backwards i.s.o. forward?

So why?

The answer, in this case, is twofold:

  1. It is a good learning experience for 'not so experienced' .NET developers, who are still learning C#
    You have a correctly working (VB) module at one side and a not-yet-good working C# module at the other side. So it is proven: it can work, just fix it!
  2. C# is the language of choice for almost every professional .NET developer
    So it will be easier to find people who can understand the source of the module and maybe provide some code enhancements

How do you convert a large module from VB.net to C#?

There are several options: line by line or an online service to convert code fragments. But that is not the options that we have used.

Some time ago I bought a commercial product that can automatically convert complete VB.net based projects into C# in a couple of minutes. Have a look at vbconversions.com. Not very cheap (around $500), but well worth the money if you have serious projects that you want to convert. This tool does a decent job in converting VB.net source code into C# equivalents. It needs a VB solution/project that builds without errors and access to all referenced DLL's. It signals potential problems, has side by side source comparison and more.

What steps did we take in the conversion?

The initial step was the translation of the project from Visual Basic (VB) to C# using the translation tool. The resulting solution has all the same files and folders but now the code is C#. After that, a proper developing environment was set up whereby the C# and VB code could be compared and debugged side by side.

The second step was to make this generated project build correctly and fixing issues.

Most of the initial build errors were related to enumerators needing to be cast, operations and ascx files. Problems arising with ascx files are that methods getting called in the code behind get/set to private (which they also are in VB) which C# does not understand. Fix for this is to make them protected.

Sometimes onclicks attributes getting placed on the wrong tags or missing entirely.

Another issue which breaks the building process is the VB Nothing declaration. This translates into C# as 'null', but if applied to the declaration of a string, VB interprets that as an empty string ("") but in C# it gets assigned to the null which can cause unexpected problems.

What modules did we convert?

We had a go at DNN.Reports (a fairly simple, but old module) and DNN.Events (a very big DNN module that as been well maintained over the years).

Both modules are now released in their C# equivalents and have a new release. DNN.Reports required most of the basic work, DNN.Events had more work because of the size of the module.

The DNN.Reports module from VB.net to C#

The Reports module is a fairly old one. It has a lot of DNN API calls which are deprecated and removed altogether in DNN 9.2. So after the solution builds correctly in DNN 7.3.2, it was necessary to remove deprecated functions from the project. This part of the conversion and upgrade was time-consuming. It required replacing old DNN API methods with the new DNN API ones. The new DNN API calls used different parameters which required rewriting big chunks of code.

After all the errors and deprecated warnings were ironed out it was time to build the module and see if it still functioned properly. During this phase some unattended ascx file errors were handled and eventually, the module functioned just like it had before under VB.

Automating the build and packaging

When DNN.Reports was updated this way, we modernized and automated the build process. For this, the MSBuild extension (DNNtcMSBuild: MS Build for DNN module development) was used and the whole structure of the project was reorganized to match a more modern DNN module structure:

  • Release notes were separated into multiple files;
  • files to be cleaned up got put into text files;
  • the dnn manifest is completely automatically generated as part of the build process;
  • a new icon was added; cleanup, release notes and sqldataproviders were put in a new 'Installation' map;
  • license and headers were updated;
  • the code was refactored using ReSharper
  • a new and an updated .build folder was added.

The last phase consisted of testing whether the new module installed and uninstalled correctly as well as checking whether files got cleaned up correctly after an install on top of an older version.

DNN.Events module from VB.net to C#

This module is much larger than DNN.Reports, but much better maintained over the years. No deprecated DNN API calls anymore in the most recent version, just a lot of work on casting, protected/private, string handling and more difference between VB.net and C#. But we managed to do so.

Credits must go to my colleague Mark van de Vries, a developer at XCESS. He did most of the development work for the conversion, code corrections, and solution improvements.

The end result: DNN.Reports 6.0.0 and DNN.Events 7.0.0 released

If you are interested in an updated version of DNN.Reports, a version that works correctly on DNN 7.3.2 to DNN 9.2 and has some issues fixed: download DNN.Reports here and give it a try. If you find any issues, document them here.

Looking for the C# version of DNN.Events? Download DNN.Events 7.0.0 here. Warning: converting VB.net solutions to C# is not a simple task. And although we did quite some testing, I guarantee you that there will be bugs to pop up in none standard configurations. But we also promise you: we will squash the bugs if you document them as an issue on GitHub.

Comments

Timo Breumelhof
Great info :-)
Timo Breumelhof Tuesday, May 15, 2018 9:51 AM (link)
Clint Patterson
Thanks for your (and your team's) contributions! Great stuff...
Clint Patterson Tuesday, May 15, 2018 12:15 PM (link)
Daniel Valadas
Awesome, I did not know about DNNtcMSBuild, I need to take a look at that...
Daniel Valadas Wednesday, May 16, 2018 5:25 AM (link)
Ernst Peter Tamminga
@Daniel; the one on GitHub is V2.0, but we are still using v1.9 of DNNtc.MSBuild4DNN. I shall create a new repo for this version (that we put on CodePlex before).
Ernst Peter Tamminga Wednesday, May 16, 2018 6:01 AM (link)

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out