none
Attempted to read or write protected memory RRS feed

  • Question

  • I have an app that is supposed to create a Word document and open Word with the document showing. It works perfectly for me and several others at my office. A customer is deploying the app via RDP on a Win2003 server. Whenever the program attempts to create the Word document in the RDP enviroment you get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I've checked and the document actually gets created however Word never opens. I put together a simple app that attempts to create a Word document the same way as my regular app and it yields the same result. I tried going to Tools>Options>Debugging>General and unchecking the "Suppress JIT optimization on module load (Managed only)" option based on other posts with the same message but it did not fix the problem. Any help will be greatly appreciated!!!

    Here is the code from my simple app:

    Imports

    System.Data
    Imports System.Data.OleDb
    Imports System.DBNull
    Imports System.IO
    Imports System.Resources
    Imports C1.C1Preview
    Imports C1.Win.C1Preview
    Imports Microsoft.Office.Interop

    Public

    Class Form1

     

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    GenerateDoc()

     

    End Sub

     

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

     

    Dim rtfexp As New C1.C1Preview.Export.RtfExporter

     

    Dim fs As New SaveFileDialog

    fs.FileName = TextBox1.Text

    rtfexp.Document = c1Pd

    rtfexp.ShowOptions =

    False

    rtfexp.UseDrawingCanvas =

    True

    rtfexp.Export(fs.FileName)

     

    Dim appWord As Word.Application

     

    Dim wrdDoc As Word.Document

     

    Dim strFileName As String

    strFileName = fs.FileName

    appWord =

    New Word.Application

    wrdDoc = appWord.Documents.Open(strFileName)

    appWord.Visible =

    True

     

    End Sub

     

    Private Sub GenerateDoc()

     

    Dim i, j As Integer

     

    For i = (lvListView.Columns.Count - 1) To 7 Step -1

    lvListView.Columns.RemoveAt(i)

     

    Next

     

    Dim tblcontents As New C1.C1Preview.RenderTable(c1Pd)

    tblcontents.Style.GridLines.All = LineDef.Empty

    tblcontents.Style.TextAlignHorz = AlignHorzEnum.Left

    tblcontents.Style.Font =

    New Font("Arial", 10)

    tblcontents.Style.TextColor = Color.Black

    tblcontents.CellStyle.Padding.All =

    "1mm"

     

    Dim tblh As New C1.C1Preview.RenderTable(c1Pd)

    tblh.Style.GridLines.All = LineDef.Empty

    tblh.Style.TextAlignHorz = AlignHorzEnum.Left

    tblh.Style.Font =

    New Font("Arial", 10)

    tblh.Style.TextColor = Color.Black

    tblh.CellStyle.Padding.All =

    "1mm"

     

    Dim nrows As Integer = lvListView.Items.Count

     

    Dim ncols As Integer = lvListView.Columns.Count

     

    Dim fr, fh As Font

    fr =

    New Font("Arial", 12, FontStyle.Regular)

    fh =

    New Font("Arial", 14, FontStyle.Bold)

    C1pp.Document = c1Pd

     

    With tblh

    .Style.Font =

    New Font("Arial", 10, FontStyle.Bold)

     

    For j = 0 To lvListView.Columns.Count - 1

    .Cells(0, j).CellStyle.Font =

    New Font("Arial", 10, FontStyle.Bold)

    .Cells(0, j).CellStyle.BackColor = Color.LightGray

    .Cells(0, j).Text = lvListView.Columns(j).Name

     

    Next

     

    End With

     

    Me.c1Pd.Body.Children.Add(tblh)

     

    With tblcontents

    .Style.Font =

    New Font("Arial", 10, FontStyle.Regular)

    .SplitHorzBehavior = C1.C1Preview.SplitBehaviorEnum.SplitNewPage

     

    For i = 0 To nrows - 1

     

    For j = 0 To ncols - 1

    .Cells(i, j).CellStyle.Font =

    New Font("Arial", 10, FontStyle.Regular)

    .Cells(i, j).CellStyle.BackColor = Color.White

     

    If Not IsDBNull(lvListView.Items(i).SubItems(j)) Then

    .Cells(i, j).Text = lvListView.Items(i).SubItems(j).Text

     

    Else

    .Cells(i, j).Text =

    ""

     

    End If

     

    Next

     

    Next

     

    End With

     

    Me.c1Pd.Body.Children.Add(tblcontents)

     

    Dim pl As New PageLayout()

    pl.PageSettings =

    New C1PageSettings()

    pl.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter

    pl.PageSettings.Landscape =

    True

    c1Pd.PageLayouts.Default = pl

     

    Dim pf As New RenderText()

    pf.Text =

    "[PageNo] of [PageCount]"

    pf.Style.Borders.All = LineDef.Empty

    pf.Style.BackColor = Color.Transparent

    pl.PageFooter = pf

     

    End Sub

    End

    Class

    • Moved by Cindy Meister MVPModerator Wednesday, October 19, 2011 2:02 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Tuesday, October 18, 2011 6:51 PM

Answers

  • The rtf file is in fact created and if I open Word directly and FILE>OPEN and navigate to the file it will open just fine.


    OK, that's a useful piece of information. And no messages at all?

    <<simple test app I made uses a text box to allow the user to speciify the path and name of the file to open. The default text in the text box is C:\Test.rtf.>>

    Could you show us the code of the simple test app, please? And please use the code button provided in the web interface toolbar (second button from the right) when pasting in the code, that will make it more readable. If we're having to struggle with following the code it's not easily possible to try to discern difficulties.

    Run your code in debug mode (open the project in VS and press F5) and note on which line it fails.

    Additional question: the code and Word 2003 are both installed locally, on the same machine?


    Cindy Meister, VSTO/Word MVP
    Thursday, October 20, 2011 6:45 AM
    Moderator

All replies

  • What version of Word was your interop dll was created for?

    What version of Word is installed on the client's machine?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Tuesday, October 18, 2011 7:04 PM
  • I'm not sure what version the dll was created for. It was created by another developer and they no longer work for my company. The version number of the dll is 11.0.5530.0.

    I use Word 2007, but most in my office use 2003. The client is using 2003.

    Tuesday, October 18, 2011 7:46 PM
  • Your app must be developed on the machine with the lowest supoported version of Word.

    Uninstall Word 2007, install Word 2003, remove the the Word reference from your project, then add it again.

     


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Tuesday, October 18, 2011 7:55 PM
  • I did as you suggested and it did not resolve the isssue. Thanks anyway.
    Wednesday, October 19, 2011 1:02 PM
  • Hi Rbelliveau

    As you aren't using the VSTO technology I'm going to move your question to the Word for Developers forum where it will be more on-topic.

    You should be able to determine against which version of Word the project was compiled by looking at the References. What do you see for Word and/or Office?

    If the document gets created then Word certainly does "open". although I see absolutely no code that has to do with creating a document, only with opening an existing one. 

    You may mean "GenerateDoc", but that's not Word object model code. It appears to be some kind of wrapper or tool you're using. But no idea what's going on in the background...

    I'm guessing the problem occurs from the point on where you're actually interoping with Word (New Word.Application). What's a sample file name of the type of document you're trying to open with Documents.Open?


    Cindy Meister, VSTO/Word MVP
    Wednesday, October 19, 2011 2:02 PM
    Moderator
  • Word and Office references are both version 11.0.0.0.

    The code creates the document using a ComponentOne control and then using an export to rtf method to show the document in Word. This may not be the best approach but it's the code I inherited and I have to make it work in short order as a client is beta testing now.

    The simple test app I made uses a text box to allow the user to speciify the path and name of the file to open. The default text in the text box is C:\Test.rtf.

    Wednesday, October 19, 2011 2:28 PM
  • So do you which line of your code raises the error?
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.2 is now available!
    Wednesday, October 19, 2011 2:40 PM
  • It would appear to be the line:

    wrdDoc = appWord.Documents.Open(strFileName)

    This line appears as the second to last line in the Button1 click event.

    Wednesday, October 19, 2011 3:01 PM
  • Word and Office references are both version 11.0.0.0.

    The code creates the document using a ComponentOne control and then using an export to rtf method to show the document in Word. This may not be the best approach but it's the code I inherited and I have to make it work in short order as a client is beta testing now.

    The simple test app I made uses a text box to allow the user to speciify the path and name of the file to open. The default text in the text box is C:\Test.rtf.


    Thank you for the additional detail. My first thought was that an Open XML file was being created that Office 2003 couldn't open because the Compatibility Pack wasn't installed. Apparently, my idea was in the right direction, but the wrong file format..

    I suspect that the RTF file may not be correct. The way to test this would be to try to open the RTF file from within Word 2003, as an end-user (File/Open, navigate to the file and select it.) Can Word open it? Do you get any messages or prompts?


    Cindy Meister, VSTO/Word MVP
    Wednesday, October 19, 2011 3:16 PM
    Moderator
  • The rtf file is in fact created and if I open Word directly and FILE>OPEN and navigate to the file it will open just fine.
    Wednesday, October 19, 2011 4:31 PM
  • The rtf file is in fact created and if I open Word directly and FILE>OPEN and navigate to the file it will open just fine.


    OK, that's a useful piece of information. And no messages at all?

    <<simple test app I made uses a text box to allow the user to speciify the path and name of the file to open. The default text in the text box is C:\Test.rtf.>>

    Could you show us the code of the simple test app, please? And please use the code button provided in the web interface toolbar (second button from the right) when pasting in the code, that will make it more readable. If we're having to struggle with following the code it's not easily possible to try to discern difficulties.

    Run your code in debug mode (open the project in VS and press F5) and note on which line it fails.

    Additional question: the code and Word 2003 are both installed locally, on the same machine?


    Cindy Meister, VSTO/Word MVP
    Thursday, October 20, 2011 6:45 AM
    Moderator