2012-04-27 76 views
0

就像很多這個話題一樣,我遇到了一個問題,這個異常發生在一個特定的地方(5%的時間)和其他地方。試圖讀取或寫入受保護的內存。這通常表明其他內存已經損壞

的第一行代碼是這個

((DefinitionDetailForm.FindNameInContent("DataFieldDefinitionPoints") as DataField). 
         FindName("DefinitionScoringPoints") as RadNumericUpDown). 
         Minimum = 0; 

首先,我想,我也許需要保持在一個領域的基準,但這沒有幫助。

另一種情況是在不確定的地方,我甚至不得到調用堆棧東西讓我不能給任何更多的信息:(

任何人都至少具有關於第一個想法?

編輯:

當事情打破

 
[Managed to Native Transition] 
System.Windows.dll!MS.Internal.XcpImports.SetValue(MS.Internal.IManagedPeerBase obj, System.Windows.DependencyProperty property, string s) + 0x6f bytes 
System.Windows.dll!MS.Internal.XcpImports.SetValue(MS.Internal.IManagedPeerBase doh, System.Windows.DependencyProperty property, object obj) + 0x2ce bytes 
System.Windows.dll!System.Windows.DependencyObject.SetObjectValueToCore(System.Windows.DependencyProperty dp, object value) + 0xd6 bytes  
System.Windows.dll!System.Windows.DependencyObject.SetEffectiveValue(System.Windows.DependencyProperty property, ref System.Windows.EffectiveValueEntry newEntry, object newValue) + 0x35 bytes 
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) + 0xe6 bytes  
System.Windows.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp, object value, bool allowReadOnlySet, bool isBindingInStyleSetter) + 0x248 bytes 
System.Windows.dll!System.Windows.Controls.TextBox.Text.set(string value) + 0x33 bytes 
Telerik.Windows.Controls.Input!Telerik.Windows.Controls.RadNumericUpDown.UpdateText() + 0xa5 bytes 
Telerik.Windows.Controls.Input!Telerik.Windows.Controls.RadNumericUpDown.OnValueChanged(Telerik.Windows.Controls.RadRangeBaseValueChangedEventArgs e) + 0x1f5 bytes 
Telerik.Windows.Controls!Telerik.Windows.Controls.RadRangeBase.OnValueChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x105 bytes 
Telerik.Windows.Controls!Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) + 0x58b bytes  
System.Windows.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications(System.Windows.DependencyProperty dp, object oldValue, object newValue) + 0x53 bytes  
System.Windows.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) + 0xf3 bytes  
System.Windows.dll!System.Windows.DependencyObject.RefreshExpression(System.Windows.DependencyProperty dp) + 0x47 bytes 
System.Windows.dll!System.Windows.Data.BindingExpression.SendDataToTarget() + 0xff bytes  
System.Windows.dll!System.Windows.Data.BindingExpression.SourceAcquired() + 0x5f bytes 
System.Windows.dll!System.Windows.Data.Binding.EnsureBreakPoint(System.Windows.Data.Debugging.BindingDebugState debugState, System.Action callback, bool canDelay) + 0x47 bytes 
System.Windows.dll!System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) + 0xa4 bytes 
System.Windows.dll!System.Windows.Data.BindingExpression.DataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) + 0xc bytes  
System.Windows.dll!System.Windows.FrameworkElement.OnDataContextChanged(System.Windows.DataContextChangedEventArgs e) + 0x1e bytes 
System.Windows.dll!System.Windows.FrameworkElement.OnAncestorDataContextChanged(System.Windows.DataContextChangedEventArgs e) + 0x26 bytes 
System.Windows.dll!System.Windows.FrameworkElement.NotifyDataContextChanged(System.Windows.DataContextChangedEventArgs e) + 0xcb bytes 
System.Windows.dll!System.Windows.FrameworkElement.OnTreeParentUpdated(System.Windows.DependencyObject newParent, bool bIsNewParentAlive) + 0x3d bytes 
System.Windows.dll!System.Windows.DependencyObject.UpdateTreeParent(MS.Internal.IManagedPeer oldParent, MS.Internal.IManagedPeer newParent, bool bIsNewParentAlive, bool keepReferenceToParent) + 0x4a bytes  
System.Windows.dll!MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(System.IntPtr oldParentElement, System.IntPtr parentElement, System.IntPtr childElement, byte bIsParentAlive, byte bKeepReferenceToParent, bool canCreateParent) + 0xf8 bytes 
[Managed to Native Transition] 
System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0x9e bytes 
[Managed to Native Transition] 
System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0x9e bytes 
[Appdomain Transition] 

回答

1

該異常表明有東西損壞了非託管內存。腐敗往往發生在拋出異常之前的某個時刻,這使得難以解決問題。 Spinner可能根本不參與,只是您的應用程序中一個更險惡的問題的使者。

坦率地說,我只能想到一種方法來破壞Silverlight中的非託管內存,也就是在Silverlight 5中使用P/Invoke。如果你這樣做,你應該仔細看看你的代碼部分。

問題中的演員絕不會造成傷害。在最壞的情況下,丟失或錯誤的控件可能觸發NullReferenceException,但不會破壞非託管內存。


如果你想提高鑄件(這不會解決你的問題),你可以使用一個擴展方法做一些驗證,並告訴你,如果有一個問題:

static class FrameworkElementExtensions { 

    public T FindName<T>(this FrameworkElement parent, String name) { 
    var child = parent.FindName(name); 
    if (child == null) 
     throw new ArgumentException(
     String.Format("No element named '{0}' exists.", name); 
    var typedChild = child as T; 
    if (typedChild == null) 
     throw new ArgumentException(
     String.Format("Named element '{0}' has wrong type.", name); 
    return typedChild; 
    } 

} 

然後你可以這樣使用它:

dataField.FindName<RadNumericUpDown>("DefinitionScoringPoints").Minimum = 0; 

您必須實現對Telerik的特定調用類似的擴展方法。

0

那麼首先第一件事情,這是一個很多類型轉換爲共同的單行調用堆棧德。在代碼中投入的每一種類型意味着你比代碼所知更多,這是不好的。而且還有一種可能性,即查找方法可能會返回null

如果您要設置窗體的數值微調器的最小值,我建議您在窗體內部執行此操作 - 沿線的。

DefinitionDetailForm.SetNumericSpinnerMinValue(0); 

而且SetNumericSpinnerMinValue可能對正確的情況下空檢查微調設置最小值的邏輯。

在懷疑異常的代碼周圍使用try/catch塊。

再次 - 擺脫這些演員!

+0

感謝你們......我會試試看......關於演員陣容,我們得到了這段代碼,因爲它來自最後一支編寫它的團隊,而且有數以百萬計的演員陣容遍佈整個地方。我們的目標是在我們將這個錯誤從系統中移除後將所有內容都轉換爲HTML 5 ......再次感謝 – 2012-04-27 08:10:33

相關問題