Error: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) RRS feed

  • Question

  • I have a windows service written in .NET.  Target platform is 2.0 and Processor is AnyCPU.  The service runs fine on many servers.  However on one Windows 2003 SBS SP2 x86 server with .NET 2.0 SP2 installed I get the following error:

    Error: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

    This is not at immediate startup.  In fact many debug statements get logged to the event log.  I have narrowed down the offending line to be the instantiation of a web service (which my service uses):


    Private MyWebSvc As TossMon.MyWebService
    MyWebSvc = New TossMon.MyWebService()   <---  Exception gets thrown

    Most of the research says this is a x64 vs x86 issue but I don't see that here from what I can tell.  Everything is x86 and there is no funny external dll being called.  Just a regular external web reference being instantiated.  How can I go about figuring out what's going on ?


    Here is the stack trace:

    Error: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) Stack: at Microsoft.Win32.Win32Native.SHGetFolderPath(IntPtr hwndOwner, Int32 nFolder, IntPtr hToken, Int32 dwFlags, StringBuilder lpszPath)

    at System.Environment.GetFolderPath(SpecialFolder folder)

    at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)

    at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)

    at System.Configuration.Internal.ConfigurationManagerInternal.System.Configuration.Internal.IConfigurationManagerInternal.get_ExeProductName()

    at System.Configuration.ApplicationSettingsBase.get_Initializer()

    at System.Configuration.ApplicationSettingsBase.CreateSetting(PropertyInfo propInfo)

    at System.Configuration.ApplicationSettingsBase.EnsureInitialized()

    at System.Configuration.ApplicationSettingsBase.get_Properties()

    at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)

    at System.Configuration.SettingsBase.get_Item(String propertyName)

    at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)

    at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)

    at TossW32Agent.My.MySettings.get_TossW32Agent_TossMon_TossMonWebService() in C:\Users\hfamili\Documents\Projects\TossW32Agent\My Project\Settings.Designer.vb:line 63

    at TossW32Agent.TossMon.TossMonWebService..ctor() in C:\Users\hfamili\Documents\Projects\TossW32Agent\Web References\TossMon\Reference.vb:line 62

    at TossW32Agent.TossW32Service.ServiceMain() in C:\Users\hfamili\Documents\Projects\TossW32Agent\TossW32Service.vb:line 134


    Source: mscorlib





    Tuesday, December 28, 2010 10:42 PM


  • Ok, so I used Process Monitor (procmon.exe) and it gave me the clue we needed.  Right before crashing I saw it accessing c:\windows\system32\shfolder.dll - which sounded like close territory as the stack trace stopped while calling SHGetFolderPath().  So I go to look at the file and when I right click on it, it doesn’t show me the dll version (which normally windows does).  So I renamed the file to .bad and (I guess) windows must have a protection scheme because it recreated the file automatically. And this time, the dll version shows up properly.  I ran service and viola it’s running!  Go figure - a corrupted windows dll. 
    • Marked as answer by Heems Tuesday, December 28, 2010 11:42 PM
    Tuesday, December 28, 2010 11:42 PM