Configuration System Failed to Initialize

05.23.08

Problem: Your application contains User Scope Settings and you receive the exception.

“Configuration system failed to initialize” when attempting to retrieve these settings.

Solution: The settings file has been corrupted and is unreadable. Close or stop your application and delete the user.config file. The file is located at:

C:\Documents and Settings\[UserName]\Local Settings\Application Data\[AppCompany]\[AppName] \[AppVersion]\

If you are in Visual Studio you can easily find the exact file that is causing the problem by viewing the details and drilling down to the inner exception to find the file name.

DotNetNuke Upgrade - My Rant

03.31.08

I have been using DotNetNuke for a year or more now mostly for personal fun projects but I have setup a site for a family business using DNN, nothing explosive and shinny but it has served its purpose. I manage 2 different DotNetNuke installations and I have to say upgrading DNN application (not the modules) is scary. I have yet to do it successfully on my first try. Here are my steps to failure:

1. Backup my SQL Server as well as my site files. This is the most important step because the fallowing steps are sure to fail.

2. Download the latest install or upgrade package for your DotNetNuke application. I have tried upgrading using both the upgrade and install packages with equal success err failure... successful failure?

3. Create an app_offline.htm with some generic text stating that you are doing maintenance on the site blah blah blah.

4. Rename your current web.config to web.config.old

5. Copy contents of the install/upgrade package to your DNN application folder.

6. Rename release.config to web.config.

7. Merge your old web.config with the new web.config. The areas to merge are: Connection Strings, MachineKey, and the codeSubDirectories. I also like to set AutoUpgrade key too false so nobody but me will trigger the installation.

8. Now I navigate to [Domain Name]/install/install.aspx

9. After I watch the list of Successful, or sometimes on Friday and the moon is full I will get a failure, I navigate to my home page of my DNN application to view the wonderful yellow screen. The error displayed is usually different every time or a different flavor of the same variety "Object Null Reference" being my favorite for its descriptiveness [insert sarcasm].

The good news and one of the reasons that I like DNN is it has a great community and I have fixed every problem with the help of people on the forums. Also once it is updated and running it is a solid application and very easy to extend and write custom modules for. I just wish for a one click update and BAM you are getting your "real" work completed. Anyway my SQL Server and root files are done restoring, time for try number two.

Note: Currently DotNetNuke was on version 4.8.2 when I wrote this.

Here are a few tutorials on upgrading your installation: 1 2

Sweet Sweet NUnit on VS2005 Action

09.15.07

This is great! I dont know why I didnt do this earlier, but you can Debug your code and run NUnit at the same time. You just need to set the Debug>Start Action to start external aplication NUnit.exe. Then set your start project to be the same project as your test code and tada you now have debuging and break point goodness wile running nunit.

 

Unable to find the report in the manifest resources. please build the project, and try again.

09.13.07

I was reorganizing a project and I moved a crystal report after that I received this error at runtime "Unable to find the report in the manifest resources. please build the project, and try again." No amount of building could fix this problem. I eventually had to open up the project file in note pad and edit the entries in the xml/MSBUILD.

Here is what a Crystal Report should look like in your MSBUILD script.

<Compile Include="CrystalReport1.cs">
    <AutoGen>True</AutoGen>
    <DesignTime>True</DesignTime>
    <DependentUpon>CrystalReport1.rpt</DependentUpon>
    <SubType>Component</SubType>
</Compile>
<EmbeddedResource Include="CrystalReport1.rpt">
    <Generator>CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator</Generator>
    <LastGenOutput>CrystalReport1.cs</LastGenOutput>
</EmbeddedResource>

After you correct the entry Rename the file Build then rename it again to the old name and build again.

Switching to C# from VB.Net

04.05.07

My current job requires me to jump on the band wagon and start coding in the C# syntax for .Net. For the last year I have been coding in VB.Net and doing all my blog examples in VB.Net and I really started to enjoy that language. The My namespace allowed for quick access to a number of common functions, key words such as AndAlso and OrElse eliminated the need for extra if statements, the background compiler was great finding errors instantly, the VB.Net code is formatted automatically for you (in C# I find my self having to hit ctr+K+D a lot and some times still have to format braces my self), and the lack of {}.[], <>, and () makes the language easy to read.
    My switch to C# was relatively easy I can't quite code as fast as I am able to in VB.Net and I still try to write Dim, forget semicolons, and other little syntax issues like that. I like that C# seems to hide less from you than VB.Net one example is just having the namespace automatically at the top of the page. C# is also less wordy than VB.Net and I can see more of the code that is important to me at one time. Maybe its just because I am new to the language but C# seems to have less ambiguous ways of doing things as well, witch seems to make code from programmer to programmer more consistent. Example of this is casting int from a string in VB you can use Cint(str), Ctype(str,int), Integer.Parse(str), and Val(str). There are a lot of other instances of this in VB.Net I think it has a lot to do with helping the VB 6.0 coders with there transition to .Net.
    All and all it is a refreshing change and I like going back to “C” derived syntax I believe to progress as a programmer you really need to experience in multiple languages.

Throw vs Throw ex - The Why

01.17.07

I was talking to a friend of mine and he found my example of throw vs. throw ex interesting but he asked me a question that I didn’t expect, he asked me, "why?" I simply replied, "I don’t know, just don’t do it." But his insightful question made me curious. The answer to the question is in the real .Net language, the IL. When you compile your C# or VB.Net code just plain Throw becomes ReThrow but if you write Throw ex it becomes throw. In the IL snipit below Look at line 13 for JustThrowIT and line 14 in ThrowEX.

.method private instance void JustThrowIT() cil managed
{
      .maxstack 2
      .locals init (
            [mscorlib]System.Exception exception1)
       L_0000: nop
       L_0001: nop
       L_0002: ldarg.0
       L_0003: callvirt instance void throwDemo.Form1::ThrowsExceptions()
       L_0008: nop
       L_0009: leave.s L_001c
       L_000b: dup
       L_000c: call void [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.ProjectData::SetProjectError([mscorlib]System.Exception)
       L_0011: stloc.0
       L_0012: nop
       L_0013: rethrow
       L_0015: call void [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.ProjectData::ClearProjectError()
       L_001a: leave.s L_001c
       L_001c: nop
       L_001d: nop
       L_001e: ret
       .try L_0002 to L_000b catch [mscorlib]System.Exception handler L_000b to L_001c
}
.method private instance void ThrowEX() cil managed
{
      .maxstack 2
      .locals init (
            [mscorlib]System.Exception exception1)
       L_0000: nop
       L_0001: nop
       L_0002: ldarg.0
       L_0003: callvirt instance void throwDemo.Form1::ThrowsExceptions()
       L_0008: nop
       L_0009: leave.s L_001c
       L_000b: dup
       L_000c: call void [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.ProjectData::SetProjectError([mscorlib]System.Exception)
       L_0011: stloc.0
       L_0012: nop
       L_0013: ldloc.0
       L_0014: throw
       L_0015: call void [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.ProjectData::ClearProjectError()
       L_001a: leave.s L_001c
       L_001c: nop
       L_001d: nop
       L_001e: ret
       .try L_0002 to L_000b catch [mscorlib]System.Exception handler L_000b to L_001c
}
The ReThrow will pass on exception details were the throw is starting from scratch.

Throw vs Throw ex

12.27.06

A common mistake a lot of new .Net developers do is using Throw ex instead of just Throw. The difference between Throw ex and Throw is very simple but can cause major headaches when it comes to maintenance. If you use Throw ex it overwrites the stack trace this makes it very hard to find the original line of the thrown exception as you can see in the example I have provided.
Public Class Form1
    Private Sub ThrowsExceptions()
        Throw New System.Exception("Exception Thrown") 'Line 3
    End Sub
    Private Sub JustThrowIT()
        Try
            ThrowsExceptions()
        Catch ex As Exception
            Throw 'Line 9
        End Try
    End Sub
    Private Sub ThrowEX()
        Try
            ThrowsExceptions()
        Catch ex As Exception
            Throw ex 'Line 16
        End Try
    End Sub
    Private Sub ThrowEX_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click
        Try
            ThrowEX() 'Line 21
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
    Private Sub JustThrowIt_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
        Try
            JustThrowIT() 'Line 29
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub
End Class

When you click the Throw ex button you get only get references to two lines 16 and 21 the original line the exception is thrown is missing(line 3).



When you click the Throw button you get the full stack trace including the line of the original exception that was thrown.



Download Source.
throwDemo.zip (47.73 KB)

Using an Enum as the DataSource for a ComboBox

12.19.06

While working on my spell check app Dyslexic Helper I had to use an Enum (System.Windows.Forms.keys) as a data source for a Combo box I found this to be very easy and very useful. Here is an example of how to do this.
Public Class frmExample
    'Enum to fill the combo box with
    Public Enum Names
        Jim
        Bob
        Dave
        Sam
        Tim
        Jon
        Suse
        Ann
        Sassy
        Silvia
    End Enum
    Private Sub FormExample_Load(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles Me.Load
        'fills the combo box with the names from the Enum Names
        Me.ComboBoxExample.DataSource = System.Enum.GetValues(GetType(Names))
        'selects the last selected name in the combobox
        'My.Settings.Name is defined in the project/properties/settings as a string
        Me.ComboBoxExample.SelectedIndex = Me.ComboBoxExample.FindStringExact(My.Settings.Name)
    End Sub
    Private Sub frmExample_FormClosing(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'saves the selected name in settings as form is closeing
        My.Settings.Name = Me.ComboBoxExample.Text
        My.Settings.Save()
    End Sub
End Class
You can download the source here.

CboExample.zip (50.48 KB)