开发者

How to know if MS Chart Controls are installed on client workstation?

开发者 https://www.devze.com 2023-04-12 19:20 出处:网络
I developed a ClickOnce application using MS Chart Controls. It works fine for the charting part. But, as Chart Control needs to be installed beforehand (with admin rights and not with classic ClickOn

I developed a ClickOnce application using MS Chart Controls. It works fine for the charting part. But, as Chart Control needs to be installed beforehand (with admin rights and not with classic ClickOnce deployment), I need to detect if the component is available on the machine.

So I tried to create a new Chart and to handle the possible Exception but it seems it is not possible to catch it (too low level Exception?) :

Try
  Dim oChart as New Chart
Catch
  ' Some user-friendly message to ask the user to contact the helpdesk
End Try

This code is never executed: I get a unhandled Exception as soon as I enter the event this code is in.

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

***** Exception Text ******* System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. File name: 'System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' at SIPReportingControl.Main.expMain_SelectedGroupChanged(Object sender, GroupEventArgs e)开发者_JAVA百科 at Infragistics.Win.UltraWinExplorerBar.SelectedGroupChangedEventHandler.Invoke(Object sender, GroupEventArgs e)

Do you have some ideas in order to:

  • be able to deploy MS Chart Controls with ClickOnce (I do not think it is possible).
  • detect if Chart Controls are installed or not.
  • catch this strange Exception.

Thanks in advance.

Edit The calling method (the exception is generated even if I click in another group than Reporting):

Private Sub expMain_SelectedGroupChanged(sender As Object, e As Infragistics.Win.UltraWinExplorerBar.GroupEventArgs) Handles expMain.SelectedGroupChanged
    Try
        If blnDoEvent Then
            CleanControls()
            Select Case e.Group.Key
                Case "Search"
                    DisplayGrid(True)
                Case "AddEdit"
                    DisplayAddEdit(Nothing)
                Case "Reporting"
                    Dim oChart As New Chart
            End Select
        End If
    Catch ex As Exception
        MsgBox(ex.Message & vbCrLf & ex.StackTrace)
    End Try
End Sub


I have seen a interesting answer about an exception been thrown in generated MSIL code for a function call, unfortunately it has been deleted and I cannot add a comment to it.

I have understood that your code is not responsible for firing the event. I would suggest to put the whole statement in a sub and to call it enclosed by a try catch this way :

Private Sub expMain_SelectedGroupChanged(sender As Object, e As Infragistics.Win.UltraWinExplorerBar.GroupEventArgs) Handles expMain.SelectedGroupChanged 
    Try 
        RedirectTo(e.Group.Key)
    Catch ex As Exception 
        MsgBox(ex.Message & vbCrLf & ex.StackTrace) 
    End Try 
End Sub 

Sub RedirectTo(Screen as string)
    If blnDoEvent Then 
        CleanControls() 
        Select Case Screen 
            Case "Search" 
                 DisplayGrid(True) 
            Case "AddEdit" 
                 DisplayAddEdit(Nothing) 
            Case "Reporting" 
                 Dim oChart As New Chart 
        End Select 
    End If
End Sub

Is it better ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号