gpt4 book ai didi

wpf - clickonce 部署后出现 xamlparser 错误。安装后应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 22:37:24 26 4
gpt4 key购买 nike

我已经使用 Visual Studio 2008 构建了一个 WPF 应用程序,并为其创建了一个安装程序。到目前为止,工作正常。我意识到它缺乏自动更新功能,在尝试了几种解决方案后,我决定尝试单击一次部署在网络服务器上成功部署后,我注意到应用程序在安装下载的应用程序后崩溃。它提示这一点:

Cannot create instance of 'Login' defined in assembly 'MyApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'MyApplication;component/login.xaml' Line 1 Position 9.

这是堆栈跟踪

at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException) at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Markup.TreeBuilder.Parse()
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
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.Threading.Dispatcher.Run()
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 myApplication.App.Main()

这里只是调试器指向的区域

<Window x:Class="MyApplication.Login"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:MyApplication"
xmlns:UI="clr-namespace:UI;assembly=UI"
Title="My Application" Height="400" Width="550" ResizeMode="NoResize" WindowStyle="ThreeDBorderWindow" WindowStartupLocation="CenterScreen" Name="Logine" Loaded="Logine_Loaded" Closed="Logine_Closed" Icon="orLogo.ico">

但是安装项目中的 msi 中的安装程序版本工作正常。所以我看不到错误来自哪里,因为我可以拥有设计 View 。
问题 1:是否有人遇到类似问题,或者这是一个已知问题?
问题 2:如果这是一个已知问题,那么有什么替代方案。我可能会放弃一次点击,但随后我的自动更新功能将丢失(因为没有一个不是 vekill 或严重过时的功能)我现在就能找到)。
感谢您阅读本文并为我指明了正确的方向。

最佳答案

如果您转到 ClickOnce 缓存并找到应用程序的可执行文件并双击它,它仍然会失败吗?如果是这样,那么它本身就不是 ClickOnce 问题。可能是您在部署中缺少一些所需的程序集。或者您正在执行 ClickOnce 不允许的操作,例如访问需要管理权限的文件夹。

您还可以在构建后尝试从\bin\release 文件夹运行它,但这不会告诉您您正在使用的计算机上是否有未部署的程序集。

Windows 7(和 Vista)上的 ClickOnce 缓存位于:
C:\Users\用户名\AppData\Local\Apps\2.0\obfuscatedfolder\obfuscatedfolder

从那里开始,对于 win 表单应用程序,它会创建两个文件夹,一个名为 xxxx...exe_etc,另一个名为 xxxx...tion_etc... 以 xxxx_tion 开头的文件夹(其中 xxxx = 您的文件的第 1 个四个字符)程序集名称)是应用程序运行的位置。我不确定 WPF 应用程序的文件夹名称是否相同,但希望它们不会有太大不同。可执行文件仅位于一个文件夹中。 (是的,您可能认为它位于 xxxx...exe_etc 文件夹中,但事实并非如此。)

编辑 - 添加信息

对于丢失图像的问题:它们是否作为文件包含在项目中?如果是这样,请确保构建操作是“内容”,并且“复制到输出目录”属性设置为“始终复制”。否则,它不会将它们包含在部署中。

对于数据库,同样的问题。它需要包含在项目中,并且必须相应地设置属性(将“复制...”设置为“如果较新则复制”)。另外,打开“应用程序文件”对话框并查看它是否标记为“包含(数据)”。如果是,则它将被部署到数据目录。如果您以这种方式部署它,当您发布新版本时,它会将数据复制到新文件夹中。您可以使用 ApplicationDeployment.DataDirectory 属性以编程方式找到它。

我通常不建议将您的数据信任给 ClickOnce。如果您将某些内容部署为数据,并且本地版本上的日期/时间戳发生更改,ClickOnce 将部署新版本,并将旧版本放入名为 .\pre 的子文件夹中。对我来说,这很危险,因为您可能会意外修改数据。如果您只是打开数据库查看表结构,SQLCE 会更改日期/时间戳。所以我自己移动数据并处理数据库的更新。如果您想了解更多信息,请查看我的博客文章 keeping your data safe from ClickOnce updates .

关于wpf - clickonce 部署后出现 xamlparser 错误。安装后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2928474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com