Jim's Blog Ramblings about novels, comics, programming, and other geek topics

30Aug/0713

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 DotNetKicks.com

29Aug/073

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: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.aspx.

    References:

    My Related Posts: ,
    27Aug/072

    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.

    Feature

    Naming Guidelines

    Namespace

    CompanyName.TechnologyName[.Feature][.Design]

    Pascal case for namespaces

    Example: System.Drawing

    Class

    Use a noun or noun phrase to name a class.

    Use Pascal case.

    Do not use the underscore character.

    Example: AppDomain

    Enumeration

    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)

    Parameter

    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

    Method

    Use verbs or verb phrases to name methods.

    Use Pascal case.

    Example: ToString

    Property

    Use a noun or noun phrase to name properties.

    Use Pascal case.

    Do not use Hungarian notation.

    Example: BackColor

    Event

    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

    Interface

    Use Pascal case.

    Always begins with the prefix I.

    Example: IDisposable

    Abbreviations

    • 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 DotNetKicks.com

    27Aug/070

    San Diego Sunset

    San Diego Sunset - Port of San Diego, North Embarcadero

    San Diego sunset taken from the Port of San Diego, North Embarcadero

    Date of photograph: Aug 8, 2007

    Map of photograph origin: Google Map

    23Aug/071

    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

    Example:

    1 /// <summary>

    2 /// Hello world.

    3 /// </summary>

    4 /// <returns></returns>

    5 public string HelloWorld()

    6 {

    7 return "Hello World";

    8 }

    Notes:

    • 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.
    23Aug/070

    2007 Ultimate Developer and Power Users Tool List for Windows

    Scott Hanselman of Computer Zen creates a list every year with the most indispensable developer utilities. I've found dozens of great utilities and reference material from his previous lists. Here's this year's batch of must have tools.

    Everyone collects utilities, and most folks have a list of a few that they feel are indispensable. Here's mine. Each has a distinct purpose, and I probably touch each at least a few times a week. For me, util means utilitarian and it means don't clutter my tray. If it saves me time, and seamlessly integrates with my life, it's the bomb.

    My Related Posts: ,
    23Aug/070

    5 Popular Design Trends of 2007

    Will Smith of EvoArt.info comments on and provides some illustrations for the emerging design trends originally analyzed by Paul Boag article.

    In five years time things will have no doubt changed even further, but for now its all about big footers, focus on content, and sexy typography!

    The trends are:
    5. F*ck the Fold!
    4. Big, Sexy Fonts.
    3. More Functional Footers.
    2. Textures & Patterns.
    1. Focus on Content & Clear Area Divisions.

    Of the five trends, I've started using more functional footers and trying to divide the content areas into easy to find and use sections. I still try to keep the important parts of the web page above the fold, but with the advent of the wheel mouse, scrolling has become a lot easier than before. At work, I've tried to keep the textures and patterns to a minimum, going for the more minimalist and clean approach over the more edgier and colorful styles.

    My Related Posts: ,
    19Aug/070

    Sunday in the Park with OSCAR®

    The San Diego Symphony performed a free concert today at the Spreckels Organ Pavilion in Balboa Park. Luckily, I just happen to be near the pavilion when the symphony was getting ready. They performed famous songs from movies (OSCAR as in the OSCAR awards).

    Although, I had only seen a handful of the movies, they did play a few theme songs written by the great composer John Williams including the theme from Star Wars, Raiders of the Lost Ark, and Harry Potter. They also played the theme songs from 2001: A Space Odyssey, Wizard of Oz, Ten Commandments (to celebrate the Dead Sea Scrolls exhibit), Breakfast at Tiffany's, and a few more.

    San Diego Symphony at Balboa Park’s Spreckels Organ Pavilion

    Date of photograph: Aug 19, 2007

    18Aug/071

    Simple Speed Testing in .NET – System.Diagnostics.Stopwatch

    One of the biggest problems with the .NET Framework is that so many new features are released with each major version that minor additions and features usually slip through the cracks. In my experience, very few classes have been overlooked during the transition from 1.1 to 2.0 as much as the Stopwatch class (System.Diagnostics.Stopwatch).

    Adam Wolkov writes about a rarely seen or used class within the .NET Framework - System.Diagnostics.Stopwatch. In fact, I had never heard of that class before this article, but most of my work has still been in version 1.1 and I'm just now moving full speed into 2.0 (and 3.5 will probably be out next year!). This little tid bit of info is great and I'm sure I'll use it more and more, since my old way of doing speed tests was just as Adam described - create a DateTime.Now value at the start and then subtract the ending DateTime.Now to get the TimeDuration value that elapsed.

    My Related Posts: ,
    18Aug/070

    Anthology San Diego – Larry Coryell

    A few weeks ago, a few friends and I visited Anthology. Anthology is a new jazz bar/restaurant located in Little Italy and across the street from my new home.

    Larry Coryell - A Renaissance musician who excels at all styles of playing, and a true pioneer of Rock/Jazz Fusion.

    While we were there, we saw Larry Coryell and his band . For one song, his wife took the stage to sing a Tracy Chapman song. His set went for about 1 1/2 hours as we ate and shared a bottle of wine. Although I've never been a jazz fan, this style of music was really great. We had a table in the front row only a few feet from the stage and a three course meal, which was also extremely good.

    While I continue to wait for my friend to make me a CD of various Jazz samples so I can get a better understanding, here's a sample of Larry Coryell's music.