WPF ARM64 app crashes on startup, unless assemblies are somewhat forcibly loaded
See original GitHub issueHi, I have been getting BadImageException
’s when loading my WPF app exported as arm64.
These are the publishing settings, but not that it also happens with single file (on/off) and framework-dependant as well.
An attempt was made to load a program with an incorrect format. (0x8007000B)
System.BadImageFormatException
at MS.Win32.PresentationCore.UnsafeNativeMethods.MilCoreApi.RenderOptions_ForceSoftwareRenderingModeForProcess(Boolean fForce)
at System.Windows.Media.RenderOptions.set_ProcessRenderMode(RenderMode value)
at Myapp.App.App_Startup(Object sender, StartupEventArgs e) in App.xaml.cs:line 156
at System.Windows.Application.OnStartup(StartupEventArgs e)
at System.Windows.Application.<.ctor>b__1_0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
The line that triggers the issue looks like this:
RenderOptions.ProcessRenderMode = UserSettings.All.DisableHardwareAcceleration ? RenderMode.SoftwareOnly : RenderMode.Default;
Removing that line just makes the app crash in the next line (a FindResource()
call).
As previously discussed in https://github.com/dotnet/wpf/discussions/6286, at first, I thought it could be related to some of my projects (or dependencies, such as SharpDX) being exported as x86 and failing to load.
So, I decided to export as self-contained + not as single file, to be able to scan all assemblies.
I simply added a method to execute a for loop before the app passed though the line that triggered the crash, calling AssemblyName.GetAssemblyName(name)
for all assemblies in the same folder.
By doing that, the app worked normally (note that if I remove the call to the method that runs over all DLLs, the app crashes). Why does that work?
I can’t do that normally in my app, as I export as a single file.
Accessibility.dll - AnyCPU
clretwrc.dll - Not a valid assembly
clrjit.dll - Not a valid assembly
coreclr.dll - Not a valid assembly
D3DCompiler_47.dll - Not a valid assembly
dbgshim.dll - Not a valid assembly
DirectWriteForwarder.dll - None
hostfxr.dll - Not a valid assembly
hostpolicy.dll - Not a valid assembly
KGySoft.CoreLibraries.dll - AnyCPU
KGySoft.Drawing.dll - AnyCPU
Microsoft.Bcl.AsyncInterfaces.dll - AnyCPU
Microsoft.CSharp.dll - AnyCPU
Microsoft.DiaSymReader.Native.arm64.dll - Not a valid assembly
Microsoft.Extensions.ObjectPool.dll - AnyCPU
Microsoft.VisualBasic.Core.dll - AnyCPU
Microsoft.VisualBasic.dll - AnyCPU
Microsoft.VisualBasic.Forms.dll - AnyCPU
Microsoft.VisualBasic.Forms.resources.dll - AnyCPU
Microsoft.Win32.Primitives.dll - AnyCPU
Microsoft.Win32.Registry.AccessControl.dll - AnyCPU
Microsoft.Win32.Registry.dll - AnyCPU
Microsoft.Win32.SystemEvents.dll - AnyCPU
mscordaccore.dll - Not a valid assembly
mscordaccore_arm64_arm64_6.0.422.16404.dll - Not a valid assembly
mscordbi.dll - Not a valid assembly
mscorlib.dll - AnyCPU
mscorrc.dll - Not a valid assembly
netstandard.dll - AnyCPU
PenImc_cor3.dll - Not a valid assembly
PresentationCore.dll - AnyCPU
PresentationCore.resources.dll - AnyCPU
PresentationFramework-SystemCore.dll - AnyCPU
PresentationFramework-SystemData.dll - AnyCPU
PresentationFramework-SystemDrawing.dll - AnyCPU
PresentationFramework-SystemXml.dll - AnyCPU
PresentationFramework-SystemXmlLinq.dll - AnyCPU
PresentationFramework.Aero.dll - AnyCPU
PresentationFramework.Aero2.dll - AnyCPU
PresentationFramework.AeroLite.dll - AnyCPU
PresentationFramework.Classic.dll - AnyCPU
PresentationFramework.dll - AnyCPU
PresentationFramework.Luna.dll - AnyCPU
PresentationFramework.resources.dll - AnyCPU
PresentationFramework.Royale.dll - AnyCPU
PresentationNative_cor3.dll - Not a valid assembly
PresentationUI.dll - AnyCPU
PresentationUI.resources.dll - AnyCPU
ReachFramework.dll - AnyCPU
ReachFramework.resources.dll - AnyCPU
MyApp.dll - AnyCPU
MyApp.Domain.dll - AnyCPU
MyApp.Native.dll - AnyCPU
MyApp.Util.dll - AnyCPU
MyApp.ViewModel.dll - AnyCPU
SharpDX.Direct3D11.dll - AnyCPU
SharpDX.dll - AnyCPU
SharpDX.DXGI.dll - AnyCPU
sni.dll - Not a valid assembly
System.AppContext.dll - AnyCPU
System.Buffers.dll - AnyCPU
System.CodeDom.dll - AnyCPU
System.Collections.Concurrent.dll - AnyCPU
System.Collections.dll - AnyCPU
System.Collections.Immutable.dll - AnyCPU
System.Collections.NonGeneric.dll - AnyCPU
System.Collections.Specialized.dll - AnyCPU
System.ComponentModel.Annotations.dll - AnyCPU
System.ComponentModel.Composition.dll - AnyCPU
System.ComponentModel.Composition.Registration.dll - AnyCPU
System.ComponentModel.DataAnnotations.dll - AnyCPU
System.ComponentModel.dll - AnyCPU
System.ComponentModel.EventBasedAsync.dll - AnyCPU
System.ComponentModel.Primitives.dll - AnyCPU
System.ComponentModel.TypeConverter.dll - AnyCPU
System.Configuration.ConfigurationManager.dll - AnyCPU
System.Configuration.dll - AnyCPU
System.Console.dll - AnyCPU
System.Core.dll - AnyCPU
System.Data.Common.dll - AnyCPU
System.Data.DataSetExtensions.dll - AnyCPU
System.Data.dll - AnyCPU
System.Data.Odbc.dll - AnyCPU
System.Data.OleDb.dll - AnyCPU
System.Data.SqlClient.dll - AnyCPU
System.Design.dll - AnyCPU
System.Diagnostics.Contracts.dll - AnyCPU
System.Diagnostics.Debug.dll - AnyCPU
System.Diagnostics.DiagnosticSource.dll - AnyCPU
System.Diagnostics.EventLog.dll - AnyCPU
System.Diagnostics.EventLog.Messages.dll - AnyCPU
System.Diagnostics.FileVersionInfo.dll - AnyCPU
System.Diagnostics.PerformanceCounter.dll - AnyCPU
System.Diagnostics.Process.dll - AnyCPU
System.Diagnostics.StackTrace.dll - AnyCPU
System.Diagnostics.TextWriterTraceListener.dll - AnyCPU
System.Diagnostics.Tools.dll - AnyCPU
System.Diagnostics.TraceSource.dll - AnyCPU
System.Diagnostics.Tracing.dll - AnyCPU
System.DirectoryServices.AccountManagement.dll - AnyCPU
System.DirectoryServices.dll - AnyCPU
System.DirectoryServices.Protocols.dll - AnyCPU
System.dll - AnyCPU
System.Drawing.Common.dll - AnyCPU
System.Drawing.Design.dll - AnyCPU
System.Drawing.dll - AnyCPU
System.Drawing.Primitives.dll - AnyCPU
System.Dynamic.Runtime.dll - AnyCPU
System.Formats.Asn1.dll - AnyCPU
System.Globalization.Calendars.dll - AnyCPU
System.Globalization.dll - AnyCPU
System.Globalization.Extensions.dll - AnyCPU
System.IO.Compression.Brotli.dll - AnyCPU
System.IO.Compression.dll - AnyCPU
System.IO.Compression.FileSystem.dll - AnyCPU
System.IO.Compression.Native.dll - Not a valid assembly
System.IO.Compression.ZipFile.dll - AnyCPU
System.IO.dll - AnyCPU
System.IO.FileSystem.AccessControl.dll - AnyCPU
System.IO.FileSystem.dll - AnyCPU
System.IO.FileSystem.DriveInfo.dll - AnyCPU
System.IO.FileSystem.Primitives.dll - AnyCPU
System.IO.FileSystem.Watcher.dll - AnyCPU
System.IO.IsolatedStorage.dll - AnyCPU
System.IO.MemoryMappedFiles.dll - AnyCPU
System.IO.Packaging.dll - AnyCPU
System.IO.Pipes.AccessControl.dll - AnyCPU
System.IO.Pipes.dll - AnyCPU
System.IO.Ports.dll - AnyCPU
System.IO.UnmanagedMemoryStream.dll - AnyCPU
System.Linq.dll - AnyCPU
System.Linq.Expressions.dll - AnyCPU
System.Linq.Parallel.dll - AnyCPU
System.Linq.Queryable.dll - AnyCPU
System.Management.dll - AnyCPU
System.Memory.dll - AnyCPU
System.Net.dll - AnyCPU
System.Net.Http.dll - AnyCPU
System.Net.Http.Json.dll - AnyCPU
System.Net.HttpListener.dll - AnyCPU
System.Net.Mail.dll - AnyCPU
System.Net.NameResolution.dll - AnyCPU
System.Net.NetworkInformation.dll - AnyCPU
System.Net.Ping.dll - AnyCPU
System.Net.Primitives.dll - AnyCPU
System.Net.Quic.dll - AnyCPU
System.Net.Requests.dll - AnyCPU
System.Net.Security.dll - AnyCPU
System.Net.ServicePoint.dll - AnyCPU
System.Net.Sockets.dll - AnyCPU
System.Net.WebClient.dll - AnyCPU
System.Net.WebHeaderCollection.dll - AnyCPU
System.Net.WebProxy.dll - AnyCPU
System.Net.WebSockets.Client.dll - AnyCPU
System.Net.WebSockets.dll - AnyCPU
System.Numerics.dll - AnyCPU
System.Numerics.Vectors.dll - AnyCPU
System.ObjectModel.dll - AnyCPU
System.Printing.dll - None
System.Private.CoreLib.dll - AnyCPU
System.Private.DataContractSerialization.dll - AnyCPU
System.Private.ServiceModel.dll - AnyCPU
System.Private.ServiceModel.resources.dll - AnyCPU
System.Private.Uri.dll - AnyCPU
System.Private.Xml.dll - AnyCPU
System.Private.Xml.Linq.dll - AnyCPU
System.Reflection.Context.dll - AnyCPU
System.Reflection.DispatchProxy.dll - AnyCPU
System.Reflection.dll - AnyCPU
System.Reflection.Emit.dll - AnyCPU
System.Reflection.Emit.ILGeneration.dll - AnyCPU
System.Reflection.Emit.Lightweight.dll - AnyCPU
System.Reflection.Extensions.dll - AnyCPU
System.Reflection.Metadata.dll - AnyCPU
System.Reflection.Primitives.dll - AnyCPU
System.Reflection.TypeExtensions.dll - AnyCPU
System.Resources.Extensions.dll - AnyCPU
System.Resources.Reader.dll - AnyCPU
System.Resources.ResourceManager.dll - AnyCPU
System.Resources.Writer.dll - AnyCPU
System.Runtime.Caching.dll - AnyCPU
System.Runtime.CompilerServices.Unsafe.dll - AnyCPU
System.Runtime.CompilerServices.VisualC.dll - AnyCPU
System.Runtime.dll - AnyCPU
System.Runtime.Extensions.dll - AnyCPU
System.Runtime.Handles.dll - AnyCPU
System.Runtime.InteropServices.dll - AnyCPU
System.Runtime.InteropServices.RuntimeInformation.dll - AnyCPU
System.Runtime.Intrinsics.dll - AnyCPU
System.Runtime.Loader.dll - AnyCPU
System.Runtime.Numerics.dll - AnyCPU
System.Runtime.Serialization.dll - AnyCPU
System.Runtime.Serialization.Formatters.dll - AnyCPU
System.Runtime.Serialization.Json.dll - AnyCPU
System.Runtime.Serialization.Primitives.dll - AnyCPU
System.Runtime.Serialization.Xml.dll - AnyCPU
System.Security.AccessControl.dll - AnyCPU
System.Security.Claims.dll - AnyCPU
System.Security.Cryptography.Algorithms.dll - AnyCPU
System.Security.Cryptography.Cng.dll - AnyCPU
System.Security.Cryptography.Csp.dll - AnyCPU
System.Security.Cryptography.Encoding.dll - AnyCPU
System.Security.Cryptography.OpenSsl.dll - AnyCPU
System.Security.Cryptography.Pkcs.dll - AnyCPU
System.Security.Cryptography.Primitives.dll - AnyCPU
System.Security.Cryptography.ProtectedData.dll - AnyCPU
System.Security.Cryptography.X509Certificates.dll - AnyCPU
System.Security.Cryptography.Xml.dll - AnyCPU
System.Security.dll - AnyCPU
System.Security.Permissions.dll - AnyCPU
System.Security.Principal.dll - AnyCPU
System.Security.Principal.Windows.dll - AnyCPU
System.Security.SecureString.dll - AnyCPU
System.ServiceModel.dll - AnyCPU
System.ServiceModel.Duplex.dll - AnyCPU
System.ServiceModel.Http.dll - AnyCPU
System.ServiceModel.NetTcp.dll - AnyCPU
System.ServiceModel.Primitives.dll - AnyCPU
System.ServiceModel.Security.dll - AnyCPU
System.ServiceModel.Syndication.dll - AnyCPU
System.ServiceModel.Web.dll - AnyCPU
System.ServiceProcess.dll - AnyCPU
System.ServiceProcess.ServiceController.dll - AnyCPU
System.Speech.dll - AnyCPU
System.Text.Encoding.CodePages.dll - AnyCPU
System.Text.Encoding.dll - AnyCPU
System.Text.Encoding.Extensions.dll - AnyCPU
System.Text.Encodings.Web.dll - AnyCPU
System.Text.Json.dll - AnyCPU
System.Text.RegularExpressions.dll - AnyCPU
System.Threading.AccessControl.dll - AnyCPU
System.Threading.Channels.dll - AnyCPU
System.Threading.dll - AnyCPU
System.Threading.Overlapped.dll - AnyCPU
System.Threading.Tasks.Dataflow.dll - AnyCPU
System.Threading.Tasks.dll - AnyCPU
System.Threading.Tasks.Extensions.dll - AnyCPU
System.Threading.Tasks.Parallel.dll - AnyCPU
System.Threading.Thread.dll - AnyCPU
System.Threading.ThreadPool.dll - AnyCPU
System.Threading.Timer.dll - AnyCPU
System.Transactions.dll - AnyCPU
System.Transactions.Local.dll - AnyCPU
System.ValueTuple.dll - AnyCPU
System.Web.dll - AnyCPU
System.Web.HttpUtility.dll - AnyCPU
System.Web.Services.Description.dll - AnyCPU
System.Web.Services.Description.resources.dll - AnyCPU
System.Windows.Controls.Ribbon.dll - AnyCPU
System.Windows.Controls.Ribbon.resources.dll - AnyCPU
System.Windows.dll - AnyCPU
System.Windows.Extensions.dll - AnyCPU
System.Windows.Forms.Design.dll - AnyCPU
System.Windows.Forms.Design.Editors.dll - AnyCPU
System.Windows.Forms.Design.resources.dll - AnyCPU
System.Windows.Forms.dll - AnyCPU
System.Windows.Forms.Primitives.dll - AnyCPU
System.Windows.Forms.Primitives.resources.dll - AnyCPU
System.Windows.Forms.resources.dll - AnyCPU
System.Windows.Input.Manipulations.dll - AnyCPU
System.Windows.Input.Manipulations.resources.dll - AnyCPU
System.Windows.Presentation.dll - AnyCPU
System.Xaml.dll - AnyCPU
System.Xaml.resources.dll - AnyCPU
System.Xml.dll - AnyCPU
System.Xml.Linq.dll - AnyCPU
System.Xml.ReaderWriter.dll - AnyCPU
System.Xml.Serialization.dll - AnyCPU
System.Xml.XDocument.dll - AnyCPU
System.Xml.XmlDocument.dll - AnyCPU
System.Xml.XmlSerializer.dll - AnyCPU
System.Xml.XPath.dll - AnyCPU
System.Xml.XPath.XDocument.dll - AnyCPU
UIAutomationClient.dll - AnyCPU
UIAutomationClient.resources.dll - AnyCPU
UIAutomationClientSideProviders.dll - AnyCPU
UIAutomationClientSideProviders.resources.dll - AnyCPU
UIAutomationProvider.dll - AnyCPU
UIAutomationProvider.resources.dll - AnyCPU
UIAutomationTypes.dll - AnyCPU
UIAutomationTypes.resources.dll - AnyCPU
vcruntime140_cor3.dll - Not a valid assembly
WindowsBase.dll - AnyCPU
WindowsBase.resources.dll - AnyCPU
WindowsFormsIntegration.dll - AnyCPU
WindowsFormsIntegration.resources.dll - AnyCPU
wpfgfx_cor3.dll - Not a valid assembly
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
Marking this as closed since the PR for this is already merged and will be available in servicing release 6.0.6. Thanks! #6496
Yeah, with .NET 7 Preview 3, the app loads normally.