Solving ASP.NET Compiler Issues with Unrecognized VB.NET 3.5 Feature Syntax

The Issue

I recently encountered an issue with an ASP.NET 3.5 solution after converting it from ASP.NET 2.0.  The issue I’m going to be describing only pertains to the older web site projects (and only web projects — class libraries, etc. do not have this problem) as opposed to the newer web application projects.  I believe this to be true because the conversion wizard built into Visual Studio has rarely ever had trouble converting web application projects, while I’ve never successfully been able to automatically convert a web site project.

At some point after conversion of my web site project, I introduced some nullable type syntax, such as:

Dim amount As Double?

The next time I tried compiling the solution, the VB compiler spit an “error BC30037: Character is not valid.” message at me on the line that contained the nullable variable declaration.  Google was no help — every instance of that vague error message occurring in the search results let me further and further away from anything pertaining to nullable types.  I found that if I changed my variable declaration to:

Dim amount As Nullable(Of Double)

that the solution would compile just fine.  I ignored the problem because there was a simple workaround, until I ran into another trying to use LINQ on a simple collection object. I was looking through a collection of payments with a simple where restriction on one attribute on the payment object, like so:

Dim hasSkips As Boolean = payments.Where(Function(p) p.Code = "SKIP").Count > 0

I have used this syntax in other projects just fine in the past, but this time, the compiler reported an “error BC30201: Expression expected” while verifying the web site after trying to build the solution.

This error message, along with the realization that something seemed wrong with these supposed .NET 3.5 features, got me thinking. Understanding that the syntax I was using was reserved for Visual Studio 2008 and VB.NET 3.5, the first thing I did was check to make sure I was targeting the ASP.NET 3.5 framework (but I just converted it!).  Of course, the property pages for the web site project reported that I was targeting the correct framework.

I tried cleaning the solution and rebuilding, cycling Visual Studio, clearing out the Temporary ASP.NET Files directory; all to no avail.  After another 20 minutes of scouring the web for an answer, I finally found it in a comment on another blog.

The Solution

When converting a web application project or choosing a different framework to target, the process going on behind the scenes to accomplish those tasks isn’t afraid to modify configuration files or even modify code inside your solution.  Attempting the same on a web site project yields much less acceptable results.  It turns out that, even though I’ve instructed my web site project to target the .NET 3.5 framework, the compiler needs a little more nudging to actually use the 3.5 features of the 2.0 compiler that 3.0 and 3.5 use under the hood.

Adding the following block of XML to the web.config file in my web site project made all the difference:

<system.codedom>
        <compilers>
                <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                        <providerOption name="CompilerVersion" value="v3.5"/>
                        <providerOption name="OptionInfer" value="true"/>
                        <providerOption name="WarnAsError" value="false"/>
                </compiler>
        </compilers>
</system.codedom>

Makes all too much sense now that I found it.  I checked other 3.5 web projects and sure enough, they each had this code, conveniently added automatically when I changed their targeted framework version from 2.0 to 3.5.  Trying to figure out why Visual Studio didn’t do it automatically this time is more than my brain wants to handle at the moment, but I’m happy that I can go back to utilizing the .NET 3.5 features that make development even more enjoyable than it was before.

Happy coding!

Tags: , , ,

One Response to “Solving ASP.NET Compiler Issues with Unrecognized VB.NET 3.5 Feature Syntax”

  1. Joe Herr says:

    Thanks, good tip. Fixed my problem.

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word