2012-04-27 6 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

예외는 관리되지 않는 메모리가 손상된 것을 나타냅니다. 예외가 발생하기 전에 종종 손상이 발생하여 문제를 해결하기가 어려워집니다. 회 전자는 전혀 관련이 없지만 응용 프로그램에서 단순히 더 불길한 문제의 메신저 일 수 있습니다.

솔직히 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

그럼 먼저 물건을 나누기 캐스트의 많은 공동의 단일 라인의

콜 스택 드. 코드에있는 모든 타입 캐스트는 코드가하는 것보다 훨씬 많은 것을 알고 있다는 것을 의미합니다. 또한 Find 메서드가 반환 할 가능성이 있습니다. null

양식의 숫자 회 전자에 대한 최소값을 설정하려는 경우 양식 내에서 수행하도록 제안합니다. 의.

DefinitionDetailForm.SetNumericSpinnerMinValue(0); 

그리고 SetNumericSpinnerMinValue 적절한 널 검사와 회 전자에 대한 최소 값을 설정하기위한 로직을 가질 수있다.

예외가 의심되는 코드 주위에 try/catch 블록을 사용하십시오.

다시 - 해당 캐스트를 제거하십시오!

+0

감사합니다 ... 나는 그것을 시험해 볼 것입니다 ... 캐스트에 관해서는,이 코드를 마지막으로 작성한 팀에서 얻었으므로이 코드는 수백만 개가 넘습니다. 우리의 목표는 시스템에서이 버그를 얻은 후에 모든 것을 HTML 5로 변환하는 것입니다. 다시 한번 감사드립니다. –