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

发布于 2024-09-03 11:25:20 字数 5373 浏览 2 评论 0原文

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

无法创建程序集“MyApplication,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”中定义的“Login”实例。调用目标已引发异常。标记文件“MyApplication;component/login.xaml”第 1 行第 9 行出错。

这是堆栈跟踪

在System.Windows.Markup.XamlParseException.ThrowException(字符串消息,异常innerException,Int32 lineNumber,Int32 linePosition,Uri baseUri,XamlObjectIds currentXamlObjectIds,XamlObjectIds contextXamlObjectIds,类型objectType)
在System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext,Int32 lineNumber,Int32 linePosition,字符串消息,异常innerException) 在System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(字符串消息,异常innerException)
在 System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(类型类型,Int16 typeId,布尔值 throwOnFail)
在 System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord、Object&元素、ReaderFlags&标志、Type&delayCreatedType、Int16&delayCreatedTypeId)
在 System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在 System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
在 System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
在 System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
在 System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
在 System.Windows.Markup.TreeBuilder.Parse()
在 System.Windows.Markup.XamlReader.LoadBaml(流流,ParserContext parserContext,对象父级,布尔 closeStream)
在 System.Windows.Application.LoadBamlStreamWithSyncInfo(流流,ParserContext pc)
在 System.Windows.Application.LoadComponent(Uri resourceLocator,布尔值 bSkipJournaledProperties)
在 System.Windows.Application.DoStartup()
在 System.Windows.Application.<.ctor>b__0(对象未使用)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,布尔值 isSingleParameter)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象参数,布尔 isSingleParameter,委托 catchHandler)
在 System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调、对象参数、布尔 isSingleParameter、委托 catchHandler)
在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
在 System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(对象状态)
在 System.Threading.ExecutionContext.runTryCode(Object userData)
在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode代码,CleanupCode backoutCode,对象userData)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallback 回调,对象状态)
在 System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallback 回调,对象状态)
在 System.Windows.Threading.DispatcherOperation.Invoke()
在 System.Windows.Threading.Dispatcher.ProcessQueue()
在 System.Windows.Threading.Dispatcher.WndProcHook(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(委托回调,对象参数,布尔值 isSingleParameter)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(对象源,委托回调,对象参数,布尔 isSingleParameter,委托 catchHandler)
在 System.Windows.Threading.Dispatcher.WrappedInvoke(委托回调、对象参数、布尔 isSingleParameter、委托 catchHandler)
在 System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority 优先级、TimeSpan 超时、委托方法、对象参数、布尔值 isSingleParameter)
在 System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority 优先级、委托方法、对象 arg)
在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd、Int32 msg、IntPtr wParam、IntPtr lParam)
在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
在System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame框架)
在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame 框架)
在 System.Windows.Threading.Dispatcher.Run()
在 System.Windows.Application.RunDispatcher(对象忽略)
在 System.Windows.Application.RunInternal(窗口窗口)
在 System.Windows.Application.Run(窗口窗口)
在 System.Windows.Application.Run()
在 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 工作正常。所以我看不到错误来自哪里,因为我可以拥有设计视图。< br> 问题 1:是否有人遇到类似问题,或者这是一个已知问题?
问题 2:如果这是一个已知问题,那么有什么替代方案。我可能会放弃一次点击,但随后我的自动更新功能将丢失(因为没有一个不是 vekill 或严重过时的功能)我现在就能找到)。
感谢您阅读本文并为我指明了正确的方向。

I've built an WPF application with visual studio 2008 and created an installer for it.Works fine so far.I realized it lacks the automatic updates feature, and after trying several solutions, i decided to give a try to clickonce deployment.After a successful deployment on a network server, i 've noticed that the application crashes after installation of the downloaded app.It complains about this:

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.

here is the stacktrace

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()

here is just the region the debugger is pointing to

<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">

But the installer version as in the msi from setup project works fine.so i cannot see where the error is comming from since i can have design view.
Question 1 : Does any one have a similar issue, or is that a known issue?
Question 2 : If it's a known issue then what are alternative.I might give up on the clickonce but then i my automatic update feature will be lost (as in there is none which is not ovekill or seriously outdated that i can find right now).
thanks for reading this and for pointing me to the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆沫 2024-09-10 11:25:20

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

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

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

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

编辑 - 添加信息

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

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

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

If you go to the ClickOnce cache and find the executable for your application and double-click on it, does it still fail? If so, then it is not a ClickOnce problem per se. It could be that you are missing some assembly in your deployment that is required. Or you are doing something that ClickOnce doesn't allow, such as accessing a folder that requires administrative privileges.

You can also try running it from your \bin\release folder after doing a build, but that won't tell you if you have an assembly on your machine that you're using that is not being deployed.

The ClickOnce cache on windows 7 (and vista) is here:
C:\Users\username\AppData\Local\Apps\2.0\obfuscatedfolder\obfuscatedfolder

From there, for a win forms app, it creates two folders, one called xxxx...exe_etc and one called xxxx...tion_etc... The one that starts with xxxx_tion (where xxxx = 1st four characters of your assembly name) is the one where the app is run from. I'm not sure if the folder names are the same for a WPF app, but hopefully they're not too different. The executable will only be in one folder. (And yes, you'd think it would be in the xxxx...exe_etc folder, but it's not.)

EDIT -- ADDED INFO

For the issue of missing images: Are they included in the project as files? If so, make sure the build action is 'content' and the 'copy to output directory' property is set to 'copy always'. Otherwise, it won't include them in the deployment.

For the database, same issue. It needs to be included in the project, and the properties must be set accordingly (set 'copy...' to 'copy if newer'). ALSO, open the Application Files dialog and see if it is marked as Include(Data). If it is, then it is being deployed to the Data directory. If you deploy it that way, when you publish a new version, it will copy the data forward to the new folders. You can find it programmatically using the ApplicationDeployment.DataDirectory property.

I generally don't recommend trusting your data to ClickOnce. If you deploy something as data, and the date/time stamp on your local version changes, ClickOnce will deploy the new version, and put the old version in a subfolder called .\pre. To me, this is dangerous, because you could modify the data accidentally. SQLCE changes the date/time stamp if you just open the database to look at the table structures. So I move the data and handle the updating of the database myself. If you want more information about this, check out my blog post on keeping your data safe from ClickOnce updates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文