Why does the VisualStudio DataSet Visualizer fire an AssemblyResolve event?

323 views Asked by At

I'm working on a Visual Studio VB solution that uses the AssemblyResolve event, displaying a message and shutting down the application whenever it's fired.

Recently, a colleague has reported that whenever he tries to use the Data Visualizer during debugging (that nifty little magnifying glass button), the aforementioned message is displayed, after which the application accordingly shuts down.

This is how we handle AssemblyResolve:

    Public Sub New()

        AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf AppDomain_CurrentDomain_AssemblyResolve

    End Sub

    Public Shared Function AppDomain_CurrentDomain_AssemblyResolve(ByVal sender As Object, _
                                                                   ByVal e As ResolveEventArgs) As Assembly
        If _blnShuttingDown Then
            Return Nothing
        End If

        MsgBox(String.Format("Unexpected error : " & vbCrLf & vbCrLf & _
                             "Assembly {0} raised an error" & vbCrLf & vbCrLf & _
                             "The application is about to shut down. Please contact tech support.", _
                             e.Name), _
               MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, _
               SA.DAP.dapMessages.Titre.Erreur)
        _blnShuttingDown = True

        Application.Exit()

        ' The compiler needs this.
        Return Nothing
    End Function

We work with Visual Studio 2008, in which ResolveEventArgs doesn't have the RequestingAssembly property. It might have come in useful, but there you go.

An obvious workaround would be to add

        If e.Name.StartsWith("Microsoft.VisualStudio.Debugger.DataSetVisualizer") Then
            Return
        End If

at the beginning of the method (maybe even with just "Microsoft.VisualStudio.Debugger").

I don't want to try and force loading Microsoft.VisualStudio.Debugger at the beginning, because I feel that it wouldn't be good practice.

Still, I don't understand why AssemblyResolve is fired at that point. I understand that it happens when loading an assembly yields an error. What did I do wrong?

0

There are 0 answers