How to tell if a .NET Assembly is debug or release

Google AdSense

Yesterday, I was asked by a ISV developer to check to see if their product was built in debug or release. I didn’t question why a ISV development team would package and deliver debug assemblies to a customer…

The first thing that I did was open up .NET Reflector – a great product from Lutz Roeder that I’ve used for years. However, I wasn’t exactly sure what I was looking for. And the .NET Reflector can’t show attributes that don’t exist, so I didn’t see the Debuggable attribute.

If the assembly was built for debug, then the .NET Reflector would show this line on the Disassembler window:

[assembly: Debuggable(…)]

So since I wasn’t 100% sure of what I was looking for, I wrote a simple function to load an assembly and check to see if it was debug or release.

Assembly assemb = Assembly.LoadFile(Path.GetFullPath(fileName));
bool isDebug = false;
foreach (object att in assemb.GetCustomAttributes(false))
     if (att is DebuggableAttribute)
          isDebug = ((DebuggableAttribute)att).IsJITTrackingEnabled;
Console.WriteLine("Assembly is {0}.", isDebug ? "debug" : "release");

The above code takes the file name of a .NET assembly and then loops through each of the custom attributes assigned to the assembly.  If the assembly was built for debug, then one of the attributes is the type of DebuggableAttribute. Otherwise, if it was built for release, then the DebuggableAttribute will not be found.


Update 9/6/2007: Changed logic to support assemblies using .NET 1.x and 2.0 Frameworks.

My Related Posts: ,

kick it on

CS0030 Compilation Error on Published ASP.NET Web Site

Google AdSense

I ran into this error today and its the first time that I’ve seen it. It’s been around for a few years – since the release of Visual Studio 2005, so it’s probably old news to most people.

This “software feature” only affects users of Visual Studio 2005 Professional (and greater) who use the “Publish Web Site” feature. The “Publish Web Site” feature is not available to Visual Studio Express users.

The error occurs when you have an ASP.NET page located in your root directory (I’ll explain later why you may not see this error in subdirectories) that is named the same as an existing class in the System.Web.UI.WebControls namespace.

For example, my page was named “View.aspx” (class name “View”). Here’s the error message that I found on the published web site. The page runs fine in development and only occurs after you have used the “Publish Web Site” feature.

The reason why you may not see this in subdirectories is because Visual Studio appends the name of the directory to the class’s name. So if the class named “View” was in the subdirectory of “Work”, then Visual Studio automatically names it “Work_View” and there is no naming conflict with the System.Web.UI.WebControls.View class.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0030: Cannot convert type ‘ASP.view_aspx’ to ‘System.Web.UI.WebControls.View’
Source Error:

Line 120: public view_aspx() { 
Line 121: string[] dependencies; 
Line 122: ((View)(this)).AppRelativeVirtualPath = "~/View.aspx"; 
Line 123: if ((global::ASP.view_aspx.@__initialized == false)) { 
Line 124: global::ASP.view_aspx.@__stringResource = this.ReadStringResource();

The Work Around

You will need rename the class associated with the ASP.NET Page to something other than the name you are using.

  1. Open the Page’s Designer and Code pages.
  2. Rename the Page’s class name to something else.
  3. In the code behind page, just append “Page” to the class name such as “public partial class ViewPage : System.Web.UI.Page”
  4. In the design view page, append the same value such as “<%@ Page … CodeFile=”View.aspx.cs” Inherits=”ViewPage“… %>”
  5. Save and Publish your web site.

Here’s a quick list of a few class names to avoid:

  • AdRotator
  • Calendar
  • ChangePassword
  • Content
  • CreateUserWizard
  • DataGrid
  • DataList
  • DetailsView
  • FileUpload
    • GridView
    • Login
    • LoginStatus
    • Menu
    • Style
    • Table
    • View
    • Wizard

    You can find the complete list of class names for the System.Web.UI.WebControls namespace at:


    My Related Posts: ,

    Code Naming Guidelines

    I’ve tried to maintain a consistent set of naming rules for my code. However, sometimes I get into the “zone” of programming and my typing-thread out paces my neat-thread.

    Here’s a few guidelines that I’ve collected over the years. Most of guidelines came from Microsoft’s Design Guidelines for Class Library Developers.


    Naming Guidelines



    Pascal case for namespaces

    Example: System.Drawing


    Use a noun or noun phrase to name a class.

    Use Pascal case.

    Do not use the underscore character.

    Example: AppDomain


    Pascal case for Enum types and value names.

    Use abbreviations sparingly.

    Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields.

    Example: ErrorLevel (type)
    Example: FatalError (value)


    Use camel case.

    Use descriptive parameter names.

    Use names that describe a parameter’s meaning rather than names that describe a parameter’s type.

    Do not prefix parameter names with Hungarian type notation.

    Example: typeName


    Use verbs or verb phrases to name methods.

    Use Pascal case.

    Example: ToString


    Use a noun or noun phrase to name properties.

    Use Pascal case.

    Do not use Hungarian notation.

    Example: BackColor


    Use Pascal case.

    Use an EventHandler suffix on event handler names.

    Consider naming events with a verb. For example, correctly named event names include Clicked, Painting, and DroppedDown. Use a gerund (the “ing” form of a verb) to create an event name that expresses the concept of pre-event, and a past-tense verb to represent post-event. For example, a Close event that can be canceled should have a Closing event and a Closed event. Do not use the BeforeXxx/AfterXxx naming pattern. Do not use a prefix or suffix on the event declaration on the type. For example, use Close instead of OnClose.Do not use Hungarian notation.

    Example: ValueChange
    Example: MouseEventHandler

    Exception Class

    Use Pascal case.

    Always ends with the suffix Exception.

    Example: WebException


    Use Pascal case.

    Always begins with the prefix I.

    Example: IDisposable


    • Do not use abbreviations or contractions as parts of identifier names. For example, use GetWindow instead of GetWin.
    • Do not use acronyms that are not generally accepted in the computing field.
    • Where appropriate, use well-known acronyms to replace lengthy phrase names. For example, use UI for User Interface and OLAP for On-line Analytical Processing.
    • When using acronyms, use Pascal case or camel case for acronyms more than two characters long. For example, use HtmlButton or htmlButton. However, you should capitalize acronyms that consist of only two characters, such as System.IO instead of System.Io.
    • Do not use abbreviations in identifiers or parameter names. If you must use abbreviations, use camel case for abbreviations that consist of more than two characters, even if this contradicts the standard abbreviation of the word.
    My Related Posts: ,

    kick it on

    How to Post Code From Visual Studio to Your Blog

    I use the CopySourceAsHtml add-on for Visual Studio to prepare and format code for my blog. Here’s a simple set of instructions to get your code from Visual Studio into WordPress post.

    1. Download & Install CopySourceAsHtml (link above)
    2. Open your project/solution/web site in Visual Studio
    3. Select your code block
    4. Click “Copy As HTML…” from the Edit menu (or right click menu)
    5. Click the “Code” tab of your Write Post form
    6. Paste the code


    1 /// <summary>

    2 /// Hello world.

    3 /// </summary>

    4 /// <returns></returns>

    5 public string HelloWorld()

    6 {

    7 return “Hello World”;

    8 }


    • If you use the option to use <pre> tags for each line, then the lines will not wrap and will be cut off. (If “Wrap Words” option is unchecked then it uses <pre> tags, if checked then it uses <p> tags). To use <pre> and not have the code truncated, you need to include the styles of “white-space: normal;” in the “Line Style” tab of the dialog.
    • You can enable line numbering and the starting line number. Example above uses 1 as the starting line number.
    • Be sure to uncheck “Include RTF” checkbox, or you will get the RTF code along with the HTML code.

    Word Press bugs:

    • Problems with <div> tags being replaced by <p> tags and the new tags aren’t formatted correctly (resolved)
    • Removes extra spaces (e.g. $nbsp;$nbsp;$nbsp;$nbsp; are removed and replaced with a single space – yes I know it should be an ampersand, but wordpress also converts it to spaces even when entered from the Visual tab.). If you use the $nbsp; markup, the extra spaces will get lost if you edit your post after you post it. If you use <pre> then this will retain the extra spaces, but you’ll need to add the word-wrap style to make long lines wrap in the browsers.