FrankSh

VS2005, VSTO2005SE, Office2003

Whenever I use a DatagridView, Datagrid or ReportViewer control in an office AddIn I get an AccessViolationException as soon as System.Drawing tries to paint the control.

This happens in every Office AddIn (Excel, Word, Outlook). It doesn't happen when I use this controls in a Windows Forms application.

I created a simple AddIn with a form and a Datagridview and just a few lines to fill the Grid so it has something to paint:

public class ThisAddIn

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

' Anfang des von VSTO generierten Codes

Me.Application = CType(Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(GetType(Excel.Application), Me.Application), Excel.Application)

' Ende des von VSTO generierten Codes

Dim oGrid As New frmGrid

oGrid.Show()

End Sub

End Class

The form with just a few lines:

Public Class frmGrid

Private myTable As New ArrayList

Private Sub frmGrid_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

CreateDatas()

SetBinding()

End Sub

Private Sub CreateDatas()

Dim intX As Integer

For intX = 1 To 30

myTable.Add("Value" & CStr(intX))

Next

End Sub

Private Sub SetBinding()

Try

MyGrid.DataSource = myTable

Catch ex As System.Exception

MsgBox("Error: " & ex.Message)

End Try

End Sub

End Class

Any ideas

Thank you,

Frank

And here's the callstack:

System.AccessViolationException: Es wurde versucht, im geschutzten Speicher zu lesen oder zu schreiben. Dies ist haufig ein Hinweis darauf, dass anderer Speicher beschadigt ist.
bei System.Drawing.SafeNativeMethods.Gdip.GdipDrawLineI(HandleRef graphics, HandleRef pen, Int32 x1, Int32 y1, Int32 x2, Int32 y2)
bei System.Drawing.Graphics.DrawLine(Pen pen, Int32 x1, Int32 y1, Int32 x2, Int32 y2)
bei System.Windows.Forms.DataGridViewCell.PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
bei System.Windows.Forms.DataGridViewTopLeftHeaderCell.PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
bei System.Windows.Forms.DataGridViewTopLeftHeaderCell.PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, Boolean computeContentBounds, Boolean computeErrorIconBounds, Boolean paint)
bei System.Windows.Forms.DataGridViewTopLeftHeaderCell.Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, Object value, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
bei System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
bei System.Windows.Forms.DataGridView.PaintTopLeftHeaderCell(Graphics g)
bei System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle gridBounds, Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean singleHorizontalBorderAdded)
bei System.Windows.Forms.DataGridView.OnPaint(PaintEventArgs e)
bei System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
bei System.Windows.Forms.Control.WmPaint(Message& m)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.DataGridView.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Geladene Assemblys **************
mscorlib
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
msosec
Assemblyversion: 7.0.5000.0
Win32-Version: 7.10.3191.0
CodeBase: file:///C:/WINDOWS/assembly/GAC/msosec/7.0.5000.0__b03f5f7f11d50a3a/msosec.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime
Assemblyversion: 8.0.0.0
Win32-Version: 8.0.50727.816
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.dll
----------------------------------------
Microsoft.Office.Tools.Common
Assemblyversion: 8.0.0.0
Win32-Version: 8.0.50727.816
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Tools.Common/8.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Common.dll
----------------------------------------
System
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
GridTestExcel
Assemblyversion: 1.0.0.0
Win32-Version: 1.0.0.0
CodeBase: file:///C:/Dokumente%20und%20Einstellungen/Frank.Sharp/Eigene%20Dateien/Visual%20Studio%202005/Projects/GridTestExcel/GridTestExcel/bin/Debug/GridTestExcel.DLL
----------------------------------------
Microsoft.Office.Interop.Excel
Assemblyversion: 11.0.0.0
Win32-Version: 11.0.5530
CodeBase: file:///C:/WINDOWS/assembly/GAC/Microsoft.Office.Interop.Excel/11.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
----------------------------------------
Microsoft.Office.Tools.Excel
Assemblyversion: 8.0.0.0
Win32-Version: 8.0.50727.816
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.Office.Tools.Excel/8.0.0.0__b03f5f7f11d50a3a/Microsoft.Office.Tools.Excel.dll
----------------------------------------
System.Drawing
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
office
Assemblyversion: 11.0.0.0
Win32-Version: 11.0.5530
CodeBase: file:///C:/WINDOWS/assembly/GAC/office/11.0.0.0__71e9bce111e9429c/office.dll
----------------------------------------
Accessibility
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Windows.Forms.resources
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_de_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
Microsoft.VisualBasic
Assemblyversion: 8.0.0.0
Win32-Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Configuration
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assemblyversion: 2.0.0.0
Win32-Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.VisualStudio.Tools.Applications.Runtime.resources
Assemblyversion: 8.0.0.0
Win32-Version: 8.0.50727.42
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualStudio.Tools.Applications.Runtime.resources/8.0.0.0_de_b03f5f7f11d50a3a/Microsoft.VisualStudio.Tools.Applications.Runtime.resources.dll
----------------------------------------



Re: Visual Studio Tools for Office AccessViolationException in DatagridView

Cindy Meister

Hi Frank

Let's see if I've got the facts straight:

- You're creating VSTO add-ins for various office 2003 (2007 ) applications

- you try to insert a WinForms control onto the Office file (word doc, Excel sheet, etc.)

- and when you do this, you're getting an error

If I'm correct with my summary, then the error is to be expected. An Office document is not able to support a WinForms control.

You can only place WinForms controls on Word or Excel documents that have been created using the full VSTO 2005 document-level customization. This is not available as part of the VSTO 2005 SE that supports creating Add-ins. It's a separate release that you must purchase (unless you have VS Team Suite).

If you're trying to put a table of data into an Office document using an Add-in, you'll need to create it by automating the application using its interop.






Re: Visual Studio Tools for Office AccessViolationException in DatagridView

FrankSh

Hi Cindy,

thank you for your reply and sorry for my poor explanation.

No, I create and show a Winform with a Datagridview.

I do nothing with an Office document.

Just for demonstration of this error.

And it's a problem that I have on just one of my PC's.

It runs on all my other computers.

I guess I'm having the same problem I found reportet at:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx FeedbackID=93843

Thank you,

Frank





Re: Visual Studio Tools for Office AccessViolationException in DatagridView

FrankSh

The fact that this error only happened in Office AddIns on my PC made me looking for a solution in a completly wrong direction. It's not a problem in VSTO, it's a bug in the DataGrid and DataGridView control.

A workaround can be found at:

http://forums.microsoft.com/msdn/ShowPost.aspx postid=1652215&isthread=false&siteid=1

Thank u,

Frank





Re: Visual Studio Tools for Office AccessViolationException in DatagridView

Cindy Meister

Glad you found it, and thanks for the link :-)