This post has already been read 932 times!
The other day I truly had a dumbstruck, absolutely floored, speechless moment. I tried to run SQL Server Management Studio and was presented with an error telling me that an exception has been thrown by the target of an invocation. Well that error message was about as helpful as the first time I ever saw the Object reference not set to an instance of an object error. And as I stared blankly at my monitor, I thought….. ‘I have nothing’.
Exception Thrown By The Target Of An Invocation
Pro Tip: to skip all the details and go straight to the solution, see the ‘Take Away – The Gist’ section at the end of this article.
In retrospect, the error message is quite descriptive. The target of what I am trying to invoke threw an error. So I tried starting Visual Studio and saw the same error. Again, there was that moment… nothing.
Thank goodness that I tried running SYSPRO 7 after that. When I tried to log on to the company, I got an error telling me that it could not establish a SQL connection because it could not find a specific DLL at the specific file path. And that my dear friends, is what got me thinking. Why can’t SYSPRO find that DLL?
Exception Thrown – A Moment Of Clarity
So this got me thinking, if the DLL file was there (I checked) why could Windows not find it? I could also not run Notepad or Remote Desktop Connection and all their icons were missing and showing as unrecognized files.
I then decided to go and look at my Environment Variables because I saw that the shortcut to the applications made use of the environment variables. So in the Control Panel under System, I clicked on ‘Advanced system settings’ and Windows 7 displayed this gem of a message to me. Refer to the Gandalf gif above.
Ok, so I had to go the long way round to view the Environment Variables. Click on SystemPropertiesAdvanced.exe in the System32 sub-folder in Windows.
When System Properties open up, click on the Environment Variables button to view and edit these values.
First thing I checked was windir which seemed fine.
Then I noticed the Path variable. The value of this was insanely long. I was so dumbfounded, I checked this in the registry editor to be sure.
So in HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment you will see the Path value. To give you an idea of what this variable contained, look here:
That is a total of 2473 characters. So I Googled the problem and it seems as though it is a common issue. It seems as though as soon as the Path variable exceeds 2048 characters, other variables such as windir stop working. What I did was delete many of the entries from this Path variable (you will notice, the paths are separated by a semicolon), and after a reboot, everything started working fine again.
Take Away – The Gist
If you are seeing these errors, do the following:
- Run the following program – c:windowssystem32systempropertiesadvanced.exe
- Check the length of the Path variable by pasting it into a word document and check the character count
- Remove some of the entries until the length is under 2048 characters
- Reboot your PC
I am not sure if there are any other causes for the errors described above, but on my Windows 7 machine, this is what solved it. After I fixed this, my applications (Visual Studio, SQL Server and SYSPRO 7) immediately started working and my Notepad, Remote Desktop Connection and icons all returned after a reboot.