【问题标题】:WPF design view errorWPF 设计视图错误
【发布时间】:2011-05-07 05:46:36
【问题描述】:

我是这份工作的新手,当我打开一个项目时,我得到了这个错误,我无法弄清楚发生了什么。 有什么帮助吗?

SO:WinXP Sp3、Visual Studio 2010 Express

提前致谢。

异常不受控制。 细节: System.Reflection.TargetInvocationException Se produjo una excepción en el destino de la invocación。 zh System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo 方法,对象目标,Object[] 参数,SignatureStruct& sig,MethodAttributes methodAttributes,RuntimeType typeOwner) en System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo 方法, 对象目标, Object[] 参数, 签名 sig, MethodAttributes methodAttributes, RuntimeType typeOwner) en System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] 参数, CultureInfo 文化, Boolean skipVisibilityChecks) zh System.Delegate.DynamicInvokeImpl(Object[] args) zh System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,Int32 numArgs) en MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

System.NullReferenceException Referenceencia a objeto no establecida como instancia de un objeto。 zh ControlPesajeLavanderia.ItemParte.NuevoItemParte_IsVisibleChanged(Object sender, DependencyPropertyChangedEventArgs e) zh C:\Documents and Settings\golaizola\Mis documentos\Visual Studio 2010\Projects\ControlPesajeLavanderia\ControlPesajeLavanderia\usercontrols\ItemParte.xaml.vb:línea 186 zh System.Windows.UIElement.RaiseDependencyPropertyChanged(EventPrivateKey 键,DependencyPropertyChangedEventArgs 参数) zh System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) zh System.Windows.UIElement.UpdateIsVisibleCache() zh System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v,DependencyProperty 属性) zh System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) zh System.Windows.UIElement.UpdateIsVisibleCache() zh System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v,DependencyProperty 属性) zh System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) zh System.Windows.UIElement.UpdateIsVisibleCache() zh System.Windows.UIElement.InvalidateForceInheritPropertyOnChildren(Visual v,DependencyProperty 属性) zh System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) zh System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) zh System.Windows.UIElement.UpdateIsVisibleCache() zh System.Windows.UIElement.SynchronizeForceInheritProperties(UIElement uiElement, ContentElement contentElement, UIElement3D uiElement3D, DependencyObject parent) zh System.Windows.UIElement.OnVisualParentChanged(DependencyObject oldParent) zh System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent) zh System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent) zh System.Windows.Media.Visual.AddVisualChild(Visual child) zh System.Windows.FrameworkElement.set_TemplateChild(UIElement 值) zh System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(FrameworkElement 容器) zh System.Windows.StyleHelper.ApplyTemplateContent(UncommonField1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate) en System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField1 templateDataField,FrameworkElement 容器) zh System.Windows.FrameworkElement.ApplyTemplate() zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Border.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Control.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Border.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh MS.Internal.Designer.ZoomableViewPresenter.DesignerBackground.MeasureOverride(尺寸约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Decorator.MeasureOverride(大小约束) zh Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh MS.Internal.Helper.MeasureElementWithSingleChild(UIElement 元素,大小约束) zh System.Windows.Controls.ScrollContentPresenter.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Grid.MeasureCell(Int32 单元格,布尔 forceInfinityV) en System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead,大小referenceSize,布尔ignoreDesiredSizeU,布尔forceInfinityV) zh System.Windows.Controls.Grid.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.ScrollViewer.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Grid.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh MS.Internal.Helper.MeasureElementWithSingleChild(UIElement 元素,大小约束) zh System.Windows.Controls.ContentPresenter.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Controls.Control.MeasureOverride(大小约束) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(可用大小) zh System.Windows.Interop.HwndSource.SetLayoutSize() zh System.Windows.Interop.HwndSource.set_RootVisualInternal(视觉值) zh System.Windows.Interop.HwndSource.set_RootVisual(视觉值) en MS.Internal.DeferredHwndSource.ProcessQueue(Object sender, EventArgs e)

更新:

我创建了一个新表单并复制所有 xaml,直到出现错误。当我在这一行中包含我自己的用户控件时会发生错误:

并且错误说: “对象引用未设置为对象的实例。”

我不知道为什么......

【问题讨论】:

  • 你能帮我们翻译一下邮件内容吗?
  • 我假设它是“对象引用未设置为对象的实例”。

标签: .net wpf visual-studio


【解决方案1】:

如果您仅在设计视图中收到错误(是的,它看起来像未设置对象引用),那么我建议您创建另一个空白表单并逐段复制文本,直到您复制给您错误的文本。否则您将不知道从哪里开始诊断此错误。

此文件中的这一行可能与错误有关:

C:\Documents and Settings\golaizola\Mis documentos\Visual Studio 2010\Projects\ControlPesajeLavanderia\ControlPesajeLavanderia\usercontrols\ItemParte.xaml.vb

第 186 行

【讨论】:

  • +1 因为我认为您抓住了错误所在的正确行。提问者应该看看那一行,看看他们是否对不为空的东西做出错误的假设。
  • 这很有用。我创建了一个空白用户表单并开始复制我的 xaml,直到出现错误。错误在这一行:
  • @Kioko,如果 UcItemParte 在 C:\Documents and Settings\golaizola\Mis documentos\Visual Studio 2010\Projects\ControlPesajeLavanderia\ControlPesajeLavanderia\usercontrols\ItemParte.xaml.vb 中实现 i>,然后看看第 186 行发生了什么
  • 这很有用。我创建了一个空白用户控件并开始复制 XAML。我在这一行得到错误: 女巫 ItemParte 是另一个用户控件,我得到“对象引用未设置为对象的实例”错误
  • ItemParte.xaml.vb 包含:182 Private Sub NuevoItemParte_IsVisibleChanged(ByVal sender As System.Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs) 处理 Me.IsVisibleChanged 183 Dim uc As UserControl = DirectCast(sender , UserControl) 185 If uc.Visibility = Windows.Visibility.Visible Then 186 ListViewItems.SelectionMode = SelectionMode.Single 188 Try 189 If mConfig.GetConfig("solo_uniformidad") Then
【解决方案2】:

亲爱的例外消息!!!您在某处的构造函数中抛出异常,很难从异常消息中分辨出哪里;我是根据TargetInvocationException 做出这个判断的,这似乎总是表明这一点。

如果我是对的,那么在构造函数的某个地方,您会假设变量不为空。

遍历解决方案中的每个类并检查构造函数。对您触摸的所有内容执行空检查。如果不存在明显问题,请开始从设计器中实例化的类型中使用的任何构造函数中删除逻辑。你最终会找到它。

【讨论】:

  • 基本上你只需要检查你实际使用的构造函数。
猜你喜欢
  • 2012-01-07
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多