powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
5 сообщений из 5, страница 1 из 1
WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
    #37452540
RedBird
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Объект TreeView.
При раскрытии пользователем узла дерева появляется ошибка:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
System.Windows.Markup.XamlParseException: Необходимо создать DependencySource в том же потоке, в котором создан DependencyObject. ---> System.ArgumentException: Необходимо создать DependencySource в том же потоке, в котором создан DependencyObject.
   в System.Windows.DependencyObject.ValidateSources(DependencyObject d, DependencySource[] newSources, Expression expr)
   в System.Windows.Expression.ChangeSources(DependencyObject d, DependencyProperty dp, DependencySource[] newSources)
   в System.Windows.Data.BindingExpressionBase.ChangeSources(DependencyObject target, DependencyProperty dp, WeakDependencySource[] newSources)
   в System.Windows.Data.BindingExpressionBase.ChangeSources(WeakDependencySource[] newSources)
   в System.Windows.Data.BindingExpression.ChangeWorkerSources(WeakDependencySource[] newWorkerSources, Int32 n)
   в MS.Internal.Data.ClrBindingWorker.ReplaceDependencySources()
   в MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
   в MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   в MS.Internal.Data.ClrBindingWorker.AttachDataItem()
   в System.Windows.Data.BindingExpression.Activate(Object item)
   в System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
   в System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
   в System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
   в System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
   в System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
   в System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   в System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
   в System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry& entry)
   в System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
   в System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
   в System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
   в System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
   в System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__3(Object sender, XamlObjectEventArgs args)
   в System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
   в System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   в System.Xaml.XamlObjectWriter.WriteEndObject()
   в System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   в System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   --- Конец трассировки внутреннего стека исключений ---
   в System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri)
   в System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   в System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   в System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   в System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   в System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   в System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   в System.Windows.FrameworkElement.ApplyTemplate()
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.Controls.Border.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   в System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   в System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.Controls.Control.MeasureOverride(Size constraint)
   в System.Windows.Controls.TreeViewItem.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.Controls.StackPanel.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   в System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   в System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   в System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   в System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   в System.Windows.UIElement.Measure(Size availableSize)
   в System.Windows.ContextLayoutManager.UpdateLayout()
   в System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   в System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   в System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   в System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   в System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   в System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   в MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Данная ошибка может как возникнуть (воспроизводится в DEBUG версии из-под VS2010), так и не возникнить. К сожалению Stack вызовов не содержит ссылок на исходный код проекта и возникает исключительно в системных классах.
Не очень понятно куда копать...
...
Рейтинг: 0 / 0
WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
    #37452811
SeVa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Добавление данных в списки возможно только в UI Thread.
...
Рейтинг: 0 / 0
WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
    #37452910
RedBird
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
SeVa,

Это понятно из текста сообщения об ошибке.
Проблема в том, что в стеке вызовов нет ни одной строки моего кода и воспроизводится через раз...

Сама коллекция заполняется ВСЕГДА из одного потока:
Код: plaintext
1.
2.
3.
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate()
{
.............................................
});
...
Рейтинг: 0 / 0
WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
    #37455733
Фотография Алексей К
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Видимо сказываются особенности работы внутренностей WPF. Видимо в нём внутри происходит многопоточность. Нужен пример, воспроизводящий проблему.
...
Рейтинг: 0 / 0
WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
    #37456407
RedBird
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Алексей К,

В том то и беда, что происходит через раз... и в стеке вызовов (см. выше) есть только системные вызовы.

Обособить код не удалось, т.к. в тестовом проекте все работает... Попытка закомментировать подозрительные строки разметки и/или кода ни к чему не привели - когда строки закомментировали - все разработало... а потом опять упало. Строки вернули - проблема так и не воспроизвелась... Все очевидные причины я вроде уже исключил (?)...

Мне нужна методика поиска ошибки, т.к. причина ее возникновения очень далеко (как по коду, так и по времени) отстоит от момента ее возникновения...
...
Рейтинг: 0 / 0
5 сообщений из 5, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / WPF 4.0: Необходимо создать DependencySource в том же потоке, в котором создан...
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]