带有 WPF 桌面桥包的 UWP 中的 System.BadImageFormatException [英] System.BadImageFormatException in UWP with WPF desktop bridge package

查看:48
本文介绍了带有 WPF 桌面桥包的 UWP 中的 System.BadImageFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在本主题中完整详细地描述了问题和疑问

编辑 2: **********************************************************************************************************

我使用 Windows 10 Pro 64 位操作系统,基于 x64 的处理器Visual Studio 2019 版本 16.1.4,目标框架:.NETFramework 4.7.2 Version 4.7.03056, Microsoft.NETCore.Universal Windows Platform 6.2.8 路径文件夹 C:\Program Files (x86)\Microsoft SDKs\Windows 包含文件夹:v7.0Av8.1v8.1Av10.0A

.csproj 中:

 存储库 UWP_desktop_bridge.它是 WPF 的 UWP 和控制台启动器,基于 第 1 部分第 2 部分第 3 部分 <UWP-FullTrust 课程.com/users/686985/stefan-wick-msft" rel="nofollow noreferrer">Stefan Wick MSFT

没有 InitializeAppServiceConnection(); 场景来自 第 1 部分第 2 部分 有效,但将 InitializeAppServiceConnection(); 包含到 WPF InitializeComponent(); 以获得 第 3 部分 功能,我得到:

<块引用>

System.BadImageFormatException HResult=0x80131058 消息=可以不加载文件或程序集 'System.Runtime.WindowsRuntime,版本=4.0.10.0,文化=中性,PublicKeyToken=...' 或它的依赖项之一.不应加载引用程序集执行.它们只能在 Reflection-only 加载器中加载语境.(来自 HRESULT 的异常:0x80131058)Source=WpfApp1
堆栈跟踪:在WpfApp1.MainWindow.d__4.MoveNext() 中C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line59 在System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&状态机)在WpfApp1.MainWindow.InitializeAppServiceConnection() 在WpfApp1.MainWindow..ctor() 中C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line38 内部异常 1:BadImageFormatException:无法加载引用组装执行.

SingleInstance.cs一样,如果使用这部分代码:

[STAThread]public static void Main(string[] args){SingleInstanceManager manager = new SingleInstanceManager();manager.Run(args);}

<块引用>

严重代码描述项目文件行抑制状态错误CS0017 程序定义了多个入口点.编译/main 指定包含入口点的类型.

它的功能和失败与我以前的项目相似.

编辑 5:*********************************************************************************************************

此时,我已经根据ZhuMingHao/AppSerViceTest demo Nico Zhu - MSFT 对相关问题的回答 发送语音识别args.Result作为UWP桌面桥包中的参数:

Debug 成功加载 UWPWPF.在 UWP 中点击 Click 按钮 AppSerViceTest/AppServiceTest/MainPage.xaml.cs:

我遇到了同样的异常:

<块引用>

System.NullReferenceException: '未将对象引用设置为一个对象的实例.

点击WPF Send Message 按钮,它只是关闭WPF 应用程序,UWP StatusBlockInfoBlock 什么也没显示.

直接调试WPF并点击Send message按钮,抛出相同System.BadImageFormatException的不同内容:

<块引用>

System.BadImageFormatException HResult=0x80131058 消息=可以不加载文件或程序集 'System.Runtime.WindowsRuntime,Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' 或其中之一依赖关系.不应为执行加载引用程序集.它们只能在仅反射加载器上下文中加载.(来自 HRESULT 的异常:0x80131058)Source=WpfApp1 StackTrace:
在 WpfApp1.MainWindow.d__5.MoveNext() 中C:\Users\User\Desktop\UWP\UWP_DB_SR\WpfApp1\MainWindow.xaml.cs:line91 在System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&stateMachine) 在 WpfApp1.MainWindow.Button_Click_1(对象发送者,RoutedEventArgs e) 在System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs routedEventArgs) 在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs args, Boolean reRaised) atSystem.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args) 在System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 在System.Windows.Controls.Primitives.ButtonBase.OnClick() 在System.Windows.Controls.Button.OnClick() 在System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgse) 在 System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object发件人,MouseButtonEventArgs e) 在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(委托genericHandler,对象 genericTarget) 在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)在System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs routedEventArgs) 在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs args, Boolean reRaised) atSystem.Windows.UIElement.ReRaiseEventAs(DependencyObject sender,RoutedEventArgs args, RoutedEvent newEvent) 在System.Windows.UIElement.OnMouseUpThunk(对象发送者,MouseButtonEventArgs e) 在System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(委托genericHandler,对象 genericTarget) 在System.Windows.RoutedEventArgs.InvokeHandler(委托处理程序,对象目标)在System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,RoutedEventArgs routedEventArgs) 在System.Windows.EventRoute.InvokeHandlersImpl(对象源,RoutedEventArgs args, Boolean reRaised) atSystem.Windows.UIElement.RaiseEventImpl(DependencyObject sender,RoutedEventArgs args) 在System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) 在System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean受信任)在 System.Windows.Input.InputManager.ProcessStagingArea()在 System.Windows.Input.InputManager.ProcessInput(InputEventArgs输入)在System.Windows.Input.InputProviderSite.ReportInput(InputReport输入报告)在System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd,InputMode 模式,Int32 时间戳,RawMouseActions 动作,Int32 x,Int32 y, Int32 轮)在System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtrhwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean&处理)在System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd,Int32 msg、IntPtr wParam、IntPtr lParam、Boolean&处理)在MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam,IntPtr lParam, Boolean&处理)在MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,Int32 numArgs)在System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调、对象参数、Int32 numArgs、委托 catchHandler)在System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority优先级、时间跨度超时、委托方法、对象参数、Int32numArgs) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd,Int32 msg, IntPtr wParam, IntPtr lParam) atMS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) atSystem.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame帧)在System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame框架)
在 System.Windows.Application.RunDispatcher(Object ignore) 在System.Windows.Application.RunInternal(窗口窗口)在System.Windows.Application.Run(窗口窗口)在System.Windows.Application.Run() 在 WpfApp1.App.Main() 内部异常 1:BadImageFormatException:无法加载引用程序集执行.

解决方案:**********************************************************************************************************

Stefan Wick MSFT 给出的解决方案答案也在 WDC 主题 AppServiceResponse 中的 System.NullReferenceException 和带有 WPF 桌面桥包的 UWP 的 System.BadImageFormatException on System.BadImageFormatException 使用 特定的 UWP 桌面桥应用通信项目,基于 带有桌面扩展的 UWP – 第 3 部分 示例 UWP-FullTrust/UWP_FullTrust_3/ 以及我的 Nico Zhu - MSFT 解决方案 ZhuMingHao/AppSerViceTest:

我的错误:

  • 程序文件 (x86)\参考Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll
  • Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd

必须是正确的参考设置:

  • ProgramFiles(x86)%\Reference程序集\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
  • 程序文件(x86)%\WindowsKits\10\UnionMetadata\10.0.17134.0\Windows.winmd

解决方案

当从非 UWP 项目(WPF、Winforms、控制台等)错误地引用 Windows 运行时库时,会发生此异常.请务必按如下方式引用它们

  1. 在添加引用……"对话框中,单击浏览……"并将过滤器设置为所有文件 (*.*)"
  2. 导航到%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll"
  3. 导航到%ProgramFiles(x86)%\Windows Kits\10\UnionMetadata\{TargetVersion}\Windows.winmd"

I''ve fully and detailed described problem and question in this topic System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package, but still have no found answer, what can cause this failure.

Topic link to Windows Dev Center above describes assembly, shows all used code with examples, including attempts to fix problem, and other details. So I will put only basic part of task in this stackoverflow topic to avoid text overload in post and focus only on System.BadImageFormatException, which provokes App.Connection null in Windows Application Package Project with connection from UWP to WPF application, created according to UWP with Desktop Extension – Part 3 lesson, (sending of request to desktop extension, read registry key values, and sending of request from desktop extension to UWP, handle requests from desktop code).

I've tried fix it different ways (also described above), but can't find any clue of reason, at least to know where to look for problem, maybe I've missed something, but I can't find related useful answers anywhere in internet

This is the message, but the System.Runtime.WindowsRuntime.dll is already in references:

System.BadImageFormatException HResult=0x80131058 Message=Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) Source=WpfApp1
StackTrace: at WpfApp1.MainWindow.d__4.MoveNext() in C:\Users\User\Desktop\UWP\App\WpfApp1\MainWindow.xaml.cs:line 58 at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at WpfApp1.MainWindow.InitializeAppServiceConnection() at WpfApp1.MainWindow..ctor() in C:\Users\User\Desktop\UWP\App\WpfApp1\MainWindow.xaml.cs:line 37 Inner Exception 1: BadImageFormatException: Cannot load a reference assembly for execution.

Any advice, guide or example would be very helpful

EDIT 1: **************************************************************************************************

I've tried all this combinations below two ways Debug and Release, as well as changed Solution platform "compiler settings", from menu bar of VS target from "Any CPU" to "X86 " and vice-versa as shown in System.BadImageFormatException: Could not load file or assembly [duplicate], and from Solution->Properties->Configuration Properties->Configuration->Project contexts as well as from Project->Properties->Build->Platform target, but functionality and failure equally occurs in all cases:

Current Configuration Properties:

Console Launcher - AnyCPU
UWP - x86
Package - x86
WPF - AnyCPU
WinForms - AnyCPU

Setup all Solution apps to x86:

Console Launcher - x86
UWP - x86
Package - x86
WPF - x86
WinForms - x86

or x64:

Console Launcher - x64
UWP - x64
Package - x64
WPF - x64
WinForms - x64

executes same results by scenario:

Lessons Part 1 "Run WinForms from UWP" and Part 2 "Passing parameters" works successfully, runs application, sends parameters with loading of WPF or WinForms.

Scenarios from lesson Part 3 results with same failure, InitializeAppServiceConnection(); throws System.BadImageFormatException with direct debug, attempt to run WPF or WinForms from UWP, does nothing with requested application, just shows Console Launcher for a second, without any message, and Invoke desktop code to read reg key throws same System.NullReferenceException

Setup all apps to AnyCPU, except UWP, which bin debug output path, as platform targets drop-down menu from solution or app properties includes only x64, x86, ARM, ARM64:

Console Launcher - AnyCPU
UWP - x86 
Package - AnyCPU
WPF - AnyCPU
WinForms - AnyCPU

throws:

Severity Code Description Project File Line Suppression State Error MSB3270 There was a mismatch between the processor architecture of the project being built "x86" and the processor architecture of the reference "C:\Users\User\Desktop\UWP_BD\UWP_BD\Launcher\bin\Debug\Launcher.exe", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. Package C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106

and:

Severity Code Description Project File Line Suppression State Warning The element 'PropertyGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element 'WapProjPath' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. List of possible elements expected: 'Property, VisualStudioVersion, MinimumVisualStudioVersion, AdditionalFileItemNames, AllowUnsafeBlocks, AppConfigForCompiler, ApplicationIcon, ApplicationRevision, ApplicationVersion, AppDesignerFolder, AspNetConfiguration, AspNetCoreHostingModel, AspNetCoreModuleName, AssemblyKeyContainerName, AssemblyKeyProviderName, AssemblyName, AssemblyOriginatorKeyFile, AssemblyOriginatorKeyFileType, AssemblyOriginatorKeyMode, AssemblyType, AutoGenerateBindingRedirects, AutorunEnabled, BaseAddress, BootstrapperComponentsLocation, BootstrapperComponentsUrl, BootstrapperEnabled, CharacterSet, CheckForOverflowUnderflow, CLRSupport, UseDebugLibraries, CodePage, Configuration, ConfigurationName, ConfigurationOverrideFile, CreateDesktopShortcut, CreateWebPageOnPublish, CurrentSolutionConfigurationContents, DebugSecurityZoneURL, DebugSymbols, DebugType, DefaultClientScript, DefaultHTMLPageLayout, DefaultTargetSchema, DefineConstants, DefineDebug, DefineTrace, DelaySign, DisableLangXtns, DisallowUrlActivation, CodeAnalysisAd.... Package C:\Users\User\Desktop\UWP_BD\UWP_BD\Package\Package.wapproj 49

and x64:

Console Launcher - AnyCPU
UWP - x64 
Package - AnyCPU
WPF - AnyCPU
WinForms - AnyCPU

Severity Code Description Project File Line Suppression State Error MSB3270 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Users\User\Desktop\UWP_BD\UWP_BD\UWP_Control\bin\x64\Debug\UWP_Control.exe", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. Package C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106

I'm not sure, maybe I should change Minimum Version to Anniversary Edition or to Windows 10 (10.0; Build 10214) with creating of UWP which default is Windows 10 (10.0; Build 10586):

EDIT 2: **************************************************************************************************

I'm using Windows 10 Pro 64-bit OS, x64-basesd processor with Visual Studio 2019 Version 16.1.4, Target Framework: .NET Framework 4.7.2 Version 4.7.03056, Microsoft.NETCore.Universal Windows Platform 6.2.8 Path folder C:\Program Files (x86)\Microsoft SDKs\Windows includes folders: v7.0A, v8.1, v8.1A, v10.0A

in .csproj:

 <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.14393.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
    <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>

I got the same failure System.BadImageFormatException, if I change Minimum Version to Windows 10 Anniversary Edition (10.0; Build 14393) same as for Target Version, with both previous and new assembly without Part 1 and Part 2 code.

Also I've followed Roy Li suggestion in System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package on Windows Dev Center, "To create a more simple demo to reproduce the problem". So, I've created new package only with UWP and WPF according only UWP with Desktop Extension – Part 3 with UWP_FullTrust_3.

In previous assembly I have missed SingleInstance.cs in WPF application, but including of this code into previous or new assembly (without "Running app" and "passing parameter"), throws error:

Severity Code Description Project File Line Suppression State Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. FullTrust C:\Users\User\Desktop\UWP_BD2\Solution1\FullTrust\SingleInstance.cs 57 Active

on this part of code:

[STAThread]
public static void Main(string[] args)
{
    SingleInstanceManager manager = new SingleInstanceManager();
    manager.Run(args);
} 

EDIT 3: **************************************************************************************************

So, for Windows 10 Pro 64-bit OS, Version 1803 (OS Build 17134.829) suitable Target version should be 17134, I'm not sure about Minimum version:

I've updated Windows just few hours ago. Something goes wrong in Targets menu with creating Windows Application Package Project, or UWP, which does not contains 17134, with higher version, I got this message:

By some reason Target selection menu does not contains 17134 and it is gone for Windows Application Package Project too:

EDIT 4: **************************************************************************************************

I've installed SDK version 17134, and selected 17134 for Target Version with Windows Application Package Project and UWP creation.

I've added code, references, setup, but I got same Error! I'm not sure if I am able to fix it. Maybe complete test project, with actual code will help.

So, here is a full Solution repository UWP_desktop_bridge. It is UWP and Console Launcher to WPF, based on Part 1, Part 2, Part 3 of UWP-FullTrust lesson by Stefan Wick MSFT

Without InitializeAppServiceConnection(); scenarios from Part 1, Part 2 works, but with including InitializeAppServiceConnection(); to WPF InitializeComponent(); to get Part 3 functionality, I got:

System.BadImageFormatException HResult=0x80131058 Message=Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) Source=WpfApp1
StackTrace: at WpfApp1.MainWindow.d__4.MoveNext() in C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line 59 at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at WpfApp1.MainWindow.InitializeAppServiceConnection() at WpfApp1.MainWindow..ctor() in C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line 38 Inner Exception 1: BadImageFormatException: Cannot load a reference assembly for execution.

and same with SingleInstance.cs if using of this part of code:

[STAThread]
public static void Main(string[] args)
{
    SingleInstanceManager manager = new SingleInstanceManager();
    manager.Run(args);
}

Severity Code Description Project File Line Suppression State Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

It is similar functionality and failure as in my previous projects.

EDIT 5: **************************************************************************************************

At this time, I've carefully created copy-paste build, based on ZhuMingHao/AppSerViceTest demo given in answer by Nico Zhu - MSFT on related question Send speech recognition args.Result as parameter in UWP desktop-bridge package:

Debug loads UWP and WPF successfully. With click on the Click button with in UWP AppSerViceTest/AppServiceTest/MainPage.xaml.cs:

I got same exception:

System.NullReferenceException: 'Object reference not set to an instance of an object.

With click on WPF Send Message button, it is just closes WPF app, UWP StatusBlock and InfoBlock shows nothing.

Direct debug of WPF and click Send message button, throws a different content of the same System.BadImageFormatException:

System.BadImageFormatException HResult=0x80131058 Message=Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) Source=WpfApp1 StackTrace:
at WpfApp1.MainWindow.<Button_Click_1>d__5.MoveNext() in C:\Users\User\Desktop\UWP\UWP_DB_SR\WpfApp1\MainWindow.xaml.cs:line 91 at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at WpfApp1.MainWindow.Button_Click_1(Object sender, RoutedEventArgs e) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 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) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at WpfApp1.App.Main() Inner Exception 1: BadImageFormatException: Cannot load a reference assembly for execution.

SOLUTION: **************************************************************************************************

Solution answer given by Stefan Wick MSFT to question described also on WDC topic System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package on System.BadImageFormatException with particular UWP desktop-bridge app communication project, based on UWP with Desktop Extension – Part 3 example UWP-FullTrust/UWP_FullTrust_3/ as well as solver my copy of Nico Zhu - MSFT solution ZhuMingHao/AppSerViceTest:

My incorrect:

  • Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll
  • Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd

Must be correct references setup:

  • ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
  • ProgramFiles(x86)%\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd

解决方案

This exception occurs when referencing the Windows Runtime libraries incorrectly from the non-UWP project (WPF, Winforms, Console, etc.). Be sure to reference them as follows

  1. In the "Add Reference …" dialog click "Browse …" and set the filter to "All Files (*.*)"
  2. Navigate to "%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll"
  3. Navigate to "%ProgramFiles(x86)%\Windows Kits\10\UnionMetadata\{TargetVersion}\Windows.winmd"

这篇关于带有 WPF 桌面桥包的 UWP 中的 System.BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆