I have a Silverlight 4 application that access a couple of WCF Data Services.
There are no problems accessing the service through the browser.
I set the program to run out-of-browser with elevated trust. Then I can see the calls to the WCF Service via fiddler, but nothing ever comes back.
If I debug then I get the following error:
$exception {System.UnauthorizedAccessException: Invalid cross-thread access.
at MS.Internal.XcpImports.CheckThread()
at System.Windows.Controls.ItemCollection.GetValueInternal(DependencyProperty dp)
at System.Windows.PresentationFrameworkCollection`1.get_CountImpl()
at System.Windows.PresentationFrameworkCollection`1.get_Count()
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.RemoveAll()
at System.Windows.Controls.ItemContainerGenerator.RemoveAll()
at System.Windows.Controls.ItemContainerGenerator.OnRefresh()
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.ItemCollection.NotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.ItemCollection.System.Windows.Controls.ICollectionChangedListener.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Controls.WeakCollectionChangedListener.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
at System.Collections.ObjectModel.Collection`1.Clear()
at ClientFolderExplorer.ViewModels.DocumentExplorerViewModel.clientCatalog_ClientsLoadingComplete(Object sender, ClientLoadingEventArgs e)
at ClientFolderExplorer.Catalogs.ClientCatalog.<>c__DisplayClass3.<ExecuteClientQuery>b__2(IAsyncResult a)} System.Exception {System.UnauthorizedAccessException}
Not sure where to start troubleshooting. I have crossdomain.xml and clientaccesspolicy.xml files in place in the root of the webserver, but I cannot even see these files being requested (in fiddler).
Any Ideas?
Yes – you suppose the problem is related to cross-site access, while in reality it’s related to cross-thread access (first line of error indicates this clearly).
I’m assuming you’re trying to set some UI element’s data bound (or not, doesn’t matter) property directly from the callback handling the service call. (edit) Forgot to clarify – where the callback is running on a thread different from the UI thread. Silverlight like most other frameworks disallows modifying UI except from the UI thread.
If so, take a look at how to use
Dispatcherin order to switch back to the UI thread.