WPF:加载资源字典时的 XamlParseException -> AccessViolation

标签 wpf access-violation resourcedictionary xamlparseexception

此 WPF 应用以 .NET 3.5 为目标,并使用 Visual Studio 2010 的 4.0 工具构建(csc.exe 版本为 4.0.30319.1)。

我不确定我看到的这个异常是怎么回事。同一个 exe 已经在所有机器上运行了几个月,但就在今天,一位客户遇到了这个问题。我无法在本地重现它,我所要做的就是从下面的日志文件中获取堆栈跟踪。

我使用 Visual Studio 2010 制作了一个快速示例应用程序,它只在窗口中显示一个按钮,按钮内容字符串是从资源字典中提取的。这在客户机器上有效,所以看起来 .NET 安装没有完全在那里...

关于接下来要调查或研究的内容有什么想法吗?也许客户 .NET 安装处于某种状态??

编辑:客户执行了 .NET 3.5 的卸载和重新安装并解决了问题。我猜他们的安装中有一些奇怪的状态导致了这个问题。

错误:

System.Windows.Markup.XamlParseException: 'MainWindowViewResources.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Error at object 'System.Windows.ResourceDictionary' in markup file 'symformconfig;component/view/mainwindowview.xaml'. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.IO.Packaging.PackagePart.CleanUpRequestedStreamsList() at System.IO.Packaging.PackagePart.GetStream(FileMode mode, FileAccess access) at System.IO.Packaging.PackWebResponse.CachedResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.GetResponseStream() at System.IO.Packaging.PackWebResponse.get_ContentType() at MS.Internal.WpfWebRequestHelper.GetContentType(WebResponse response)
at MS.Internal.WpfWebRequestHelper.GetResponseStream(WebRequest request, ContentType& contentType) at System.Windows.ResourceDictionary.set_Source(Uri value) --- End of inner exception stack trace --- 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.ReadPropertyRecordBase(String attribValue, Int16 attributeId, Int16 converterTypeId) at System.Windows.Markup.BamlRecordReader.ReadPropertyConverterRecord(BamlPropertyWithConverterRecord bamlPropertyRecord) 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.LoadComponent(Object component, Uri resourceLocator) at Symform.Node.Configuration.MainWindowView.InitializeComponent() at Symform.Node.Configuration.MainWindowView..ctor() at Symform.Node.Configuration.App.OnStartup(StartupEventArgs e) 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)

最佳答案

确保 MainWindowViewResources.xaml 的 BuildAction 设置为 Page 而不是 Resource。您可以在“属性”面板中找到该设置。

关于WPF:加载资源字典时的 XamlParseException -> AccessViolation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4082110/

相关文章:

.net - 翻译 WPF

wpf - 在 WinForms/WPF 中实现 "Remember Me"复选框的最佳方式

c++ - Release模式下的访问冲突

wpf - 来自外部组件的问题引用转换器

c# - 添加 ResourceDictionary 后 MyApp.App 不包含 Initialize 的定义

wpf - 如何解决 AllowsTransparency=true 的 WPF 窗口中的 ActiveX WebBrowser 缺陷

c++ - 访问冲突(未处理的异常)

c# - native dll 中的动态内存分配

c# - 将 ResourceDictionary 应用于 WPF 框架中的页面

WPF Listview 虚拟化模式在绑定(bind)时会出现问题