There is such a client code:
private void btChangeState_Click(object sender, RoutedEventArgs e) { if (!IsConnected) { Exception error = null; if (!TryConnect($"net.tcp://{tbIP.Text}:{tbPort.Text}/JobService", out Proxy, out error)) { MessageBox.Show(error.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); return; } } else { Proxy.Close(); } IsConnected = !IsConnected; Jobs.Clear(); } private bool TryConnect(string endpoint, out JobServiceClient proxy, out Exception error) { try { var callback = new ClientCallback(); callback.GiveJob += Callback_GiveJobAsync; var ctx = new InstanceContext(callback); proxy = new JobServiceClient(ctx); proxy.Endpoint.Address = new EndpointAddress(endpoint); proxy.Connect(); error = null; return true; } catch (Exception e) { proxy = null; error = e; return false; } } Why does this error fall when I call Connect? "This type of CollectionView does not support changes to its SourceCollection from a stream other than the Dispatcher stream." No additional streams are used in this case, everything is basically.
Now, it’s not the client on which the error pops up to debug, but the server, where the Connect function via the proxy is actually called. Campaign error is there. But why she pops up, I still do not understand ... In the service contract there is a collection of public ObservableCollection<ClientView> Clients { get; } = new ObservableCollection<ClientView>(); public ObservableCollection<ClientView> Clients { get; } = new ObservableCollection<ClientView>(); . In the Connect function, a ClientView object is created and added to it. And it is with this addition (according to the debugger) that the error falls, which is simply transmitted to the client. But everything happens in one thread, there are no extra threads there! Where does the mistake come from?