gpt4 book ai didi

c# - 如何调试 base.Dispose(disposing) 样板上发生的 NullReferenceException

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:07 29 4
gpt4 key购买 nike

我是 c# 和 VSTO 的新手。

我有一个 Excel 插件,我在其中创建了一个功能区和一些可以执行各种操作的新按钮。

我在 base.Dispose 中收到 NullReferenceException,该异常发生在加载项加载到 Excel 中时。

根据文档所说,我可能在没有使用 new 关键字的情况下实例化了一些东西,但我不知道在哪里可以找到我没有做过的东西!

我今天早些时候确实有这个工作,但没有进行任何备份或连接到源代码管理,事后看来这是个坏主意!

异常时有很多null,不知道有没有意义?

基本上;我不知道我做了什么突然导致这种情况发生,也不确定如何调试它、在哪里设置我的中断或这段样板如何适应事物的方案。

我不希望有人在我没有包含绝大多数代码的情况下神奇地解决错误,但对如何操作的一些指导或解释会很棒!

发生异常时的本地窗口

  -           this  {ReportFramework.Ribbon}      ReportFramework.Ribbon
- base {ReportFramework.Ribbon} Microsoft.Office.Tools.Ribbon.RibbonBase {ReportFramework.Ribbon}
+ base {ReportFramework.Ribbon} System.ComponentModel.Component {ReportFramework.Ribbon}
Base null Microsoft.Office.Tools.Ribbon.OfficeRibbon
+ Context '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Context' threw an exception of type 'System.NullReferenceException' object {System.NullReferenceException}
Factory null Microsoft.Office.Tools.Ribbon.RibbonFactory
+ Global '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Global' threw an exception of type 'System.NullReferenceException' bool {System.NullReferenceException}
+ Name '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Name' threw an exception of type 'System.NullReferenceException' string {System.NullReferenceException}
+ OfficeMenu '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).OfficeMenu' threw an exception of type 'System.NullReferenceException' Microsoft.Office.Tools.Ribbon.RibbonOfficeMenu {System.NullReferenceException}
+ Parent '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Parent' threw an exception of type 'System.NullReferenceException' Microsoft.Office.Tools.Ribbon.RibbonComponent {System.NullReferenceException}
+ RibbonId '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).RibbonId' threw an exception of type 'System.NullReferenceException' string {System.NullReferenceException}
+ RibbonType '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).RibbonType' threw an exception of type 'System.NullReferenceException' string {System.NullReferenceException}
+ RibbonUI '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).RibbonUI' threw an exception of type 'System.NullReferenceException' Microsoft.Office.Core.IRibbonUI {System.NullReferenceException}
+ StartFromScratch '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).StartFromScratch' threw an exception of type 'System.NullReferenceException' bool {System.NullReferenceException}
+ Tabs '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Tabs' threw an exception of type 'System.NullReferenceException' System.Collections.Generic.IList<Microsoft.Office.Tools.Ribbon.RibbonTab> {System.NullReferenceException}
+ Tag '((Microsoft.Office.Tools.Ribbon.RibbonBase)(this)).Tag' threw an exception of type 'System.NullReferenceException' object {System.NullReferenceException}
+ Non-Public members
btnAddCETotals null Microsoft.Office.Tools.Ribbon.RibbonButton
btnLinkBank null Microsoft.Office.Tools.Ribbon.RibbonButton
btnCEDataTransfer null Microsoft.Office.Tools.Ribbon.RibbonButton
*...More btn's*
IsClose false bool
LargeColWidth 0.0 double
+ objCReport {ReportFramework.Classes.CReport} ReportFramework.Classes.CReport
objFormat null ReportFramework.Classes.CFormat
oExcel null Microsoft.Office.Interop.Excel.Application
PageWidthLandscape 0.0 double
PageWidthPortrait 0.0 double
SmallColWidth 0.0 double
tabBoyceTools null Microsoft.Office.Tools.Ribbon.RibbonTab
userName null string
WorksheetResult null Microsoft.Office.Interop.Excel.Worksheet
disposing false bool

异常详情

  System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.Office.Tools.Common.v4.0.Utilities
StackTrace:
at Microsoft.Office.Tools.Ribbon.RibbonBase.Dispose(Boolean disposing)
at ReportFramework.Ribbon.Dispose(Boolean disposing) in C:\Users\lsmith\Documents\Visual Studio 2010\Projects\xxx Tools 2\ReportFramework\Ribbon.Designer.cs:line 30
at System.ComponentModel.Component.Finalize()
InnerException:

第 30 行是 base.Dispose 下面的行

Ribbon.Designer.cs

namespace ReportFramework
{
partial class Ribbon : Microsoft.Office.Tools.Ribbon.RibbonBase
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

public Ribbon()
: base(Globals.Factory.GetRibbonFactory())
{
InitializeComponent();
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}

base.Dispose(disposing);

}

#region Component Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tabBoyceTools = this.Factory.CreateRibbonTab();
this.grpBoyceCAL = this.Factory.CreateRibbonGroup();
this.btnGenerateCAL = this.Factory.CreateRibbonButton();
*...Lots more code here; not sure if it's pertinent. can post if necessary.*

}

partial class ThisRibbonCollection
{
internal Ribbon Ribbon
{
get { return this.GetRibbon<Ribbon>(); }
}
}
}

最佳答案

FWIW,在选中“项目设置”>“签署程序集”中的复选框并尝试使用临时 key 签署后,我开始收到此异常。

我确定此错误可能是由许多其他错误引起的,但希望这对某人有所帮助。

关于c# - 如何调试 base.Dispose(disposing) 样板上发生的 NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24950323/

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