This project has moved. For the latest updates, please go here.


Exception when typing - IronPython


I have seen it in 1.5, 2.0 alpha and beta. Periodically there is an error dialog popping with:
Visual Studio has encountered an exception. This may be caused by extension.
You can get more information ...
The devenv.log attached.
I can upload entire project file if it's necessary.
I am using IronPython 2.7.4 beta and VS2010 on win7-32

[Zooba]: The error:
System.InvalidOperationException: Specified element is already the logical child of another element. Disconnect it first.
   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent, Object newContent)
   at System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Microsoft.PythonTools.Intellisense.CompletionControl..ctor(UIElement view, ICompletionSession session)
   at Microsoft.PythonTools.Intellisense.CompletionUIElementProvider.GetUIElement(CompletionSet itemToRender, ICompletionSession context, UIElementType elementType)
   at Microsoft.VisualStudio.Language.Intellisense.Implementation.Helpers.<>c__DisplayClass8`2.<FindUIElement>b__6(IUIElementProvider`2 provider)
   at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.InstantiateExtension[TExtension,TMetadata,TExtensionInstance](Object errorSource, Lazy`2 provider, Func`2 getter)

file attachments


Zooba wrote Jun 27, 2013 at 5:56 PM

We've seen the message box as well (and fixed many of them), but this looks like a new cause. Thanks for the report, we'll take a look.

(At first glance, it seems like the completion control we're wrapping in ours is being reused, even though we're not. It may just be a case of clearing the original one out whenever we're closed.)

dinov wrote Jul 17, 2013 at 10:25 PM

Does this repro consistently for you w/ your project? If so could you upload the project + repro steps? I've been trying to track down what might cause this, but so far no luck :(

paweljasinski wrote Jul 18, 2013 at 2:59 PM

this is very likely related or the same as
Unfortunately I did not capture devenv.log. Fortunately I made a snapshot of the project which triggered the problem. I will send link directly to ptvshelp

paweljasinski wrote Jul 18, 2013 at 3:10 PM

it happened again, this time in beta.
devenv.log attached

paweljasinski wrote Jul 18, 2013 at 3:26 PM


Zooba wrote Jul 18, 2013 at 4:40 PM

This is completely unrelated to 1472 (which is just as well, or we'd be in a lot of trouble...), it seems to be the same thing as I mentioned above. All the attached logs show the error I added to the description.

Dino - might the contract for CompletionUIElementProvider.GetUIElement have changed recently? It looks like the VS one caches their result but ours doesn't.

dinov wrote Jul 18, 2013 at 5:47 PM

VS caches their result, but that shouldn't matter, they only re-use it if it's not still attached to the completion session, and there can be cases where it doesn't cache the result.

I was initially concerned that if our control lingered around w/ VS's control as a child that we would get this exception, but I forced our control to be leaked and the issue doesn't repro. So I haven't been able to find a way to make VS's control be in the visual tree twice.

paweljasinski wrote Jul 19, 2013 at 8:38 AM

I noticed very reliable way to trigger the error message.
Once you open my project and try to type:

ExtractContext is a module
asdfg can be anything not on the auto complete list

dinov wrote Jul 19, 2013 at 5:54 PM

Is there a specific file I should try that in? I tried it in and it worked fine for me :(

Looking at the devenv log one possibility here might be a clash between PTVS & Resharper, if they provide their own completion presenter we might be wrapping theirs instead of the default, which . If that's the case we could certainly become more restrictive about what controls we are willing to wrap. Could you temporarily disable ReSharper and see if the issue goes away?

paweljasinski wrote Jul 20, 2013 at 8:31 AM

I have retested with and without reshaper (disabled but not uninstalled), in both cases the same.
I also checked
The sequence is:
open VS
line 21 type: ExtractContext.asd<Ctrl><Space>
This happens only once after VS restart. Any consecutive attempts will not produce exception. If I see the error second time within a session, I will report it.

I have filed original report with most of extentions (reshaper, productivity power tools) disabled. At the moment, the only things still active are: ankhhSVN, Microsoft.VisualStudio.InteractiveWindow, WixToolset

paweljasinski wrote Jul 20, 2013 at 8:38 AM

There is another thing. The project I have give you is part of the solution. There are other c# projects within this solution which I did not upload. I will make a fresh snapshot and upload the whole thing but it will take a moment.

dinov wrote Jul 22, 2013 at 11:31 PM

Thanks for trying that... I think I might finally know what's going on, it looks like there was a fix in WPF in .NET 4.5 which changed the behavior when reparenting a control so it would be a little more flexible, and I'm guessing you don't have 4.5 installed. I'll setup a VM to confirm, but if that's the case, I believe the fix is pretty easy. I'll report back when I find out more.

dinov wrote Jul 23, 2013 at 9:22 PM

Ok, unfortunately I'm still not getting a repro even when I'm on a machine w/o .NET 4.5... Could I e-mail you a private build that I suspect would fix the issue? Or if you're setup to build PTVS from source you could modify CompletionControl.xaml.cs so that it implements IDisposable and just does "Content = null;" in it's dispose method.

paweljasinski wrote Jul 24, 2013 at 10:30 AM

Private Build would be better.
I did manage to build PTVS once, but it was over a year ago with version 1.5

paweljasinski wrote Jul 25, 2013 at 9:20 AM

I just installed private build delivered via email, and I can not reproduce the problem anymore. I have tested with and without resharper.

dinov wrote Jul 25, 2013 at 6:36 PM

Awesome, thanks for sticking through to the end! I'll go ahead and get the fix reviewed and committed.