Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix COM interop ELEMDESC #1254

Merged
merged 1 commit into from
Jul 2, 2019
Merged

Fix COM interop ELEMDESC #1254

merged 1 commit into from
Jul 2, 2019

Conversation

JeremyKuhne
Copy link
Member

ELEMDESC doesn't contain a pointer. This fixes a regression introduced in #818.

Fixes #896

This particular bug is breaking Office interop on WPF and WinForms. Repro is to reference the following COM components:

  • Microsoft.Office.Interop.Outlook
  • Office
  • stdole

In a WPF app, add the following to the main Window xaml:

<ComboBox ItemsSource="{Binding}" DisplayMemberPath="DisplayName" Height="27" Width="332" />

And the following to the code behind for Window_Loaded:

using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;

// ...
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            List<Account> Accounts = new List<Account>();
            Outlook.Application outlook = new Outlook.Application();
            foreach (Account account in outlook.Session.Accounts)
            {
                Accounts.Add(account);
            }
            this.DataContext = Accounts;
        }

This should be considered for preview 7.

Ultimately we should use the COM types defined in CoreFX to reduce risk and cut the assembly size for WinForms, but making that change is non-trivial for 3.0. #1253

cc: @sharwell, @AaronRobinsonMSFT

ELEMDESC doesn't contain a pointer. This fixes a regression introduced in dotnet#818.

Fixes dotnet#896
@JeremyKuhne JeremyKuhne requested a review from a team as a code owner July 1, 2019 23:46
RussKie added a commit to RussKie/Test-ComInterop-ELEMDESC that referenced this pull request Jul 2, 2019
@RussKie
Copy link
Member

RussKie commented Jul 2, 2019

Could you please help me with repro steps?

I've created a test .NET Core 3.0 app https://github.com/RussKie/Test-ComInterop-ELEMDESC with the above code snippet.
I have built against WinForms @ c87f30f and against your change - the observable results were identical, I didn't get any errors.
image

I'm guessing I'm not exercising the intended code path (since I don't fully understand the underlying issue).

Thanks

@JeremyKuhne
Copy link
Member Author

I'm not sure how to repro in a similar way with a WinForms app. The call stack for WPF is below. The native COM TypeDescriptor uses WinForms through reflection. Here is where it gets hooked up:

https://source.dot.net/#System.ComponentModel.TypeConverter/System/ComponentModel/TypeDescriptor.cs,2877

I haven't done much of anything with TypeDescriptors or System.ComponentModel so I can't help you much more at the moment. I've got a lot to learn here as well. (@maryamariyan, @safern, take note)

 	System.Windows.Forms.dll!System.Windows.Forms.ComponentModel.Com2Interop.Com2TypeInfoProcessor.InternalGetProperties(object obj, System.Windows.Forms.UnsafeNativeMethods.ITypeInfo typeInfo, int dispidToGet, ref int defaultIndex)	Unknown	No symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ComponentModel.Com2Interop.Com2TypeInfoProcessor.GetProperties(object obj)	Unknown	No symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor.GetPropsInfo(object component)	Unknown	No symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor.GetProperties(object component, System.Attribute[] attributes)	Unknown	No symbols loaded.
 	System.Windows.Forms.dll!System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor.ComTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()	Unknown	No symbols loaded.
 	System.ComponentModel.TypeConverter.dll!System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()	Unknown	No symbols loaded.
 	System.ComponentModel.TypeConverter.dll!System.ComponentModel.TypeDescriptor.GetPropertiesImpl(object component, System.Attribute[] attributes, bool noCustomTypeDesc, bool noAttributes)	Unknown	No symbols loaded.
 	System.ComponentModel.TypeConverter.dll!System.ComponentModel.TypeDescriptor.GetProperties(object component)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.PropertyPath.ResolvePropertyName(string name, object item, System.Type ownerType, object context, bool throwOnError)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.GetInfo(int k, object item, ref MS.Internal.Data.PropertyPathWorker.SourceValueState svs)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.ReplaceItem(int k, object newO, object parent)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.AttachDataItem()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt attempt)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachOverride(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Attach(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.OnAttach(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.GetInstanceValue(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElement feChild, System.Windows.FrameworkContentElement fceChild, int childIndex, System.Windows.DependencyProperty dp, int i, ref System.Windows.EffectiveValueEntry entry)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.GetChildValueHelper(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, ref MS.Utility.ItemStructList<System.Windows.ChildValueLookup> valueLookupList, System.Windows.DependencyProperty dp, System.Windows.DependencyObject container, MS.Internal.FrameworkObject child, int childIndex, bool styleLookup, ref System.Windows.EffectiveValueEntry entry, out System.Windows.ValueLookupType sourceType, System.Windows.FrameworkElementFactory templateRoot)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.GetChildValue(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, int childIndex, MS.Internal.FrameworkObject child, System.Windows.DependencyProperty dp, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, ref System.Windows.EffectiveValueEntry entry, out System.Windows.ValueLookupType sourceType, System.Windows.FrameworkElementFactory templateRoot)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.GetValueFromTemplatedParent(System.Windows.DependencyObject container, int childIndex, MS.Internal.FrameworkObject child, System.Windows.DependencyProperty dp, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, System.Windows.FrameworkElementFactory templateRoot, ref System.Windows.EffectiveValueEntry entry)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplatedParentValue(System.Windows.DependencyObject container, MS.Internal.FrameworkObject child, int childIndex, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, System.Windows.DependencyProperty dp, System.Windows.FrameworkElementFactory templateRoot)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(System.Windows.DependencyObject container, MS.Internal.FrameworkObject child, int childIndex, ref MS.Utility.FrugalStructList<System.Windows.ChildRecord> childRecordFromChildIndex, bool isDetach, System.Windows.FrameworkElementFactory templateRoot)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElementFactory.InstantiateTree(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.DependencyObject parent, System.Collections.Generic.List<System.Windows.DependencyObject> affectedChildren, ref System.Collections.Generic.List<System.Windows.DependencyObject> noChildIndexChildren, ref MS.Utility.FrugalStructList<System.Windows.ChildPropertyDependent> resourceDependents)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> dataField, System.Windows.DependencyObject container, System.Windows.FrameworkElementFactory templateRoot, int lastChildIndex, System.Collections.Specialized.HybridDictionary childIndexFromChildID, System.Windows.FrameworkTemplate frameworkTemplate)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField<System.Collections.Specialized.HybridDictionary[]> templateDataField, System.Windows.FrameworkElement container)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.StackPanel.StackMeasureHelper(System.Windows.Controls.IStackMeasure measureElement, System.Windows.Controls.IStackMeasureScrollData scrollData, System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.ItemsPresenter.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.ScrollContentPresenter.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.ScrollViewer.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.PopupRoot.MeasureOverride(System.Windows.Size constraint)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize()	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisualInternal.set(System.Windows.Media.Visual value)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisual.set(System.Windows.Media.Visual value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.CreateWindow(bool asyncCall)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Invalidate(bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourceInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, bool isASubPropertyChange)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.HandlePropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.OnPropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependentList.InvalidateDependents(System.Windows.DependencyObject source, System.Windows.DependencyPropertyChangedEventArgs sourceArgs)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.SetValue(object item, object value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.UpdateValue(object value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateSource(object value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.UpdateValue()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpression.UpdateOverride()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Update()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.ProcessDirty()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Dirty()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.SetValue(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, object value)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.DependencyObject.SetCurrentValueInternal(System.Windows.DependencyProperty dp, object value)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ToggleButton.OnToggle()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ToggleButton.OnClick()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.OnMouseLeftButtonDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RouteItem.InvokeHandler(System.Windows.RoutedEventArgs routedEventArgs)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.EventRoute.ReInvokeHandlers(object source, System.Windows.RoutedEventArgs args)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, System.Windows.RoutedEvent newEvent)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(System.Windows.DependencyObject sender, System.Windows.Input.MouseButtonEventArgs e)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.OnMouseDownThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.RouteItem.InvokeHandler(System.Windows.RoutedEventArgs routedEventArgs)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.EventRoute.InvokeHandlers(object source, System.Windows.RoutedEventArgs args)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args, bool trusted)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown	No symbols loaded.
 	PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown	No symbols loaded.
 	WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)	Unknown	No symbols loaded.
 	WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)	Unknown	No symbols loaded.
 	WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)	Unknown	No symbols loaded.
 	[Native to Managed Transition]		Annotated Frame
 	[Managed to Native Transition]		Annotated Frame
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)	Unknown	No symbols loaded.
 	WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)	Unknown	No symbols loaded.
 	PresentationFramework.dll!System.Windows.Application.Run()	Unknown	No symbols loaded.
 	ComBindingCore.dll!ComBindingCore.App.Main()	Unknown	Symbols loaded.

@RussKie
Copy link
Member

RussKie commented Jul 2, 2019

Do you a repro app available by a chance?

@weltkante
Copy link
Contributor

Can someone comment on the interop/marshaling rules here? In #818 I was assuming that in Desktop Framework, being defined as a class it should already have been marshaled by reference instead of being inlined.

What I can see calling Marshal.SizeOf is that in (64 bit) Desktop the tagELEMENT size is 32 byte (which is correct) and in Core it is just 24 byte leading to an AccessViolation.

/cc @sharwell

@wtgodbe
Copy link
Member

wtgodbe commented Jul 2, 2019

Approved for preview7

@wtgodbe wtgodbe merged commit 2b3a4a4 into dotnet:master Jul 2, 2019
@JeremyKuhne JeremyKuhne deleted the fixelemdesc branch July 2, 2019 17:45
wtgodbe pushed a commit to wtgodbe/winforms that referenced this pull request Jul 2, 2019
ELEMDESC doesn't contain a pointer. This fixes a regression introduced in dotnet#818.

Fixes dotnet#896
@ericstj
Copy link
Member

ericstj commented Jul 2, 2019

Shouldn't a test be added for this? @AaronRobinsonMSFT can you help with that since it looks like @sharwell tried without luck to get coverage? I'd hate for this scenario to regress again.

AdamYoblick pushed a commit that referenced this pull request Jul 2, 2019
ELEMDESC doesn't contain a pointer. This fixes a regression introduced in #818.

Fixes #896
@JeremyKuhne
Copy link
Member Author

Shouldn't a test be added for this?

We can add some unit tests for it. I've been speaking with @RussKie a bit about it and looking into .NET's dependency on this WinForms code. It might also be possible to add some light scenario tests if Office components happen to be registered.

@JeremyKuhne
Copy link
Member Author

Can someone comment on the interop/marshaling rules here?

@weltkante I added an exhaustive rundown of properly defining ELEMDESC in my Interop project. The short of it is that the struct for TYPEDESC is 2 pointers in size (16 bytes on 64 bit), while the pointer to TYPEDESC is (obviously) one pointer in size. PARAMDESC is also 2 pointers in size. Together they make a struct of 32 bytes.

On desktop this was defined as a class, which is really sub-optimal. You do get pass-by-ref semantics by default in interface definitions, but it requires allocating on the managed heap and a native allocation and two way copy by the marshaling layer. It is orders of magnitude faster to have a blittable struct definition and pass that by ref as the marshaling layer will simply pin the data on interop calls.

When it isn't the right size, all of the pointer accesses are going to be pretty much random (hence the AV).

@AaronRobinsonMSFT
Copy link
Member

Shouldn't a test be added for this?

We can add some unit tests for it. I've been speaking with @RussKie a bit about it and looking into .NET's dependency on this WinForms code. It might also be possible to add some light scenario tests if Office components happen to be registered.

We have two options here.

The first is related to what @JeremyKuhne mentioned above and consume an existing COM class that exposes a property (e.g. consume an Office installed class). This is generally a bad idea because the assumes a specific machine configuration - just bad. There are probably some Windows classes that could be used, but again this depends on a machine configuration which is bad.

An alternative approach would be to define/build/consume a COM server to be used in testing. This follows the coreclr repos approach, makes testing far more stable, and allows us to add additional scenarios without having to search for one that "kind of" works. .NET Core 3.0 SDK supports creating/consuming managed COM servers so this should be relatively easy. On top of the ability to author one, consumption can be done through RegFree COM which makes this scenario extremely reliable since the testing environment is self contained and won't pollute the build/developer's machine.

I could imagine additional tricks to exercise this scenario, but honestly I would recommend the latter rather than the former or some cleverness that makes debugging or understand the test difficult. We on the interop team have strived to make COM as consistent with the official COM story as possible in .NET Core so the more we follow official COM idioms the more reliable these scenarios will be.

@RussKie
Copy link
Member

RussKie commented Jul 3, 2019

@AaronRobinsonMSFT could you please add a test(s) or at least a demo app in which we could repo the original issue and then see it fixed (replacing binaries). So we can pass it on to our testers.
Thanks

@AaronRobinsonMSFT
Copy link
Member

@RussKie The description in the PR written by @JeremyKuhne was taken from the original offline report of the issue and is basically the entire app - minus project system boiler plate. In fact, @JeremyKuhne was on that thread if I recall and verified the app worked with his fix.

As an aside, I would not rely on that app in any capacity. It exercises such a narrow code path relative to the COM scenario. My fear is this small app becomes the glorified sniff test for COM interaction with WPF and that is just not the case. Please do not simply pass it off to a team to use as the test, it is a helpful start but rather silly being considered any kind of actual validation of the COM scenario.

@RussKie
Copy link
Member

RussKie commented Jul 3, 2019

I have created a WinForms app (#1254 (comment)) and was not able to see failures.
@JeremyKuhne also didn't know how to repro it in WinForms (#1254 (comment))

@JeremyKuhne Jeremy Kuhne FTE was on that thread if I recall and verified the app worked with his fix.

Could you please share this with us?

@AaronRobinsonMSFT
Copy link
Member

@RussKie Oh sorry. I missed that. I will share this offline.

RussKie pushed a commit that referenced this pull request Jul 3, 2019
ELEMDESC doesn't contain a pointer. This fixes a regression introduced in #818.

Fixes #896

(cherry picked from commit 52be7e5)
@@ -719,7 +719,7 @@ private static void ProcessFunctions(UnsafeNativeMethods.ITypeInfo typeInfo, IDi

unsafe
{
typeDesc = *funcDesc.elemdescFunc.tdesc;
typeDesc = funcDesc.elemdescFunc.tdesc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all the unsafe blocks still needed? (Also in the definition of the struct.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't needed but I think this specific insertion was for preview 7 so I assumed less code churn was preferred. They definitely should be removed after preview 7 though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was going for the minimal change for preview 7. :)

@JeremyKuhne
Copy link
Member Author

Could you please share this with us?

@RussKie Ugh, sorry. I shared it with you offline as well, but autocomplete sent it to someone else who didn't tell me.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix ELEMDESC native interop definition
7 participants