Ask a questionAsk a question
 

AnswerNetFwTypeLib and ComElevation dllhost fails to exit

  • Thursday, October 22, 2009 8:06 AMelement109 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am using the comelevation sample from the vistabridge library in the windows sdk to elevate a .net class I exported to a com typelib.

    To demonstrate what I have done consider something like this:

        class Firewall:IDisposable
        {
            INetFwPolicy2 policy = (INetFwPolicy2)Activator.CreateInstance(...);
           
            bool FirewallEnabled
            {
                get { return policy.get_FirewallEnabled(profileType2); }
                set { policy.set_FirewallEnabled(profileType2, value); }
            }
    
            void EnableRule(string group, string ruleName, bool enable)
            {
                IEnumerator enumerator = null;
    
                try
                {
                    enumerator = this.policy.Rules.GetEnumerator();
    
                    while (enumerator.MoveNext())
                    {
    
                        INetFwRule iNetRule = (INetFwRule)enumerator.Current;
    
                        if (string.Equals(iNetRule.Grouping, group, StringComparison.OrdinalIgnoreCase))
                        {
                            if (string.Equals(iNetRule.Name, ruleName, StringComparison.OrdinalIgnoreCase))
                            {
                                iNetRule.Enabled = enable;
                                Marshal.ReleaseComObject(iNetRule);
                                break;
                            }
                        }
                        Marshal.ReleaseComObject(iNetRule);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
    
    
    

     

    public void Dispose()

    {

     

    Marshal.ReleaseComObject(policy.Rules);

     

    Marshal.ReleaseComObject(policy);

    }

    }
    When I create my elevated com object and change the value of the property, all is well. When I do the same and call the function, it works but the dllhost process fails to exit. I am calling Marshal.ReleaseComObject on my elevated class. I narrowed the problem down to: Any time I iterate through the INetFwPolicy2.Rules the dllhost process fails to exit. In the above codeblock the function calls Marshal.Release... on each rule, I have tried without this call as well to no avail.

    Any thoughts?

    1000001 1100001 1110010 1101111 1101110 100000 1000001 1110011 1101000 1100101 1110010
    • Edited byelement109 Thursday, October 22, 2009 8:24 AMForgot to mention IDisposable
    •  

Answers

All Replies