locked
Problem with Combination of Add-in and Custom Designer RRS feed

  • Question

  • Hello,

    I have created a VS add-in. The add-in's connect() method sets a static property on one of my classes to true . I have also created a VS custom designer. The designer finds the value of the static property to be false . In an attempt to understand this I have added debugging code to the static property.

    Here is the definition of the property:

            private static bool mIsDesignTime;

            public static bool IsDesignTime
            {
                get
                {
                    unsafe
                    {
                        fixed (bool* thePointer = &mIsDesignTime)
                        {
                            FileHelper.WriteToFile(string.Format("Get: IsDesignTime = {0}, Address = {1}, AppDomain = {2}{3}", mIsDesignTime, (int)thePointer, AppDomain.CurrentDomain.FriendlyName, Environment.NewLine), @"C:\Temp\Debug.txt");
                        }
                    }
                    return mIsDesignTime;
                }
                set
                {
                    mIsDesignTime = value;
                    unsafe
                    {
                        fixed (bool* thePointer = &mIsDesignTime)
                        {
                            FileHelper.WriteToFile(string.Format("Set: IsDesignTime = {0}, Address = {1}, AppDomain = {2}{3}", mIsDesignTime, (int) thePointer, AppDomain.CurrentDomain.FriendlyName, Environment.NewLine), @"C:\Temp\Debug.txt");
                        }
                    }
                }
            }

     

    Here is what gets written to the file:

    Set: IsDesignTime = True, Address = 81570324, AppDomain = DefaultDomain
    Get: IsDesignTime = False, Address = 527689248, AppDomain = DefaultDomain
    Get: IsDesignTime = False, Address = 527689248, AppDomain = DefaultDomain
    Get: IsDesignTime = False, Address = 527689248, AppDomain = DefaultDomain
    Get: IsDesignTime = False, Address = 527689248, AppDomain = DefaultDomain

    Note that the address of the static bool mIsDesignTime has changed between the times that the add-in set it and the custome designer got it. It is as though VS has reloaded the class.

    Would you please help me to understand this behavior so that I can make the correct choices as I continue to develop my add-in and my custom designer?

    Thank you,

    Robert

    Thursday, October 21, 2010 7:48 PM

Answers

  • Hi Robert,

    I suspect you have two different copies of the designer assembly loaded here. If you debug your scenario, and view the Modules toolwindow, do you see two instances of your assembly loaded? If so, I suspect one is a shadow copy that the winform designer uses (so that we don't lock the references designer assembly in the event it's part of the project being debugged. The only way to work around this is to gac the designer assembly, or deploy it into one of the paths on the devenv.exe search path (...Common7\IDE, ....\Common7\IDE\PublicAssemblies, or ...\Common7\IDE\PrivateAssemblies.

    Sincerely,


    Ed Dore
    Friday, October 22, 2010 5:16 AM

All replies

  • Hi Robert,

    I suspect you have two different copies of the designer assembly loaded here. If you debug your scenario, and view the Modules toolwindow, do you see two instances of your assembly loaded? If so, I suspect one is a shadow copy that the winform designer uses (so that we don't lock the references designer assembly in the event it's part of the project being debugged. The only way to work around this is to gac the designer assembly, or deploy it into one of the paths on the devenv.exe search path (...Common7\IDE, ....\Common7\IDE\PublicAssemblies, or ...\Common7\IDE\PrivateAssemblies.

    Sincerely,


    Ed Dore
    Friday, October 22, 2010 5:16 AM
  • Ed,

    You are a prince among men!  Yes indeed, two copies of the assembly. Thank you very much for helping me to understand.

    Best Regards,

    Robert

     

    Friday, October 22, 2010 2:36 PM