我是c#和VSTO的新手。
我有一个Excel添加,我工作时创建了一个功能区和一些新的按钮,可以执行各种操作。
我在Ribbon.Designer.cs文件中的base.Dispose上得到NullReferenceException,该文件是在插件加载到Excel时发生的。
根据文档的说法,我可能在不使用新关键字的情况下实例化了一些内容,但我不知道在哪里可以找到我没做过的事情!
我今天早些时候确实有这个工作,但没有采取任何备份或连接到源代码管理,事后看来这是一个坏主意!
在例外的时候有很多空的,我不知道这是否有意义?
基本上;我不知道我做了什么突然发生这种情况,我不知道如何调试它,在哪里设置我的休息时间或这块样板如何适合事物的方案。
当我没有包含绝大多数代码时,我并没有指望有人神奇地把这个漏掉,但是对于该做什么的某些方向或解释会很棒!
异常时的本地窗口
- 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>(); }
}
}
}
答案 0 :(得分:0)
FWIW,在选中“项目设置”>“为程序集签名”并尝试使用TemporaryKey签名后,我开始收到此异常。
我确定此错误可能是由其他许多错误引起的,但希望对您有所帮助。