c# - Object stored in Stack has field "erased" -


i have stack<query> query following:

public class query {     private readonly ienumerable<string> _distinguishednames;     private readonly string _searchtext;      private cancellationtokensource _cancellationtokensource;      public query(         querytype querytype,         scope scope = null,         ienumerable<string> distinguishednames = null,         string searchtext = null)     {         querytype = querytype;         scope = scope;         _distinguishednames = distinguishednames;         _searchtext = searchtext;     }      private cancellationtoken cancellationtoken         => _cancellationtokensource.token;      public scope scope { get; }      public ienumerable<expandoobject> data { get; private set; }      public querytype querytype { get; }      public void cancel()     {         _cancellationtokensource?.cancel();     }      public void disposedata()     {         data = null;     }      public async task execute()     {         _cancellationtokensource = new cancellationtokensource();          var task = task.run(() =>         {             data = new searcher(                 querytype,                 scope,                 _distinguishednames,                 cancellationtoken,                 _searchtext).getdata();         },         _cancellationtokensource.token);         await task;     }      public override string tostring()     {         return querytype.tostring();     } } 

the class managing queries contains following relevant portions:

stack<query> queries = new stack<query>();  private async void executerunpreviousquery() {     queries.pop();     await runquery(queries.pop()); }  private async task runquery(     querytype querytype,     scope scope = null,     ienumerable<string> selecteditemdistinguishednames = null,     string searchtext = null) {     await runquery(         new query(             querytype,             scope,             selecteditemdistinguishednames,             searchtext)); }  private async task runquery(query query) {     starttask();     try     {         queries.push(query);         await queries.peek().execute();         data = queries.peek().data.todatatable().asdataview();         contextmenuitems = generatecontextmenuitems();     }     catch (nullreferenceexception e)     {         showmessage(e.message);         resetquery();     }     catch (operationcanceledexception)     {         showmessage("operation cancelled.");         resetquery();     }     catch (argumentnullexception)     {         showmessage(             "no results of desired type found in selected context.");         resetquery();     }     catch (outofmemoryexception)     {         showmessage("the selected query large run.");         resetquery();     }      finishtask(); } 

i can run query fine, if try run previous query method, query has _distinguishednames field set empty, if field had content. not null, somehow empty. searcher class _distinguishednames passed not manipulate it; searcher iterates on it. tried passing copy of _distinguishednames ensure searcher not somehow messing it, , did not change anything.

to clarify, call runquery parameters of querytype , non-empty ienumerable<string>. executes without problem. call runquery again other parameters, , executes again without problem. call executerunpreviousquery , first query fails run because ienumerable<string> supposed stored in _distinguishednames empty.

if want see other code, please let me know. best of knowledge, mcve.


Comments