首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XamlParseException停止项目

XamlParseException停止项目
EN

Stack Overflow用户
提问于 2011-12-05 20:03:18
回答 2查看 1.4K关注 0票数 2

我正在使用“Microsoft VS C# 2010 Step by Step”这本书学习任务2010,该书的第27章介绍了任务并行库。当我运行提供的'GraphDemo‘项目时,我得到一个XamlParseException错误。我在同一个异常上检查了这个站点上的几个线程,并设法将内部异常深入到加载PerformanceCounter失败的原因。由于担心系统的.NET Framework4安装损坏,我将其修复为原始状态,但错误仍然存在。奇怪的是,这本书的其他读者都没有抱怨过这个问题;在我写信给出版商后,作者要求我给他发送一个项目的zipfile,他声称它在他的机器上运行得很好。在第27章中还有其他七个项目,它们都在我的系统上抛出了相同的错误。

下面是生成的异常的全文:

代码语言:javascript
复制
System.Windows.Markup.XamlParseException was unhandled
  Message='The invocation of the constructor on type 'GraphDemo.GraphWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '5'.
  Source=PresentationFramework
  LineNumber=3
  LinePosition=5
  StackTrace:
       at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       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__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, 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, Boolean ignoreSyncCtx)
       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, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(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 GraphDemo.App.Main() in E:\IT Books\Source Code Projects\Microsoft Visual C# 2010 Step By Step\Chapter 27\GraphDemo\GraphDemo\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.InvalidOperationException
       Message=Cannot load Counter Name data because an invalid index '' was read from the registry.
       Source=System
       StackTrace:
            at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
            at System.Diagnostics.PerformanceCounterLib.get_NameTable()
            at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
            at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
            at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
            at System.Diagnostics.PerformanceCounter.InitializeImpl()
            at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean readOnly)
            at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName)
            at GraphDemo.GraphWindow..ctor() in E:\IT Books\Source Code Projects\Microsoft Visual C# 2010 Step By Step\Chapter 27\GraphDemo\GraphDemo\GraphWindow.xaml.cs:line 25
       InnerException: 

And this is the code pinpointed by the inner exception:

    public GraphWindow()
    {
        InitializeComponent();
        PerformanceCounter memCounter = new PerformanceCounter("Memory", "Available Bytes");
        availableMemorySize = Convert.ToUInt64(memCounter.NextValue());
        this.pixelWidth = (int)availableMemorySize / 20000;
        if (this.pixelWidth < 0 || this.pixelWidth > 15000)
        this.pixelWidth = 15000;
        this.pixelHeight = (int)availableMemorySize / 40000;
        if (this.pixelHeight < 0 || this.pixelHeight > 7500)
        this.pixelHeight = 7500;
    }

第25行是初始化memCounter的那一行。

我将感谢所有我能得到的帮助。

EN

回答 2

Stack Overflow用户

发布于 2012-06-06 22:13:50

您很有可能在针对4.0框架时引用.Net 2.0应用程序。尝试将useLegacyV2RuntimeActivationPolicy="true"添加到配置文件中:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>
票数 0
EN

Stack Overflow用户

发布于 2013-09-14 22:52:56

我也遇到了同样的问题,下面是我是如何解决的。基本上,您的性能计数器列表已损坏。http://blogs.technet.com/b/yongrhee/archive/2009/10/06/how-to-rebuild-performance-counters-on-windows-vista-server2008-7-server2008r2.aspx

要解决此问题,请以管理员身份运行CMD,然后在命令提示符下输入:

C:\Windows\System32\lodctr /r

性能计数器将从头开始重建。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8385016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档