部署 WPF 项目后的 XamlParseException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4615597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:28:42  来源:igfitidea点击:

XamlParseException after deploying WPF project

wpfdeploymentxamlparseexception

提问by Drew

I have been trying to deploy my WPF app, I created a Setup Project using the Setup Wizard.The only Project Output I added was Primary. After building this and installing the program, as soon as i click the exe on my desktop i get a pop up that says "'My Program' has stopped working", so i click Debug the Program and i see

我一直在尝试部署我的 WPF 应用程序,我使用安装向导创建了一个安装项目。我添加的唯一项目输出是主要的。构建并安装程序后,只要我点击桌面上的 exe,我就会弹出一个说“'我的程序'已停止工作”,所以我点击调试程序,我看到

An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: 'Set connectionId threw an exception.' Line number '10' and line position '9'.

PresentationFramework.dll 中发生类型为“System.Windows.Markup.XamlParseException”的未处理异常

附加信息:“设置 connectionId 引发异常。” 行号“10”和行位置“9”。

This exception does not point me in any direction as to what to fix. there is no 'connectionId' anywhere in my app.

这个例外并没有指出我要修复什么的任何方向。我的应用程序中的任何地方都没有“connectionId”。

I had previously ran into an XAMLParseException because of my NotifyIcon for my system tray, but this was fixed by adding the icon to the path of my exe. I thought this may be the problem so i added the icon to my Setup Project, along with all the other Project Outputs. Still Not Working.

由于我的系统托盘的 NotifyIcon,我以前遇到过 XAMLParseException,但是通过将图标添加到我的 exe 路径来解决这个问题。我认为这可能是问题所在,因此我将图标与所有其他项目输出一起添加到我的设置项目中。还是行不通。

I know this is a vague error but any help at all would be appreciated, my app won't run at all. Thanks!

我知道这是一个模糊的错误,但任何帮助都将不胜感激,我的应用程序根本无法运行。谢谢!

回答by jjrdk

This is normally caused by not having all dependencies copied to the output. As you say the error message is not very helpful, but I would check that your application has all the necessary dependencies available to resolve the parsed types.

这通常是由于没有将所有依赖项复制到输出中造成的。正如您所说,错误消息不是很有帮助,但我会检查您的应用程序是否具有可用于解析解析类型的所有必要依赖项。

Normally it is enough to set Copy Local to true for referenced assemblies, but I've experienced some cases where references themselves reference assemblies, so it can be necessary to explicitly add those references as well.

通常,对于引用的程序集将 Copy Local 设置为 true 就足够了,但是我遇到了一些引用本身引用程序集的情况,因此也有必要显式添加这些引用。

Update:

更新:

Important addition by @BENN1TH.

@BENN1TH 的重要补充。

If you want to see what an assembly is necessary:

如果您想查看需要什么程序集:

Was getting the same type of issue once i had published and installed my project (was working fine in debug VS2013 Desktop, no errors etc) but used the advice in from http://geekswithblogs.net/lbugnion/archive/2007/03/14/108728.aspxand wham! installed project was working..

一旦我发布并安装了我的项目(在调试 VS2013 桌面中工作正常,没有错误等),我遇到了相同类型的问题,但使用了来自http://geekswithblogs.net/lbugnion/archive/2007/03/的建议14/108728.aspx和重!安装的项目正在运行..

try

{
  InitializeComponent();
}
catch ( Exception ex )
{
  // Log error (including InnerExceptions!)
  // Handle exception
}

回答by user936597

Cleaning and Rebuilding the solution might help!

清洁和重建解决方案可能会有所帮助!

回答by bobbyb

I had this problem with a WPF solution in VS2010. The solution contained a simple dll and a test project (set to startup) for testing the dll. My dll was set to x86 and my test project was set to x64. When I changed the test project to x86 the problem was resolved.

我在 VS2010 中使用 WPF 解决方案时遇到了这个问题。该解决方案包含一个简单的 dll 和一个用于测试 dll 的测试项目(设置为启动)。我的 dll 设置为 x86,我的测试项目设置为 x64。当我将测试项目更改为 x86 时,问题解决了。

回答by Frederik M.J.V

If you get this exception in the debugger check the InnerException member of the exception. It might give you a hint about which assembly that is missing.

如果在调试器中遇到此异常,请检查异常的 InnerException 成员。它可能会提示您缺少哪个程序集。

回答by BENN1TH

Was getting the same type of issue once i had published and installed my project (was working fine in debug VS2013 Desktop, no errors etc) but used the advice in from http://geekswithblogs.net/lbugnion/archive/2007/03/14/108728.aspxand wham! installed project was working..

一旦我发布并安装了我的项目(在调试 VS2013 桌面中工作正常,没有错误等),我遇到了相同类型的问题,但使用了来自http://geekswithblogs.net/lbugnion/archive/2007/03/的建议14/108728.aspx和重!安装的项目正在运行..

try

{
  InitializeComponent();
}
catch ( Exception ex )
{
  // Log error (including InnerExceptions!)
  // Handle exception
}

回答by Richard Harrison

I just had a good 4 hours trying to figure this out. Mine ended up being nothing to do with the xaml! Turned out it was a minor error in the code behind on MainWindow initialize.

我刚刚花了 4 个小时试图解决这个问题。我的最终与 xaml 无关!原来这是 MainWindow 初始化背后的代码中的一个小错误。

If all else fails, check there

如果所有其他方法都失败,请检查那里

回答by Uni

Cleaning and rebuilding the project was not effective for me.

清理和重建项目对我来说没有效果。

You can try to delete bin Directory then rebuild, I solved my problem by this way.

您可以尝试删除bin目录然后重建,我通过这种方式解决了我的问题。

回答by Dharmendra Chaudhary

I have got this problem. This problem occurs due to Microsoft.Expression.Drawing.dll please download dll and add reference.

我有这个问题。出现此问题是由于Microsoft.Expression.Drawing.dll 请下载dll并添加引用。

回答by JesikaDG

I ran into this when working with multiple dlls running inside an application and those dlls have differing versions of the same dependency loaded.

我在处理在应用程序中运行的多个 dll 时遇到了这个问题,并且这些 dll 加载了相同依赖项的不同版本。

We normally merge the dlls during our release build to prevent this issue, but we see it if we are testing more then one set of unmerged dlls during development cycle.

我们通常在发布版本期间合并 dll 以防止出现此问题,但如果我们在开发周期中测试多于一组未合并的 dll,我们就会看到它。

The solution it to only test one set of unmerged dlls, using merged release versions for the other dlls that are not being tested, or to ensure that the dependent dll is the same version for both sets.

解决方案是仅测试一组未合并的 dll,对未测试的其他 dll 使用合并的发布版本,或者确保依赖的 dll 是两组的相同版本。

回答by AVEbrahimi

I solved this problem by removing Sign the assembly, here :

我通过删除Sign the assembly解决了这个问题,这里:

enter image description here

在此处输入图片说明