none
How to keep VSTO Excel named range proxy object in local hashtable RRS feed

  • Question

  • To gain better performance, we use hashtable in our app to cache used named ranges in excel 2003 plug-in.

    We run into a problem when a large number of named ranges stored in the hashtable, some of them become obsolete. This only happens intermediately. I am not sure if they are sort of garbage collected or out of scope. My question is how do we keep these proxy object valid while the applicaiton is running. do we have any control over the lifecycle of these objects??

    Thanks a lot 

    The error is as follows:

    System.Runtime.InteropServices.COMException (0x800A01A8): Exception from HRESULT: 0x800A01A8

    Server stack trace:

     

    Exception rethrown at [0]:

    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

    at Microsoft.Office.Interop.Excel.Range.get_Value(Object RangeValueDataType)

    Monday, March 14, 2011 3:44 PM

Answers

  • Hi Peter,

    Thanks for posting in the MSDN Forum.

    This is the snippet that I want to reproduce your issue via it. And it work fine on my side.

    using System;
    using System.Data;
    using System.Collections;
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.VisualStudio.Tools.Applications.Runtime;
    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
    
    namespace ExcelWorkbook7
    {
      public partial class Sheet1
      {
        private Hashtable ht;
        private void Sheet1_Startup(object sender, System.EventArgs e)
        {
          ht = new Hashtable();
          ht.Add("n1", namedRange1);
          ht.Add("n2", namedRange2);
          ht.Add("n3", namedRange3);
          ht.Add("n4", namedRange4);
          ht.Add("n5", namedRange5);
          ht.Add("n6", namedRange6);
        }
    
        private void Sheet1_Shutdown(object sender, System.EventArgs e)
        {
        }
    
        #region VSTO Designer generated code
    
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
          this.comboBox1.SelectedValueChanged += new System.EventHandler(this.comboBox1_SelectedValueChanged);
          this.Shutdown += new System.EventHandler(this.Sheet1_Shutdown);
          this.Startup += new System.EventHandler(this.Sheet1_Startup);
    
        }
    
        #endregion
    
        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
          Microsoft.Office.Tools.Excel.NamedRange n = (Microsoft.Office.Tools.Excel.NamedRange)ht[comboBox1.Text];
          n.Value = "Hello, this is " + comboBox1.Text;
        }
    
      }
    }
    

    According to your description, you lost the object instance in your process. However, I’m not able find the relate information in you post. In the post, I notice that you use RealProxy in your process. I’m wondering whether you lost your object instance at there. Would you please show us your Proxy snippet?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, March 16, 2011 6:07 AM
    Moderator