Room of a pleinolijf

Ask yourself this: how do I want to be remembered ?

Leave a comment

Suppress Compiler Warnings in Visual Studio

Just a quick post to put this out there.  Chances are you already know of this, but I can imagine far from everybody does.


When building a project or solution, Visual Studio will report on what’s happening in the Output window.  (By the way, you can control the verbosity of said window in the Tools – Options… – Projects and Solutions – Build and Run screen.  And the first thing I do on a new system configuration, is enable the ‘Show Output window when build starts’ option in the screen before that.)  It will print informational lines of text, but also, and more importantly, warnings and errors while compiling.

Obviously, your attention should be focused on the errors, as they will likely prevent you from running your application.  Call it neurotical behaviour, but I always aim to have an as clear Output window as I can, so the warnings receive equal attention from me (although not as diligently of course).

But sometimes warnings will keep being generated by Visual Studio, even though you intentionally wrote the code the way you did.  An example can be fields that are declared and assigned, but only used in a

#if (!DEBUG)

statement, like a bunch of license key registrations meant for production.



To keep the warnings from always popping up in the Output window when building, use the #pragma preprocessor directive.

#pragma warning disable 414, 3021

You can get the warning numbers by building  your code. If you can’t or won’t, you can also wrap the code in question in a

#pragma warning disable


#pragma warning restore

‘block’. This will disable all warnings in between, so use with caution !


PS: VSCommands by Squared Infinity is a great extension for VS that will color-code the lines in the output window to increase readability.  You can even define your own custom formatting.


1 Comment

Visual Studio 2003 Web Forms Designer Error with Page Inheritance

When you use VS2003, and you are working on a project that uses page inheritance (replacing the standard System.Web.UI.Page by a BasePage class of your own), you probably have seen the following error when double-clicking an aspx page: “The file could not be loaded into Web Forms Designer” and some other blablabla…

I know of some workarounds, and this guy Tobin Harris [ ] has summed them up all nicely on one page [ ].

They are not a guaranteed solution however, but in many cases one of the workarounds might help you. If not the case, I read some other workaround somewhere on some site that I can’t remember 🙂  Here we go ! [ ]

It states that the problem is when your custom BasePage class is declared abstract, and this way, the Forms Designer can’t instantiate any of the methods, and thus is unable to build a view of the web page.
The workaround consisted of writing extra code like this:

public class BasePage : System.Web.UI.Page
public abstract class BasePage : System.Web.UI.Page
public virtual void method1()
throw new NotImplementedException();
public abstract void method1()

If you’re developing, you’re in debug mode, and that’s the only time you’ll need the Forms Designer. if you need that crap at all, cause basically it does more bad then good, but it also triggers and fires the annoying error message when directly viewing the HTML code. When deployed, you’ll mostly use a release build, and that’s when your BasePage class will be declared abstract, like it should be.

TechnoratiTechnorati Tags: , , , , ,