dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.03k stars 1.17k forks source link

AccessViolationException - Unable to Lauch few WPF applications on few VM machines #5493

Open gnanamu opened 2 years ago

gnanamu commented 2 years ago

Launch the application from desktop icon.

Actual: Nothing happens, AccessViolationException error is logged Application EventLog.

Expected: Application should launch successfully

Event Viewer Log

Faulting application name: ComponentBrowser.exe, version: 1.14.4.0, time stamp: 0x60d07906 Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000 Exception code: 0xc0000005 Fault offset: 0x0000000000000000 Faulting process id: 0x2b78 Faulting application start time: 0x01d7bc4b94aa12b3 Faulting application path: C:\Program Files\Sample\ComponentBrowser.exe Faulting module path: unknown Report Id: 705073b0-3f7d-452b-ba75-885809c319fe Faulting package full name:

Faulting package-relative application ID:

=====================

Application: ComponentBrowser.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException at MS.Internal.FontCache.FontSourceCollection.System.Collections.Generic.IEnumerable.GetEnumerator() at MS.Internal.Text.TextInterface.FontCollectionLoader.CreateEnumeratorFromKey(IntPtr, Void, UInt32, IntPtr) at MS.Internal.Text.TextInterface.Factory.GetFontCollection(System.Uri) at MS.Internal.FontCache.DWriteFactory.GetFontCollectionFromFileOrFolder(System.Uri, Boolean) at System.Windows.Media.FontFamily.LookupFontFamilyAndFace(MS.Internal.FontCache.CanonicalFontFamilyReference, System.Windows.FontStyle ByRef, System.Windows.FontWeight ByRef, System.Windows.FontStretch ByRef) at System.Windows.Media.FontFamily.FindFirstFontFamilyAndFace(System.Windows.FontStyle ByRef, System.Windows.FontWeight ByRef, System.Windows.FontStretch ByRef) at System.Windows.Media.Typeface.ConstructCachedTypeface() at System.Windows.Media.Typeface.get_CachedTypeface() at MS.Internal.TextFormatting.TextStore.FetchTextRun(Int32) at MS.Internal.TextFormatting.TextStore.FetchLSRun(Int32, System.Windows.Media.TextFormattingMode, Boolean, MS.Internal.TextFormatting.Plsrun ByRef, Int32 ByRef, Int32 ByRef) at MS.Internal.TextFormatting.LineServicesCallbacks.FetchRunRedefined(IntPtr, Int32, Int32, IntPtr, Char, Int32, Int32 ByRef, Char ByRef, Int32 ByRef, Int32 ByRef, MS.Internal.TextFormatting.LsChp ByRef, IntPtr ByRef) at MS.Internal.TextFormatting.UnsafeNativeMethods.LoCreateLine(IntPtr, Int32, Int32, Int32, UInt32, IntPtr, MS.Internal.TextFormatting.LsLInfo ByRef, IntPtr ByRef, Int32 ByRef, MS.Internal.TextFormatting.LsLineWidths ByRef) at System.Windows.Media.TextFormatting.TextFormatterContext.CreateLine(Int32, Int32, Int32, MS.Internal.TextFormatting.LineFlags, IntPtr, IntPtr ByRef, MS.Internal.TextFormatting.LsLInfo ByRef, Int32 ByRef, MS.Internal.TextFormatting.LsLineWidths ByRef) at MS.Internal.TextFormatting.TextMetrics+FullTextLine.FormatLine(MS.Internal.TextFormatting.FullTextState, Int32, Int32, Int32, Int32, Int32, MS.Internal.TextFormatting.LineFlags, MS.Internal.TextFormatting.FormattedTextSymbols) at MS.Internal.TextFormatting.TextMetrics+FullTextLine..ctor(MS.Internal.TextFormatting.FormatSettings, Int32, Int32, Int32, MS.Internal.TextFormatting.LineFlags) at MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(System.Windows.Media.TextFormatting.TextSource, Int32, Int32, Double, System.Windows.Media.TextFormatting.TextParagraphProperties, System.Windows.Media.TextFormatting.TextLineBreak, System.Windows.Media.TextFormatting.TextRunCache) at MS.Internal.TextFormatting.TextFormatterImp.FormatLine(System.Windows.Media.TextFormatting.TextSource, Int32, Double, System.Windows.Media.TextFormatting.TextParagraphProperties, System.Windows.Media.TextFormatting.TextLineBreak, System.Windows.Media.TextFormatting.TextRunCache) at MS.Internal.Text.Line.Format(Int32, Double, System.Windows.Media.TextFormatting.TextParagraphProperties, System.Windows.Media.TextFormatting.TextLineBreak, System.Windows.Media.TextFormatting.TextRunCache, Boolean) at System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Grid.MeasureCell(Int32, Boolean) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32, System.Windows.Size, Boolean, Boolean, Boolean ByRef) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32, System.Windows.Size, Boolean, Boolean) at System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Border.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Control.MeasureOverride(System.Windows.Size) at System.Windows.Controls.ToolBar.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.StackPanel.StackMeasureHelper(System.Windows.Controls.IStackMeasure, System.Windows.Controls.IStackMeasureScrollData, System.Windows.Size) at System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Grid.MeasureCell(Int32, Boolean) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32, System.Windows.Size, Boolean, Boolean, Boolean ByRef) at System.Windows.Controls.Grid.MeasureCellsGroup(Int32, System.Windows.Size, Boolean, Boolean) at System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement, System.Windows.Size) at System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Controls.Border.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Window.MeasureOverrideHelper(System.Windows.Size) at System.Windows.Window.MeasureOverride(System.Windows.Size) at System.Windows.FrameworkElement.MeasureCore(System.Windows.Size) at System.Windows.UIElement.Measure(System.Windows.Size) at System.Windows.Interop.HwndSource.SetLayoutSize() at System.Windows.Interop.HwndSource.set_RootVisualInternal(System.Windows.Media.Visual) at System.Windows.Window.SetRootVisualAndUpdateSTC() at System.Windows.Window.SetupInitialState(Double, Double, Double, Double) at System.Windows.Window.CreateSourceWindow(Boolean) at System.Windows.Window.ShowHelper(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run() at ComponentBrowser.App.Main()

singhashish-wpf commented 2 years ago

@gnanamu Please provide the minimal repro of your application so that we can have a look at it. Also, please provide what is different with respect to the configuration/fonts on the VMs where it doesn't work with respect to the machines where it is working properly.

lindexi commented 2 years ago

@gnanamu The application can visit the Font (always in C:\windows\fonts) folder?

gnanamu commented 2 years ago

IT is happening only when we build the app on the 64bit, happening for both debug and release. if we build the app as 32bit it works fine. Is it possible could be a corrupted font cache, as this is not happening in all the machines.

gnanamu commented 2 years ago

@lindexi Application is not using font from C:\windows\fonts. it uses the Embedded fonts from assembly. @singhashish-wpf we are not doing anything different. same code is working in other machines. also on this same machine 32bit app is loading just fine. This is how we are creating the font family and added it to the application resources.

var fontFam= new FontFamily(new Uri("pack://application:,,,/resources/"), "./#Pericles Light"); Application.Current.Resources.Add("fontFam", fontFam);

When I call FamilyTypefaces property on the FontFamily object also I am getting accessViolationException. Even enumerating all the fonts in the path also giving accessviolation exception. Last week same issue suddenly started happening in one more machine. That is too my development client.

Font related code are designed as per the MSDN guide Packaging Fonts with Applications This code is part of our company propriety UI framework, and it working well in multiple geolocations and multiple products. other than our product no body faced this issue. we are also seeing this issue in only 2 machine right now.

I found font is loading and exception is not thrown only if I install the same fonts to the system, change the path to refer from there. but this will complicate our deployment , beside this is coming from our UI framework team.

Since there is no problem with code, we are really don't have any clue what is going on in these 2 machines,. Any help would be highly appreciated.

lindexi commented 2 years ago

Is it work well with the demo which used the same font from assembly in this machine?

gnanamu commented 2 years ago

Demo application also does not work . only if i install the same font to system, then i need to change the fontfamily to take from system then it works.

lindexi commented 2 years ago

@gnanamu I build the WPF framework with debug mode in https://github.com/dotnet-campus/wpf/actions/runs/1479050890

Could you use it to test?

gnanamu commented 2 years ago

Hi @lindexi I am getting below error when I try to install the package.

Could not install package 'runtime.win-x64.Microsoft.DotNet.Wpf.GitHub.Debug 5.0.13-ci'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

This package will work for application using .net framework?

gnanamu commented 2 years ago

@lindexi I created a sample application on wpf .Net core and run as 64bit. It works fine. Again I create same sample application in WPF .Net Framework and run as 64bit , this is only throwing crashing.