首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Word 2016 VSTO Com加载项错误:未将对象引用设置为对象的实例

Word 2016 VSTO Com加载项错误:未将对象引用设置为对象的实例
EN

Stack Overflow用户
提问于 2016-11-15 00:19:36
回答 1查看 543关注 0票数 0

我有一个Visual studio 2013 VSTO Word外接程序项目,它在离开visual Studio时似乎工作正常。但是当我安装它并运行一个特定的函数时,就会产生一个错误。我添加了try catch,因为Word似乎抑制了错误,并悄悄地进行了似乎很好(尽管它不是)。

我对这件事束手无策。我不明白为什么它可以在Visual Studio中正常运行,但不能在安装时正常运行。其他以前编写的功能似乎工作得很好。

对象引用未设置为对象的实例。at FrRibbon.Support.AppStats.WriteRibbonUsage(String subApplication,String featureInvoked,String initials)

代码语言:javascript
复制
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient

Namespace Support

Public Module AppStats

    Public Sub WriteRibbonUsage(subApplication As String, featureInvoked As String, initials As String)

        Try
            Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("FRAppStatsConnectionString").ConnectionString)
                Using command As New SqlCommand("InsertRibbonUsage", connection)
                    command.CommandType = CommandType.StoredProcedure
                    command.Parameters.Add(New SqlParameter("subApplication", subApplication))
                    command.Parameters.Add(New SqlParameter("featureInvoked", featureInvoked))
                    command.Parameters.Add(New SqlParameter("initials", initials))
                    connection.Open()
                    command.ExecuteNonQuery()
                End Using
            End Using

        Catch ex As Exception
            Globals.ThisAddIn.Application.ActiveDocument.Range.Text = String.Concat(ex.Message, vbCrLf, ex.StackTrace, vbCrLf, ex.Source, vbCrLf, ex.InnerException)
        End Try

    End Sub

End Module
End Namespace

 Private Sub btnRemoveHyperlinks_Click(sender As Object, e As RibbonControlEventArgs) Handles btnRemoveHyperlinks.Click

    Support.AppStats.WriteRibbonUsage("Super Macro", "Remove Hyperlinks", Helpers.GetUserName())

    If Not Globals.ThisAddIn.CustomTaskPanes.Any(Function(c) c.Title = "Remove Hyperlinks") Then
        RemoveHyperlinksTaskPane = New CustomPane(RemoveHyperlinksControl, "Remove Hyperlinks", "removeHyperlinks", RemoveHyperlinksWindowList)
        RemoveHyperlinksTaskPane.Visibility(True, "right", 425)
        RemoveHyperlinksControl.PopulateHyperLinkListBox()
    Else
        RemoveHyperlinksTaskPane.Visibility(True, "right", 425)
        RemoveHyperlinksControl.PopulateHyperLinkListBox()
    End If

End Sub
EN

回答 1

Stack Overflow用户

发布于 2016-11-15 05:09:54

直到我将连接字符串添加到应用程序设置中,并将其引用为: My.Settings.MyConnectionStringName,它才起作用。我之前刚刚在app.config的ConnectionStrings部分手动添加了它。

我怀疑这与app.config被编译为VSTOAddinName.dll.config有关,这可能解释了为什么它在Visual Studio中可以工作,但在安装时却不能。

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

https://stackoverflow.com/questions/40593269

复制
相关文章

相似问题

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