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

MS.Internal.Invariant.get_IsDialogOverrideEnabled() can throw NullReferenceException #6772

Closed
VladimirKhil opened this issue Jul 9, 2022 · 4 comments · Fixed by #6785
Closed
Assignees
Labels
Bug Product bug (most likely) Investigate Requires further investigation by the WPF team.

Comments

@VladimirKhil
Copy link
Contributor

  • .NET Core Version: 6.0

I have only the exception stack trace collected automatically from one of my clients. No other system information is available.

I hope that this stack trace would be useful for some research.

According to sources, IsDialogOverrideEnabled could throw NRE if registry key "Software\Microsoft\.NETFramework" is missing on the machine.

System.NullReferenceException: Object reference not set to an instance of an object. at bool MS.Internal.Invariant.get_IsDialogOverrideEnabled() at void MS.Internal.Invariant.Assert(bool condition) at IFontFamily System.Windows.Media.FontFamily.get_FirstFontFamily() at double System.Windows.Media.FontFamily.get_LineSpacing() at double System.Windows.Controls.TextBox.GetLineHeight() at void System.Windows.Controls.TextBox.SetScrollViewerMinMaxHeight() at Size System.Windows.Controls.TextBox.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.DockPanel.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at Size System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size Microsoft.Windows.Themes.ClassicBorderDecorator.MeasureOverride(Size availableSize) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.Grid.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at void System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) at void System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged) at Size System.Windows.Controls.Grid.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.Control.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at void System.Windows.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) at void System.Windows.Controls.Grid.MeasureCellsGroup(int cellsHead, Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged) at Size System.Windows.Controls.Grid.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.Grid.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at Size System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.Border.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size System.Windows.Controls.Control.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at Size MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) at Size System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize) at void System.Windows.UIElement.Measure(Size availableSize) at void System.Windows.ContextLayoutManager.UpdateLayout() at object System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) at void System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at void System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) at object System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) at object System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs) at object System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)

@singhashish-wpf
Copy link
Member

@VladimirKhil While it is true that there could be NRE if the Registry key isn't present, and the remediation could be as simple as a null check, Will it be possible for to update the issue with a minimal repro and would you be interested in submitting a PR?

@VladimirKhil
Copy link
Contributor Author

@VladimirKhil While it is true that there could be NRE if the Registry key isn't present, and the remediation could be as simple as a null check, Will it be possible for to update the issue with a minimal repro and would you be interested in submitting a PR?

Unfortunately I do not know how to reproduce this issue in real environment. The only way that I can suggest is to create a Unit test with mocked Registry which could cause the error.

Yes, I can try to submit a PR.

@lindexi
Copy link
Member

lindexi commented Jul 12, 2022

I can sure the win7 (since 2013) has created the Software\Microsoft\.NETFramework register key. We can ignore this error in .NET Framework, because if the system has this error, it will not be able to start the application. But now that we use .NET Core, I will no longer require .NET Framework to be installed correctly on the system.

VladimirKhil added a commit to VladimirKhil/wpf that referenced this issue Jul 12, 2022
…hen .NET Framework Registry key (HKLM\Software\Microsoft\.NETFramework) is not present on the machine

dotnet#6772
@VladimirKhil
Copy link
Contributor Author

I have created a PR: #6785

@lindexi lindexi added Bug Product bug (most likely) and removed 🪲 bug labels Jul 13, 2022
dipeshmsft added a commit that referenced this issue Oct 26, 2022
…6785)

* Fix NullReferenceException in Invariant.get_IsDialogOverrideEnabled when .NET Framework Registry key (HKLM\Software\Microsoft\.NETFramework) is not present on the machine

#6772

* Update src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs

Co-authored-by: Dipesh Kumar <[email protected]>

* Remove unnecessary declarations

Co-authored-by: Dipesh Kumar <[email protected]>
@ghost ghost removed the 🚧 work in progress label Oct 26, 2022
singhashish-wpf pushed a commit that referenced this issue Nov 1, 2022
…6785)

* Fix NullReferenceException in Invariant.get_IsDialogOverrideEnabled when .NET Framework Registry key (HKLM\Software\Microsoft\.NETFramework) is not present on the machine

#6772

* Update src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Invariant.cs

Co-authored-by: Dipesh Kumar <[email protected]>

* Remove unnecessary declarations

Co-authored-by: Dipesh Kumar <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Nov 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Product bug (most likely) Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants