我有一个Visual studio 2013 VSTO Word外接程序项目,它在离开visual Studio时似乎工作正常。但是当我安装它并运行一个特定的函数时,就会产生一个错误。我添加了try catch,因为Word似乎抑制了错误,并悄悄地进行了似乎很好(尽管它不是)。
我对这件事束手无策。我不明白为什么它可以在Visual Studio中正常运行,但不能在安装时正常运行。其他以前编写的功能似乎工作得很好。
对象引用未设置为对象的实例。at FrRibbon.Support.AppStats.WriteRibbonUsage(String subApplication,String featureInvoked,String initials)
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发布于 2016-11-15 05:09:54
直到我将连接字符串添加到应用程序设置中,并将其引用为: My.Settings.MyConnectionStringName,它才起作用。我之前刚刚在app.config的ConnectionStrings部分手动添加了它。
我怀疑这与app.config被编译为VSTOAddinName.dll.config有关,这可能解释了为什么它在Visual Studio中可以工作,但在安装时却不能。
https://stackoverflow.com/questions/40593269
复制相似问题