Runtime: NRE from PresentationFramework-SystemXmlLinq.dll cctor

Created on 19 Oct 2018  路  24Comments  路  Source: dotnet/runtime

Latest builds of the .NET Core 3 packages have an NRE from a static ctor. The LKG for me was on 10/13, and when I updated on 10/18, get this. This is causing a hard block loading my WPF app on Core.

/cc @ericstj @vatsan-madhavan

              PresentationFramework-SystemXmlLinq.dll!MS.Internal.SystemXmlLinqExtension.SystemXmlLinqExtension()              Unknown
             [Native to Managed Transition]  
             [Managed to Native Transition]  
             PresentationFramework-SystemXmlLinq.dll!MS.Internal.SystemXmlLinqExtension.SystemXmlLinqExtension()              Unknown
             [Native to Managed Transition]  
             [Managed to Native Transition]  
System.Private.CoreLib.dll!System.RuntimeType.CreateInstanceSlow(bool publicOnly, bool wrapExceptions, bool skipCheckThis, bool fillCache)            Unknown
System.Private.CoreLib.dll!System.Activator.CreateInstance(System.Type type, bool nonPublic, bool wrapExceptions)         Unknown
WindowsBase.dll!MS.Internal.AssemblyHelper.LoadExtensionFor(string name)   Unknown
WindowsBase.dll!MS.Internal.AssemblyHelper.ExtensionsForSystemXmlLinq(bool force)    Unknown
PresentationFramework.dll!MS.Internal.SystemXmlLinqHelper.IsXElement(object item)     Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.DataTypeForItem(object item, System.Windows.DependencyObject target, out System.Type type)          Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.FindTemplateResourceInternal(System.Windows.DependencyObject target, object item, System.Type templateType) Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.DefaultSelector.SelectTemplate(object item, System.Windows.DependencyObject container)              Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.ChooseTemplate()              Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.EnsureTemplate()              Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.OnPreApplyTemplate()              Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate()              Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged)           Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV) Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.StackPanel.StackMeasureHelper(System.Windows.Controls.IStackMeasure measureElement, System.Windows.Controls.IStackMeasureScrollData scrollData, System.Windows.Size constraint)       Unknown
PresentationFramework.dll!System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged)           Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, System.Windows.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV) Unknown
PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint)          Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.Window.MeasureOverrideHelper(System.Windows.Size constraint)         Unknown
PresentationFramework.dll!System.Windows.Window.MeasureOverride(System.Windows.Size availableSize)     Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize)     Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize()              Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisualInternal.set(System.Windows.Media.Visual value)   Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisual.set(System.Windows.Media.Visual value)   Unknown
PresentationFramework.dll!System.Windows.Window.SourceWindowHelper.RootVisual.set(System.Windows.Media.Visual value)   Unknown
PresentationFramework.dll!System.Windows.Window.SetRootVisual()              Unknown
PresentationFramework.dll!System.Windows.Window.SetRootVisualAndUpdateSTC()              Unknown
PresentationFramework.dll!System.Windows.Window.SetupInitialState(double requestedTop, double requestedLeft, double requestedWidth, double requestedHeight)          Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow)      Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindowDuringShow()              Unknown
PresentationFramework.dll!System.Windows.Window.SafeCreateWindowDuringShow()              Unknown
PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)      Unknown
PresentationFramework.dll!System.Windows.Window.Show()              Unknown
PresentationFramework.dll!System.Windows.Window.ShowDialog()              Unknown
> NuGetPackageExplorer.dll!PackageExplorer.PackageChooserDialog.ShowDialog(string searchTerm) Line 169    C#
NuGetPackageExplorer.dll!PackageExplorer.PackageChooserService.SelectPackage(string searchTerm) Line 52      C#
NuGetPackageExplorer.dll!PackageExplorer.MainWindow.OpenPackageFromRepository(string searchTerm) Line 335    C#
NuGetPackageExplorer.dll!PackageExplorer.MainWindow.OpenFeedItem_Click(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) Line 303         C#
PresentationCore.dll!System.Windows.Input.CommandBinding.OnExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)          Unknown
PresentationCore.dll!System.Windows.Input.CommandManager.ExecuteCommandBinding(object sender, System.Windows.Input.ExecutedRoutedEventArgs e, System.Windows.Input.CommandBinding commandBinding)          Unknown
PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(System.Windows.Input.CommandBindingCollection commandBindings, object sender, System.Windows.RoutedEventArgs e, System.Windows.Input.ICommand command, bool execute)             Unknown
PresentationCore.dll!System.Windows.Input.CommandManager.FindCommandBinding(object sender, System.Windows.RoutedEventArgs e, System.Windows.Input.ICommand command, bool execute)             Unknown
PresentationCore.dll!System.Windows.Input.CommandManager.OnExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)          Unknown
PresentationCore.dll!System.Windows.UIElement.OnExecutedThunk(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)          Unknown
PresentationCore.dll!System.Windows.Input.ExecutedRoutedEventArgs.InvokeEventHandler(System.Delegate genericHandler, object target)   Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)   Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)            Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)              Unknown
PresentationCore.dll!System.Windows.Input.RoutedCommand.ExecuteImpl(object parameter, System.Windows.IInputElement target, bool userInitiated)     Unknown
PresentationCore.dll!System.Windows.Input.RoutedCommand.ExecuteCore(object parameter, System.Windows.IInputElement target, bool userInitiated)     Unknown
PresentationFramework.dll!MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(System.Windows.Input.ICommandSource commandSource, bool userInitiated)       Unknown
PresentationFramework.dll!MS.Internal.Commands.CommandHelpers.ExecuteCommandSource(System.Windows.Input.ICommandSource commandSource)            Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnClick()              Unknown
PresentationFramework.dll!System.Windows.Controls.Button.OnClick()              Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)          Unknown
PresentationCore.dll!System.Windows.UIElement.OnMouseLeftButtonUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)              Unknown
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)    Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)   Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)            Unknown
PresentationCore.dll!System.Windows.EventRoute.ReInvokeHandlers(object source, System.Windows.RoutedEventArgs args)              Unknown
PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args, System.Windows.RoutedEvent newEvent)           Unknown
PresentationCore.dll!System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(System.Windows.DependencyObject sender, System.Windows.Input.MouseButtonEventArgs e)              Unknown
PresentationCore.dll!System.Windows.UIElement.OnMouseUpThunk(object sender, System.Windows.Input.MouseButtonEventArgs e)              Unknown
PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)    Unknown
PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)   Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)            Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)              Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs args)     Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()              Unknown
PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)    Unknown
PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)      Unknown
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
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
PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)            Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)            Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)          Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)          Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler)            Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)           Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Unknown
             [Native to Managed Transition]  
             [Managed to Native Transition]  
WindowsBase.dll!System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(ref System.Windows.Interop.MSG msg)       Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()              Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)  Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)             Unknown
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)             Unknown
PresentationFramework.dll!System.Windows.Application.Run()              Unknown
        NuGetPackageExplorer.dll!PackageExplorer.App.Main()              Unknown

Most helpful comment

Yep, that's the issue. It showed up as a regression because @rladuca fixed the loading of these extensions. Closing this out for now.

All 24 comments

Yep, that's the issue. It showed up as a regression because @rladuca fixed the loading of these extensions. Closing this out for now.

Thanks. Any hacky workarounds until the main issue is fixed?

Haven't thought through it too much, but calling TypeDescriptor.AddProvider() early enough and adding a private copy of XLinq providers might work.

@onovotny Thanks for reporting this, hit the same issue yesterday. Did you get the workaround working?

@Lakritzator I have not tried yet as it looked like a fair bit of extra code. I've been tracking dotnet/runtime#27548 and hoping it's fixed soon.

@Lakritzator

Patching the cctor with a hex editor is another option. Then you're not blocked for X weeks until this is fixed.

dotnet --version: 3.0.100-alpha1-009697
File: PresentationFramework-SystemXmlLinq.dll
x86 / x64:
File offset 0250
orig: 133002006C00000001000011720100....
 new: 062A

@rladuca can you please take a look at this?

@0xd4d That is a very cool workaround, very easy to apply.
Out of interest, what does this actually do and how did you make this so quickly?

Found the file PresentationFramework-SystemXmlLinq.dll here: C:\Program Files\dotnet\shared\Microsoft.DesktopUI.App\3.0.0-alpha-27017-4
Used an hex editor, replace the bytes on the location 0x0250 with 0x062a, stored, now my application works...

@ericstj Can I attach the binary here, for others, or is this forbidden?

@Lakritzator It replaces the cctor's method body with a 'ret' instruction. 06 = 000001 10 (1 byte body, 10 = small method header kind) and 2A = IL RET instruction.

@0xd4d would another workaround simply be to call the static ctor in a try/catch using reflection early in the main method or would that TypeInitializationException reside and cause problems with future access to that type?

The CLR should remember that the type failed to load and rethrow the same exception (typeinitialization exception) next time some other type references it.

@0xd4d Guess that would have been too easy ;)

Here's another easy workaround that should restore things to pre-regression. The regression here was caused by a fix that started loading the PresentationFramework-SystemXmlLinq.dll file. The code more-or-less looks like the desktop version:
https://referencesource.microsoft.com/#WindowsBase/Base/MS/Internal/AssemblyHelper.cs,231. I don't have your actual report to test it, but deleting that DLL looks like it should work. Of course you won't get the actual behavior provided by that but it should bring things back to pre-regression state.

I have an idea for the fix to dotnet/runtime#27548 that should make that happen quicker.

@ericstj When I renamed that file in both
C:\Users\oren\.nuget\packages\runtime.win-x64.microsoft.desktopui.app\3.0.0-alpha-27017-4\runtimes\win-x64\lib\netcoreapp3.0 and C:\Program Files\dotnet\shared\Microsoft.DesktopUI.App\3.0.0-alpha-27017-4, it doesn't even load.

The program '[12776] NuGetPackageExplorer.exe' has exited with code -2147450740 (0x8000808c).

Please delete this, if it's not allowed (nobody answered my question), but here is the patched DLL (zipped):
PresentationFramework-SystemXmlLinq.zip

This works for me, as a workaround, so I can continue with porting stuff to dotnet core 3.0 and reduce the stress on @ericstj and the rest so they can work on a solution as long as needed.

@Lakritzator which folder did you patch the file in?

@onovotny I copied the file here: C:\Program Files\dotnet\shared\Microsoft.DesktopUI.App\3.0.0-alpha-27017-4 (modify it according to your destination)

Sorry @Lakritzator I didn't notice your question about posting binaries. I'm not so sure we have a policy on that (@richlander would know for sure). Certainly our license permits it and I think its great if members of the community want to help each other out. The only thing I'd caution is that we probably won't investigate a bug report if it requires modification of the binary where that modification could be causing the bug.

The deletion solution would actually need some more work because the host has some knowledge of the contents of shared framework/app via deps files. That might have been what was causing your crash.

One thing I could use that would help in both the workarounds and the actual fix is an isolated repro. Is this as simple as putting an XElement inside a content control?

Also, to @rladuca - you could make a spot fix in SystemXmlLinqExtension by handling null returned from TypeDescriptor.GetProperties if we don't want to wait for a fix in CoreFx.

Let me see if I can cause the crash. Can you repro via the NPE netcore3 branch? I don't believe XElement is directly involved.

The interesting parts of the call stack are here:

indowsBase.dll!MS.Internal.AssemblyHelper.LoadExtensionFor(string name)   Unknown
WindowsBase.dll!MS.Internal.AssemblyHelper.ExtensionsForSystemXmlLinq(bool force)    Unknown
PresentationFramework.dll!MS.Internal.SystemXmlLinqHelper.IsXElement(object item)     Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.DataTypeForItem(object item, System.Windows.DependencyObject target, out System.Type type)          Unknown
PresentationFramework.dll!System.Windows.FrameworkElement.FindTemplateResourceInternal(System.Windows.DependencyObject target, object item, System.Type templateType) Unknown
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.DefaultSelector.SelectTemplate(object item, System.Windows.DependencyObject container)              Unknown

Seems to indicate something to do with implicit data templates may be triggering it?

@ericstj I'll have a spot fix PR today.

With the latest SDK version, 3.0.100-alpha1-009706, the NRE doesn't happen.
The PresentationFramework-SystemXmlLinq.dll is loaded from:
C:\Program Files\dotnet\shared\Microsoft.DesktopUI.App\3.0.0-alpha-27026-2

Confirmed working for me as well! 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omariom picture omariom  路  3Comments

nalywa picture nalywa  路  3Comments

noahfalk picture noahfalk  路  3Comments

jkotas picture jkotas  路  3Comments

GitAntoinee picture GitAntoinee  路  3Comments