Compile C# in VB.NET Project

ConfigurationSettings.AppSettings' is obsolete

Using the System.Configuration.ConfigurationSettings.AppSettings["whatever"] and getting the obsolete error message?

While  the definition of "obsolete" might be arguable, it still works - but of course you should fix it. Change to

System.Configuration.ConfigurationManager. AppSettings["whatever"]

If you are getting an error on that one - add a reference to System.Configuration.dll, cause appearantly Microsoft have moved the AppSettings class out of the System dll.

Alternate Solutions to Consider

Disable View State on a Page

To disable a page’s View State, add the code below in the Page class of the page. In this example, the page’s class name is MyCurrentPage.


public MyCurrentPage()
    this.Init += new EventHandler(Page_Init);
private void Page_Init(object sender, System.EventArgs e)
    this.EnableViewState = false;

Visual Basic .NET:

' Disable the View State in the page.M
Private Sub MyPage_Init_DisableViewState(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
    Me.EnableViewState = False
End Sub

Compile C# and VB.NET Together

You can easily compile C# modules and VB.NET code together.

Put your C# classes into a folder in the App_Code directory.

In your web.config

add directoryName="CS directory Name"

Read article below if you need more info.

Put C# Code in a VB.NET Project

A C# version of Michael Washington's DotNetNuke DAL+ module example.

This article is a C# supplement to the tutorial that Michael Washington did called Creating a Super-Fast and Super-Easy DotNetNuke Module For absolute beginners for DotNetNuke Version 4.3 or higher.

To make full use of this article you should first download the C# version of this module from the Downloads section of this web site. Now you should generally follow the instructions from the adefwebserver (above) to create the module. You can create both the VB and C# examples side-by-side for comparison of just one or the other.

There are a few nuances that you should be aware of when it comes to the C# part of the project.

The 4 files that are specific to the C# part of the project all start with CS and are not needed if you are only creating the VB part of the project. If that's the case then you should not be reading this article but the tutorial listed above.

Two of the C# files should be placed in a folder under the App_Code folder of the web site in question. If for example your web site is at C:\DotNetNuke_2\Website then you should put the CSThingsForSaleController.cs and CSThingsForSaleInfo.cs in the C:\DotNetNuke_2\Website\App_Code\CS\ folder. I have selected a folder called CS but you can call it anything you want.

In my projects, I put all of my C# code in folders under the ..\CS\ folder so that I can just specify one folder in the web.config file to be compiled separately.

Now this part is important and relates to the last sentence above. If you're compiling (using) C# code in a VB project you need to tell the compiler to compile the C# code apart from the VB code and build separate DLLs for the C# code. You do this by specifying the folder in the web.config file like so:

<compilation ...>
add directoryName="CS"

This lets the compiler know that the CS directory below the App_Code directory and all sub-directories below it should be compiled into a separate DLL.

Under the DesktopModules folder you can create a CSThingsForSale module and just do exactly the same with this folder as you would do for the VB folders mentioned in Michael's tutorial above and you will be able to create and use the C# version of this tutorial.

You can create and use the VB and C# module side by side - they will both work together.

If you have any questions then feel free to ask in the Forum and I will do my best to answer them.