4

PasswordBox私は、なぜそれが私に多くの問題を引き起こしているのかを理解しようと良い一日を過ごしました。
テストしたすべてのマシンで動作するアプリケーションがあります。これで他のマシンにインストールされ、内部をクリックするたびにクラッシュしますPasswordBox。とコントロール
だけを使用してテストアプリケーションを作成し、アプリケーションの基になるコードがクラッシュの原因であるかどうかを確認しましたが、そうではないことがわかりました。をクリックすると、正常に動作します。その中にテキストを入力できます。しかし、をクリックするとすぐに、アプリケーションがクラッシュします。 TextBoxPasswordBoxTextBoxPasswordBox

未処理の例外をキャッチするために、これらのイベントを設定しました。

  • Application.Current.DispatcherUnhandledException
  • AppDomain.CurrentDomain.UnhandledException
  • AppDomain.CurrentDomain.FirstChanceException

これでMessageBox、エラーが発生した場合にが表示されます。最悪の部分は、これらのイベントにスローされたエラーがないことです。
アプリケーションにいくつかのロギングを設定しましたが、次のような例外が発生しました。

  • オブジェクト参照がオブジェクトのインスタンスに設定されていません
  • 保護されたメモリの読み取りまたは書き込みを試みました。これは多くの場合、他のメモリが破損していることを示しています。

クラッシュする前にフォーカスが取得されたかどうかをテストするためのイベントを設定していたので、オブジェクト参照の例外がコントロールPasswordBoxを参照しているとは思いません。 私はどこでも検索して、他の誰かがこれらの問題を抱えていて、.NET4.0で修正されるはずのコントロールとそのフォーカスの問題 だけを見たことがありますか?PasswordBox
TextBox

おー!そしてそれは私に思い出させます。WPF.NET4.0を使用しています。

どんな助けでも大歓迎です。

テストコードは次のとおりです。

private void Application_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
    Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler((x, y) => { ShowError(x, y); });  

    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((x, y) => { ShowError(x, y); });
    AppDomain.CurrentDomain.FirstChanceException += new EventHandler<System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs>((x, y) => { ShowError(x, y); });
}

private void ShowError(object sender, object o)
{
    Exception ex = null;
    if (o.GetType() == typeof(FirstChanceExceptionEventArgs))
    {
        ex = ((FirstChanceExceptionEventArgs)o).Exception;
    }
    else if (o.GetType() == typeof(DispatcherUnhandledExceptionEventArgs))
    {
        ex = ((DispatcherUnhandledExceptionEventArgs)o).Exception;
    }
    else if (o.GetType() == typeof(UnhandledExceptionEventArgs))
    {
        ex = (Exception)((UnhandledExceptionEventArgs)o).ExceptionObject;
    }
    MessageBox.Show(ex.Message + "\n\r" + ex.StackTrace, "Error at: " + ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
}

そしてXaml:

<Window x:Class="WPF_Control_Test.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="200" Width="300">
    <Grid>
        <StackPanel Orientation="Vertical" HorizontalAlignment="Left">
            <StackPanel Orientation="Horizontal" Width="260">
                <TextBlock Text="TextBox: " TextAlignment="Right" Width="80" Height="Auto" VerticalAlignment="Center" />
                <TextBox Name="textBox" Width="120" VerticalAlignment="Center" />
            </StackPanel>
            <StackPanel Orientation="Horizontal" Width="260">
                <TextBlock Text="PasswordBox: " TextAlignment="Right" Width="80" Height="Auto" VerticalAlignment="Center" />
                <PasswordBox Name="passwordBoxTest" Width="120" VerticalAlignment="Center" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Window>

イベントビューアー

マシンのイベントビューアからの例外は次のとおりです。

アプリケーション:WPF Control Test.exe
フレームワークバージョン:v4.0.30319
説明:アプリケーションは、System.Environment.FailFast(文字列メッセージ)を介してプロセスの終了を要求しました。
メッセージ:回復不能なシステムエラー。
スタック:
System.Environment.FailFast(System.String)
at MS.Internal.Invariant.FailFast(System.String、System.String)
at System.Windows.Media.FontFamily.get_FirstFontFamily()
at System.Windows.Documents.TextSelection
System.Windows.Documents.TextSelection.UpdateCaretStateWorker(System.Object)の.CalculateCaretRectangle(System.Windows.Documents.ITextSelection、System.Windows.Documents.ITextPointer )
System.Windows.Documents.TextSelection.UpdateCaretState(System.Windows.Documents.CaretScrollMethod)
at System.Windows.Documents.TextSelection.EnsureCaret(Boolean、System.Windows.Documents.CaretScrollMethod)
at System.Windows.Documents.TextSelection.System .Windows.Documents.ITextSelection.UpdateCaretAndHighlight()
at System.Windows.Documents.TextEditor.OnGotKeyboardFocus(System.Object、System.Windows.Input.KeyboardFocusChangedEventArgs)
at System.Windows.Controls.PasswordBox.OnGotKeyboardFocus(System.Windows.Input。
System.Windows.UIElement.OnGotKeyboardFocusThunk(System.Object、System.Windows.Input.KeyboardFocusChangedEventArgs)のKeyboardFocusChangedEventArgs)
System.Windows.Input.KeyboardFocusChangedEventArgs.InvokeEventHandler(System.Delegate、System.Object)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate、System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object、System .Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object、System.Windows.RoutedEventArgs、Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject、System.Windows.RoutedEventArgs) atSystem
。 Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs、Boolean)
at System.Windows.Input.InputManager.ProcessStagingArea()
System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
at System.Windows.Input.KeyboardDevice.ChangeFocus(System.Windows.DependencyObject、Int32)
at System.Windows.Input.KeyboardDevice.TryChangeFocus(System .Windows.DependencyObject、System.Windows.Input.IKeyboardInputProvider、Boolean、Boolean、Boolean)
at System.Windows.Input.KeyboardDevice.Focus(System.Windows.DependencyObject、Boolean、Boolean、Boolean)
at System.Windows.Input.KeyboardDevice .Focus(System.Windows.IInputElement)
at System.Windows.UIElement.Focus()
at System.Windows.Documents.TextEditorMouse.MoveFocusToUiScope(System.Windows.Documents.TextEditor)
System.Windows.Documents.TextEditorMouse.OnMouseDown(System.Object、System.Windows.Input.MouseButtonEventArgs)
at System.Windows.Controls.PasswordBox.OnMouseDown(System.Windows.Input.MouseButtonEventArgs)
at System.Windows.UIElement.OnMouseDownThunk (System.Object、System.Windows.Input.MouseButtonEventArgs)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate、System.Object)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate、System.Object)
at System.Windows.EventHandlerInfo.InvokeHandler(System.Object、System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object、System.Windows.RoutedEventArgs、Boolean)
System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject、System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs 、ブール値)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input .InputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr、System.Windows.Input.InputMode、Int32、System.Windows.Input.RawMouseActions、Int32、Int32、Int32)
System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr、MS.Internal.Interop.WindowMessage、IntPtr、IntPtr、Boolean ByRef)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr、Int32、IntPtr、IntPtr、Boolean ByRef)
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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object、System.Delegate、System.Object、Int32、System.Delegate)
System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority、System.TimeSpan、System.Delegate、System.Object、Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr、Int32、IntPtr、IntPtr)
MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
at System.Windows.Threading.Dispatcher.PushFrame(System。 Windows.Threading.DispatcherFrame)
at System.Windows.Application.RunDispatcher(System.Object)
at System.Windows.Application.RunInternal(System.Windows.Window)
at System.Windows.Application.Run(System.Windows.Window)
System.Windows.Application.Run()
のWPF_Control_Test.App.Main()

4

2 に答える 2

3

.NetFrameworkが適切なデフォルトフォントを見つけることができないようです。なぜこれが発生しているのかわかりませんが、次の内部コードFontFamilyの行には、例外がスローされている行が含まれています。

fontFamily = this.FindFirstFontFamilyAndFace(
    ref normal, ref normal2, ref normal3);
if (fontFamily == null)
{
    // NullFontFamilyCanonicalName
    //  = CanonicalFontFamilyReference.Create(null, "#ARIAL");
    fontFamily = FontFamily.LookupFontFamily(
        FontFamily.NullFontFamilyCanonicalName);
    Invariant.Assert(fontFamily != null); // <- Your exception
}

どうやら、フォントを指定しないと、Arialベースのフォントが検索されますが、そのマシンでは見つけることができないため、例外です。

于 2012-01-11T16:24:25.223 に答える
1

Windows Embedded 7ボックスでこれと同じ問題が発生しました。リンクに記載されているように、コメント;

http://social.msdn.microsoft.com/Forums/ar/wpf/thread/fc2c9a54-8f66-4f1a-82be-cb40ada5fba5

次のフォントを「c:\windows\fonts」ディレクトリにコピーするだけで、問題は解決しました。

  • Arial (TrueType)
  • Courier New (TrueType)
  • Times New Roman (TrueType)
于 2014-02-27T11:15:38.793 に答える