Robert McLaws: FunWithCoding.NET

Public Shared Function BrainDump(ByVal dotNet As String) As [Value]

News

<script type="text/javascript"><!-- google_ad_client = "pub-4330602465258980"; google_hints = "ASP.NET, VB.NET, C#, C#.NET, WindowsForms, .NET Framework, VS2005, Visual Studio, XAML, WinFX, Windows Workflow, WPF, WCF, Atlas, NetFX3, Visual Studio Orcas"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="4997399242"; google_color_border = "B6C9E7"; google_color_bg = "EFEFEF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "002C99"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<!--
-->

You should feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever. That said, I will most likely only delete abusive, profane, rude, or annonymous comments, so keep it polite, please.

Blogroll

Cool .NET Articles

My .NET Tools

My Builder.com Articles

My MSKB Articles

'About Box' forms, the 'My' Namespace, and Class Libraries

In Visual Studio 2005, there is a built-in form called the "About Box". In a VB.NET project, you can add it to your application, and it will automatially display the info that you put in your AssemblyInfo file for the user. It's a pretty neat little addition that makes it just a little bit easier to build an app.

But, as far as I can tell, you can't use it in Class Library projects. Why would you want to? Well, the underlying project type for a Visual Studio Add-in is a Class Library. When you try to display an About Box form as part of a Visual Studio add-in, it will throw an error without warning. That's because, for some reason, the initialization of the My namespace is not passing in the executing assembly to the My.Application.Info default constructor (which maps to Microsoft.VisualBasic.ApplicationServices.AssemblyInfo).

The simple solution is to replace the AboutBox_Load code with the code below:

1    Private Sub AboutBox1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

2 Dim info As New Microsoft.VisualBasic.ApplicationServices.AssemblyInfo(System.Reflection.Assembly.GetExecutingAssembly)
3
4 ' Set the title of the form.
5 Dim ApplicationTitle As String
6 If info.Title <> "" Then
7 ApplicationTitle = info.Title
8 Else
9 ApplicationTitle = System.IO.Path.GetFileNameWithoutExtension(info.AssemblyName)
10 End If
11 Me.Text = String.Format("About {0}", ApplicationTitle)
12 ' Initialize all of the text displayed on the About Box.
13 ' TODO: Customize the application's assembly information in the "Application" pane of the project
14 ' properties dialog (under the "Project" menu).
15 Me.LabelProductName.Text = info.ProductName
16 Me.LabelVersion.Text = String.Format("Version {0}", info.Version.ToString)
17 Me.LabelCopyright.Text = info.Copyright
18 Me.LabelCompanyName.Text = info.CompanyName
19 Me.TextBoxDescription.Text = info.Description
20 End Sub

Basically, I've added a new line to instantiate the AssemblyInfo class manually, and then replaced My.Application.Info with info. The form will then work as it is supposed to.

I've filed this as a bug, but I have a feeling it may not get fixed... so keep this workaround handy in case you need it.

Posted: May 29 2005, 01:16 AM by interscape | with 2 comment(s)
Filed under:

Comments

Dave said:

The line:
If info.Title <> "" Then

is more efficient written as:
If info.Title.Length > 0 Then

Sorry, went into code review mode.
# May 29, 2005 2:43 AM

Robert McLaws said:

Dave, hat was Microsoft's code, not mine. I tried to change as little as possible for the purposes of the example.
# May 29, 2005 3:51 AM