Reputation: 5525
I have created a .NET 4 desktop application that runs nicely on a variety of Windows-7 based PCs, both with and without Visual Studio installed. The target PC needs to have .NET framework 4 client profile and extended profile.
However, when I try running the same application on a Vista PC (this is the only PC I have with Vista, I haven't checked others so Vista may not be the blame) with .NET 4 installed, I get this exception, which I can't figure out:
Exception object: 01dc1bb4
Exception type: System.BadImageFormatException
Message: Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The module was expected to contain an assembly manifest.
InnerException: System.BadImageFormatException, Use !PrintException 01dc25d8 to see more.
StackTrace (generated):
SP IP Function
0029E264 6F98249A mscorlib_ni!System.ModuleHandle.ResolveMethodHandleInternalCore(System.Reflection.RuntimeModule, Int32, IntPtr[], Int32, IntPtr[], Int32)+0x8a
0029E29C 6F97B4E2 mscorlib_ni!System.ModuleHandle.ResolveMethodHandleInternal(System.Reflection.RuntimeModule, Int32, System.RuntimeTypeHandle[], System.RuntimeTypeHandle[])+0x42
0029E2C4 6F97AFFF mscorlib_ni!System.Reflection.CustomAttributeData..ctor(System.Reflection.RuntimeModule, System.Reflection.CustomAttributeRecord)+0x37
0029E448 6F97AF97 mscorlib_ni!System.Reflection.CustomAttributeData.GetCustomAttributes(System.Reflection.RuntimeModule, Int32)+0x53
0029E464 6F97C887 mscorlib_ni!System.Reflection.CustomAttributeData.GetCustomAttributesInternal(System.Reflection.RuntimeAssembly)+0x47
0029E480 6F97C825 mscorlib_ni!System.Reflection.RuntimeAssembly.GetCustomAttributesData()+0x5
0029E484 6F97C815 mscorlib_ni!System.Reflection.CustomAttributeData.GetCustomAttributes(System.Reflection.Assembly)+0x21
0029E490 6F97C5C9 mscorlib_ni!System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(System.Reflection.Assembly, System.Resources.UltimateResourceFallbackLocation ByRef)+0x31
0029E4DC 6F97C515 mscorlib_ni!System.Resources.ResourceManager.CommonSatelliteAssemblyInit()+0x6d
0029E4F8 6F97C439 mscorlib_ni!System.Resources.ResourceManager..ctor(System.String, System.Reflection.Assembly)+0x51
0029E510 009CF7DB Microsoft_Practices_Composite_ba0000!Microsoft.Practices.Composite.Properties.Resources.get_ResourceManager()+0x9b
0029E53C 009CF700 Microsoft_Practices_Composite_ba0000!Microsoft.Practices.Composite.Properties.Resources.get_DefaultTextLoggerPattern()+0x20
0029E550 009CF585 Microsoft_Practices_Composite_ba0000!Microsoft.Practices.Composite.Logging.TextLogger.Log(System.String, Microsoft.Practices.Composite.Logging.Category, Microsoft.Practices.Composite.Logging.Priority)+0x35
0029E5CC 009CF359 Microsoft_Practices_Composite_UnityExtensions_b70000!Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run(Boolean)+0x99
0029E624 009CF2A4 Microsoft_Practices_Composite_UnityExtensions_b70000!Microsoft.Practices.Composite.UnityExtensions.UnityBootstrapper.Run()+0x24
0029E630 009CF054 iToldem!ClientBootstrapper.App.OnStartup(System.Windows.StartupEventArgs)+0x54
0029E648 009CEF43 PresentationFramework_4310000!System.Windows.Application.<.ctor>b__1(System.Object)+0x33
0029E658 009CC04D WindowsBase_4a00000!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0xfd
0029E67C 009CBED0 WindowsBase_4a00000!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x40
0029E6C4 009CBAC6 WindowsBase_4a00000!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object, Int32, System.Delegate)+0x36
0029E6E4 009CEE4D WindowsBase_4a00000!System.Windows.Threading.DispatcherOperation.InvokeImpl()+0x5d
0029E714 009CEDD9 WindowsBase_4a00000!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)+0x29
0029E71C 6F974DB5 mscorlib_ni!System.Threading.ExecutionContext.runTryCode(System.Object)+0x51
0029EBC0 6F974CBA mscorlib_ni!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+0x6a
0029EBD8 6F977FC2 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)+0x7e
0029EBFC 6F977F34 mscorlib_ni!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)+0x2c
0029EC18 009CED00 WindowsBase_4a00000!System.Windows.Threading.DispatcherOperation.Invoke()+0x50
0029EC54 009CE8B7 WindowsBase_4a00000!System.Windows.Threading.Dispatcher.ProcessQueue()+0x1a7
0029EC94 009CE5D4 WindowsBase_4a00000!System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0x64
0029ECE8 009CC253 WindowsBase_4a00000!MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)+0xb3
0029ED34 009CC17F WindowsBase_4a00000!MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)+0x6f
0029ED44 009CC04D WindowsBase_4a00000!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)+0xfd
0029ED68 009CBED0 WindowsBase_4a00000!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)+0x40
0029EDB0 009CBAC6 WindowsBase_4a00000!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate, System.Object, Int32, System.Delegate)+0x36
0029EDD0 009CB82B WindowsBase_4a00000!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)+0x8b
0029EE18 009CB29F WindowsBase_4a00000!MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)+0x19f
0029EFE4 009CDFBB WindowsBase_4a00000!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)+0xab
0029F034 009CDE2E WindowsBase_4a00000!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)+0x2e
0029F040 009CDD5A PresentationFramework_4310000!System.Windows.Application.RunDispatcher(System.Object)+0x2a
0029F04C 009CD987 PresentationFramework_4310000!System.Windows.Application.RunInternal(System.Windows.Window)+0x167
0029F060 009CD67A PresentationFramework_4310000!System.Windows.Application.Run(System.Windows.Window)+0x2a
0029F070 009CD62F PresentationFramework_4310000!System.Windows.Application.Run()+0x5f
0029F07C 009C00B1 MyApplication!ClientBootstrapper.App.Main()+0x41
StackTraceString: <none>
HResult: 80131018
My questions are:
Additional information: I have compiled a simple console application and a simple WPF application, both worked fine on that target PC, which leads me to believe that my original application is the blame - but how can I track it down?
Edit: The problem was eventually solved by completely uninstalling .NET 4 and reinstalling it. Weirdly, most .NET apps actually worked despite the fact the installation wasn't good.
Upvotes: 1
Views: 1499
Reputation: 5525
Turned out the .NET framework 4 installation was corrupted somehow. After uninstalling it completely and reinstalling it, everything was in order.
Upvotes: 1
Reputation: 6617
This type of execption is usually a result of trying to run an app with mixed DLLs 32 bit and 64 bit.
The main rule is that an application can only contain asssemblies (and dependencies of those assemblies) that are ALL of the same type, 32bit or 64 bit.
If you build your app using x64 or x86 settings then the app will be purely x64 or x86.
The catch: if you build your application using Any CPU
setting then the JIT (Just In Time) compiler will choose at runtime. And if the underlying OS is x64 then the JIT will choose x64 but if you have a 32bit dependency somewhere then you will get the exception at runtime.
As a general rule, try to set the build type specifically to either x86 or x64.
Upvotes: 0