none
Can not edit and continue anymore always get Common Language Runtime detected an invalid program. RRS feed

  • Question

  • Hello,

    I am using VS2012 Ultimate and Excel 2010, with Windows 7 x86.

    Everything was going fine before but I don't what has changed and I get strange errors, can set range values, can't edit & continue anymore, even the code is not working.

    This problem is just causing in a specific project, the others are ok.

            Dim w As Double
    
            For i As Integer = 11 To range_values.GetUpperBound(0)
                Dim Alan As Double, Yuk As Double
                If range_values(i, 2).ToString.IndexOf("pencere", StringComparison.CurrentCultureIgnoreCase) > -1 Then
                    Alan = range_values(i, 4) * range_values(i, 5)
                    Yuk = range_values(i, 5)
                    For j As Integer = 0 To fuga_dic.Count - 1 ' To 0 Step -1
                        Dim Dumy As Double = fuga_dic.Keys(j)
                        If Dumy > Yuk Or j = fuga_dic.Count - 1 Then
                            w = fuga_dic.Values(j)
                            Range("F" & i).FormulaR1C1 = "=RC[-2]*RC[-1]*" & w.ToString
                            Exit For
                        End If
                    Next
    
                ElseIf range_values(i, 2).ToString.IndexOf("kapı", StringComparison.CurrentCultureIgnoreCase) > -1 Then
                    Alan = range_values(i, 4) * range_values(i, 5)
                    w = fuga_dic.Values(fuga_dic.Count - 1)
                    Range("F" & i).FormulaR1C1 = "=RC[-2]*RC[-1]*" & w
                End If
    
            Next

    At line :

    Range("F" & i).FormulaR1C1 = "=RC[-2]*RC[-1]*" & w.ToString

    I get error:

    When I try to e&c

    The same error jumps to the Next line

    Later the code never works

    At button click event:

        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
            Globals.Sheet2.FugaHesap()
        End Sub
    I get:

    System.InvalidProgramException was unhandled by user code
      HResult=-2146233030
      Message=Common Language Runtime detected an invalid program.
      Source=Hesap
      StackTrace:
           at ExcelWorkbook1.Sheet2.FugaHesap()
           at ExcelWorkbook1.KDegerleriControl.Button3_Click(Object sender, EventArgs e)
           at System.EventHandler.Invoke(Object sender, EventArgs e)
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ButtonBase.WndProc(Message& m)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      InnerException:


    The brain of the computer is messed up, I tried to completely transfer code to and empty project, recreated the forms, but nothing changed.

    What can I do?

    Thanks,

    Sunday, December 22, 2013 10:45 AM

All replies

  • The image of giving error in the Next statement is like below:

    Sunday, December 22, 2013 12:02 PM
  • Hello Rusel,

    First of all, I would recommend releasing underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object.

    Also I have found the HRESULT: 0x800A03EC on Worksheet.range forum thread for you.

    Sunday, December 22, 2013 6:51 PM
  • Hi RuselGun

    The first thing I would do in your place is to put some managed error handling into your code using Try...Catch blocks. If there's something in Excel triggering this, it's the only way to get at the underlying error information.

    Please also check whether, in contrast to your other projects, "Embed Interop Types" is activated for the project references to the Office APIs. That can cause odd behavior, most especially not being able to "edit and continue" (although I'd expect a different error message).

    Also, please check the values of the counters, such as i and j to determine whether this is happening at a certain point in the things you're looping. Possibly the value is irrelevant and returning a nonsense object which is throwing the code?

    It might also help if you can check some of the things you're trying to pass into Excel. For example, does the following make sense for the value of w:

      "=RC[-2]*RC[-1]*" & w.ToString


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, December 25, 2013 2:44 PM
    Moderator