Frage

Ich habe einen guten Tag damit verbracht, herauszufinden, warum die PasswordBox verursacht mir so viele Probleme.
Ich habe eine Anwendung, die auf jeder Maschine funktioniert, auf der ich sie getestet habe. Jetzt wurde es auf anderen Maschinen installiert, es stürzt ab, wenn ich in das klicke PasswordBox.
Ich habe sogar eine Testanwendung mit nur einem gemacht TextBox und PasswordBox Kontrolle, um festzustellen, ob der Absturz in meiner Bewerbung durch einen zugrunde liegenden Code verursacht wurde, es stellte sich jedoch heraus, dass dies nicht der Fall war. Ich klicke auf die TextBox, und es funktioniert gut. Ermöglicht mir, Text in ihn einzugeben. Aber sobald ich auf die klicke PasswordBox, Anwendungsabstürze.

Ich habe diese Ereignisse eingerichtet, um unberührte Ausnahmen zu fangen:

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

Das sollte mir jetzt eine zeigen MessageBox Wenn Fehler auftreten. Das Schlimmste ist, dass diese Ereignisse keine Fehler gibt.
Ich habe eine Protokollierung in meiner Anwendung eingerichtet und habe Ausnahmen wie:

  • Die Objektreferenz wird nicht auf eine Instanz eines Objekts festgelegt
  • Versucht, geschützte Speicher zu lesen oder zu schreiben. Dies ist oft ein Hinweis darauf, dass ein anderer Gedächtnis korrupt ist.

Ich hatte eine Veranstaltung für die eingerichtet PasswordBox Um zu testen, ob es Fokus erhielt, bevor es abstürzte und es tat, denke ich nicht, dass sich die Ausnahme von Objektreferenz auf die bezieht PasswordBox Kontrolle.
Ich habe überall gesucht, um herauszufinden, ob jemand anderes diese Probleme hatte und nur Probleme mit dem gesehen habe TextBox Kontrolle und seine Fokussprobleme, die in .NET 4.0 behoben werden sollen

Oh! Und das erinnert mich. Ich verwende WPF .NET 4.0.

Jede Hilfe wäre sehr geschätzt.

Der Testcode ist:

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);
}

Und das 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>

Event -Viewer

Hier ist die Ausnahme des Event -Viewers auf der Maschine:

Anwendung: WPF -Steuerungstest.exe
Rahmenversion: v4.0.30319
Beschreibung: Die Anwendung beantragte Prozessbeendigung über System.Environment.Failfast (String -Nachricht).
Meldung: Unbeschwerter Systemfehler.
Stapel:
bei System.Environment.Failfast (System.String)
bei ms.internal.invariant.failfast (System.String, System.String)
at system.windows.media.fontfamily.get_firstfontfamily ()
at system.windows.documents.textSelection.calculateCaretrectangle (System.Windows.Documents.itextSelection, System.Windows.Documents.itextPointer))
at system.windows.documents.textSelection.updateCaretStateWorker (System.Object)
at system.windows.documents.textselction.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.KeyboardfocuschangEdEventArgs)
at system.windows.uielement.ongotKeyboardfocUsthunk (System.Object, System.windows.input.KeyboardfocuschangEdEventArgs)
at system.windows.input.KeyboardfocuschangEdEventargs.invokeEventHandler (System.Delegate, System.Object)
at system.windows.routedEventargs.invokeHandler (System.Delegate, System.Object)
at system.windows.routtedeventHandlerInfo.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)
at system.windows.uielement.raisetrustedEvent (System.Windows.routedEventArgs)
at system.windows.uielement.raiseEvent (System.Windows.routedEventArgs, Boolean)
at system.windows.input.inputManager.processstagingArea ()
at 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, Boolesche, Boolesche)
at system.windows.input.KeyboardDevice.focus (System.Windows.IinputElement)
at system.windows.uielement.focus ()
at system.windows.documents.texteditorme.movefocustouiscope (System.Windows.Documents.Texteditor)
at system.windows.documents.texteditorme.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.routtedeventHandlerInfo.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)
at system.windows.uielement.raisetrustedEvent (System.Windows.routedEventArgs)
at system.windows.uielement.raiseEvent (System.Windows.routedEventArgs, Boolean)
at system.windows.input.inputManager.processstagingArea ()
at system.windows.input.inputManager.processinput (System.windows.input.inputEventArgs)
at system.windows.input.inputprovidersit.reportInput (System.windows.input.inputReport)
at system.windows.interop.hwndMouseInputProvider.ReportInput (intptr, System.windows.input.inputMode, Int32, System.windows.input.RawmoUSactions, Int32, Int32, Int32)
at 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)
unter ms.win32.hwndwrapper.wndproc (intptr, int32, intptr, intptr, boolean byRef)
bei ms.win32.hwndsubClass.DispatcherCallbackoperation (System.Object)
at system.windows.threading.exceptionwrapper.internalrealcall (System.delegate, System.Object, Int32)
bei Frauinternal.Threading.ExceptionFilterHelper.tryCatchwhen (System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at system.windows.threading.dispatcher.invokeImpl (System.Windows.Threading.DispatcherPriority, System.timespan, System.delegate, System.Object, Int32)
bei ms.win32.hwndsubClass.subClasswndProc (INTPTR, INT32, INTPTR, INTPTR)
unter 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)
bei System.Windows.Application.run ()
bei WPF_Control_test.app.main ())

War es hilfreich?

Lösung

Es scheint, dass das .NET -Framework keine geeignete Standardschrift für die Standardschrift finden kann. Ich weiß nicht, warum das passiert, aber die folgenden Zeilen von intern Code von FontFamily Geben Sie die Linie ein, in der die Ausnahme ausgelöst wird:

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
}

Wenn Sie keine Schriftart angeben, wird sie nach einer auf Arial basierenden Schriftart suchen, die sie auf dieser Maschine nicht finden kann, daher Ihre Ausnahme.

Andere Tipps

Ich hatte das gleiche Problem in einem Fenster eingebetteten 7 -Box und wie im Link erwähnt die Kommentare;

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

Ich habe einfach die folgenden Schriftarten in das Verzeichnis "C: Windows Schriften" kopiert, und das Problem wurde gelöst.

  • Arial (TrueType)
  • Kurier neu (TrueType)
  • Times New Roman (TrueType)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top