Sometimes it works, sometimes not

This is not good!
If something in your software is dependent from the combination of

  1. current weather in London (weather there changes very often, and you and your system actually sits in Sydney)
  2. the mood of your girlfriend (or wife) this morning and
  3. amount of nuts in your muesli in your breakfast bowl

you have a big problem

 

I can’t run tests anymore with MsTest
“Sometimes I can”
... and I am not sure if this is the fault of the latest TFS KB Update... Since we moved to TFS2010 we had to install this KB to work with VS2008 an TFS2010

When I try to run my tests I get this error

clip_image002

Same problem as Gabriel had described in his post about Error: "Exception has been thrown by the target of an invocation."
His solution: none. Over time it was fine :-)

To reproduce this I can easily do

  1. Start VS2008
  2. Go to “Test” | “Windows” | “Test Results”
  3. Error message!

image

I had a couple of things installed like: Resharper, Testdriven.Net, Coderush, … and was not sure what it is…
The last thing I installed was the KB article about using VS2008 with TFS2010.

What I did and didn’t help:

  • Start up Visual Studio in safe mode (parameter /SafeMode )
  • Start up Visual Studio and reset user data (parameter /resetuserdata )

---------------------------------
Note: I hate to do a /resetuserdata because it looses all my “nice” settings like:

  • Removing animations and speedup start of VS
  • Changing F1 keyboard key to do NOTHING (That’s a big one!) ( -> Tools -> Options –> Environment –> Keyboard –> F1 “Remove” )
  • Track Active Item in Solution Explorer ( -> Tools -> Options -> Projects and Solutions  )

More of this settings can be found on stackoverflow Visual Studio optimizations
---------------------------------

 

After all that, I attached another VS to the other one running with “Debug” –> “Attach to process” and enabling all exceptions in “Debug” –> “Exceptions”

---------------------------------
Note: I saw a lot of Resharper exceptions once I start to open a solution and browsing through files…
exceptions in VSActionManager.cs, VSProjectInfo.cs, VSSolutionManager.cs, …
---------------------------------

BUT NO EXCEPTION when I tried to reproduce the problem!
image 
Figure: The top VS2008 is attached to the lower one (that reproduces the error).

Fix: None so far
but I was able to run the tests (and to see my “Test results” window) sometimes.

I think it must be a weird combination of “devenv /safemode”, “Open solution”, “Build”, “Clean”, “Rebuild”, “Cross fingers”, “Run all tests”… Or maybe the other combination mentioned at the top of the post.
Didn’t figure it out yet

Will update this post once I know!

Tools that I use and that are not on Scott Hanselman’s list of tools

I did a new install of Win7 RC last Saturday morning (my quickest install ever with my new SSD HD!!) During the install I wrote down the tools that I installed. I realised some of them are not on Scott Hanselman’s tools list! But almost all are mentioned in the comments on his blog post

This is the list of tools that I always install
And these are NOT on Scott’s tool list

Total Commander
File manager - the german “swiss army knife”. The best tool ever! Replaces Windows File Explorer, Winzip, Winrar, Beyond compare, FTP tools, …and more!

Fullshot
Screenshot utility - Don’t really like SnagIt, because its harder to use

Stroke It - Don’t be just a keyboard jed
Mouse gesture to the max - I used Symbol Commander, Sensiva in the past, but Stroke It is free

Stardock Fences
Organizes my desktop, and double-click  hide icons is great for presentations

SharpReader
My blog reader of choice, I know its old and they didn’t release a version since a couple of months / years …. but it just works

Shortkeys
Text replacement - I got used to that one and have 20 short cuts in there, don’t want to migrate to autohotkey…. to painful

Browser Selector
Depending on the URL that I click on emails it opens different browser, great! and other features described in this blog post about Browser Selector

Free Download Manager
1. Save all downloads in 1 place (FireFox, IE, …) 2. Resume downloads and 3. free

WinPatrol
Like “autorun” from sysinternals but keeps my system healthy in the background. If there is a change in my system –> Warning

irfanview
My picture viewer of choice. fast and shows all file extensions in the world

SSMS Tools
Enhances SQL Management Studio with features like: Create INSERT INTO script for table …

Nmap
If you don’t know it you don’t need it

mRemote
Save all your RDP, SSH, VNC connections in 1 place and connect by double click

 

Scott uses different tools and that is good.

My comments

What I found strange that there is no mouse gestures tool. I think he is a keyboard master and is not using a mouse at all probably :-) Or he is using some authotkey script for mouse gestures…

There is no file manager in Scott’s list. Just FAR file manager (DOS, crazy!!)  :-(

Firefox as default browser and IE for SharePoint

If you are using more than 1 browser in your daily work life, make sure to use the small little “Browser Selector” tool from Marco

The good thing for me is:

  • Firefox is my default browser (web apps like gmail, wave, … just work nicer)
  • Opera is for reading (reading, zooming, 100 open tabs: Opera is still FAST)
  • IE is for Microsoft sites like SharePoint, MS CRM, … (that require IE or Kerberos authentication)

My configuration looks like this

<?xml version="1.0" encoding="utf-8" ?>
<BrowserSelector>
  <Rules>
    <Rule Url="microsoft.com" Browser="IE" />
    <Rule Url="msdn.com" Browser="IE" />
    <Rule Url="msn.com" Browser="IE" />
    <Rule Url="live.com" Browser="IE" />
    <Rule Url="sharepoint.ssw.com.au" Browser="IE" />
    <Rule Url="crm.ssw.com.au" Browser="IE" />
    <Rule Url="intranet.ssw.com.au" Browser="IE" />
-------SNIP SNIP SNIP SNIP -------
  </Rules>
  <Browsers>
    <Browser Name="Firefox" Path="C:\Program Files (x86)\Mozilla Firefox\firefox.exe" Default="true" />
    <Browser Name="Opera" Path="C:\Program Files (x86)\Opera\opera.exe" />
    <Browser Name="IE" Path="C:\Program Files (x86)\Internet Explorer\iexplore.exe" />
  </Browsers>
</BrowserSelector>

Get it from the dedicated “Browser selector” project page

VB.NET Aaaarrrrggghhh - The missing return statement doesn’t give a compile error

Today I found another reason why i don’t like VB.NET

I forgot (commented out) the Return statement in a function (see below) to test different LINQ operators.
During running and later debugging my application I got strange LINQ runtime errors (1 result set is Nothing) …

Public Function PerformSearch(ByVal dc As myDataContext, _
                                  ByVal searchString As String, _
                                  ByVal memberId As Long) _
                    As IQueryable(Of SearchResult)

        searchString = GetFulltextSearchString(searchString)
       
        Dim q = From fulltextSearch In _
       '  -- SNIP SNIP -- removed LINQ code for blog

        ' Return q
    End Function

Figure: VB.NET function without a return statement

 

After a while I realized that the function doesn’t return nothing! But NO COMPILE ERROR! WTF???

image
Figure: BAD: No compile error

The compiler says: Warning “Function ‘PerformSearch’ doesn’t return a value on all code paths. A null reference exception could occur at run time when result is used.”

I realized that myself after a while :-| 

 

image  
Figure: BAD: Visual Studio shows me a curly line underneath “End Function” – but then I have to mouse hover to actually see the problem

 

The weird thing is, that this is by convention (from MSDN) : If the function/procedure doesn’t assign a value to the function-name AND doesn’t use the “Return” statement the function returns the default value of the return type (=Nothing (null) in my case…)  :-(

My recommendations:

  • Always use the “Return” statement in VB.NET (when I don’t forget it ;-) ) instead of assigning a value to the “procedure name” and having “Exit Function”. Its just easier to read!
  • And to make the execution flow more easier to read, I prefer a “return” statement as last line of a method/function/procedure

See this BAD example

Public Function CalcMyValue(ByVal x As Integer, ByVal y As Integer) As Integer

        Dim returnValue As Integer
        If (x > 100 And y > 365) Then
            Return 1
        Else
            If (x > 100 And y > 365) Then
                returnValue = x * 1000
            Else
                Return -1
            End If
        End If
        returnValue = returnValue * 7
        Return returnValue

    End Function

Figure: Bad example with mix of return statements in the middle 

Note
There is a Visual Studio option per Visual Basic project, to set the “compile warning” to a “compile error”
List with all warnings in VB on MSDN

image
Figure: Why is this an option? and why is the default a “Warning”?? WTF

What is --- End of inner exception stack trace ---

Why is my Stack trace split into 2 half's, delimited by “End of inner exception stack trace “??

Example StackTrace from one of my older applications, that manages GPS points

Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException: The type 'Old.Base.DataAccess.ExceptionHandler.OracleExceptionHandler, Old.DataAccess, Version=2.0.0.11969, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. ---> System.ArgumentException: The type 'Old.Base.DataAccess.ExceptionHandler.OracleExceptionHandler, Old.DataAccess, Version=2.0.0.11969, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.AssemblyQualifiedTypeNameConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   at System.ComponentModel.TypeConverter.ConvertFrom(Object value)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.NameTypeConfigurationElement.get_Type()
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.CustomProviderAssembler`3.Assemble(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntryCustomFactory.Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
   at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
   at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, String id, IConfigurationSource configurationSource)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName, ExceptionPolicyFactory factory)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
   at Old.SLFD.PlanManager.DataAccess.OracleODP.ImageSaverDAO.InsertImage(InsertImageParameter imageParam)
   at Old.SLFD.PlanManager.BusinessLogic.ImageManipulationBL.ImportImages(String elencoPtFilename, String imagefolder)
   at Old.SLFD.PlanManager.WinForms.Controls.CreationAndImportImages.StartImport()
   at Old.SLFD.PlanManager.WinForms.Controls.CreationAndImportImages.toolbarsManager_ToolClick_1(Object sender, ToolClickEventArgs e)
   at Infragistics.Win.UltraWinToolbars.ToolClickEventHandler.Invoke(Object sender, ToolClickEventArgs e)
   at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.OnToolClick(ToolClickEventArgs e)
   at Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.FireEvent(ToolbarEventIds id, EventArgs e)
   at Infragistics.Win.UltraWinToolbars.ToolBase.OnToolClick()
   at Infragistics.Win.UltraWinToolbars.ButtonToolUIElement.DoClickProcessing(MouseEventArgs e)
   at Infragistics.Win.UltraWinToolbars.ButtonToolUIElement.OnMouseUp(MouseEventArgs e)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseUpHelper(Object sender, MouseEventArgs e)
   at Infragistics.Win.ControlUIElementBase.ProcessMouseUp(Object sender, MouseEventArgs e)
   at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e)
   at Infragistics.Win.UltraControlBase.OnMouseUp(MouseEventArgs e)
   at Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Figure: ArgumentException in my code.

Long time ago, I was wondering why?

The obvious reason for this, is that an Exception can hold an InnerException (see property in screenshot).

image
Figure: Reflector showing type: Exception


This happens if the exception is caught by some other code in the middle (e.g. Business layer; see difference between layers and tiers with nice pictures and nice list of pro/contra ) and wrapped in a new exception.

In the example above EnterpriseLibrary catches an exception and wraps it into another exception. Enterprise Library has an Exception Handling Application Block that lets you configure policies for your exceptions.
E.g. Handle “SQLException” globally, log and email the exception, then wrap it into “MyCustomException” depending of the property “SqlException.Errors”
That is something similar we did for System.Data.OracleClient.OracleException

Latest Posts

Popular Posts