0

Within my view model constructor, I create a background worker using BackgroundWorker pattern and then I perform a query against a database (Informix) through a webservice in the background worker just created:

public wMainViewModel(IView view)
{                
    BackgroundWorker BWorkerInit = new BackgroundWorker();
    BWorkerInit.WorkerReportsProgress = false;
    BWorkerInit.WorkerSupportsCancellation = true;

    BWorkerInit.DoWork += new DoWorkEventHandler(BWorkerInit_DoWork);
    BWorkerInit.ProgressChanged += new ProgressChangedEventHandler(BWorkerInit_ProcessChanged);
    BWorkerInit.RunWorkerCompleted += new RunWorkerCompletedEventHandler(BWorkerInit_RunWorkerCompleted);

    BWorkerInit.RunWorkerAsync();
}

private void BWorkerInicialitzar_DoWork(object sender, DoWorkEventArgs e)
{
     List<Dept> ListDepts;
     int res = MyDataHelper.GetDepts(out ListDepts);
     // Continue doing other stuff
}

My MyDataHelper is as follows:

public static class MyDataHelper
{

#if DEBUG
    private static MyWebservice_Local_Testing.WSCore ws = new MyWebservice_Local_Testing.WSCore();  // <----- HERE IT CRASHES
#else
    private static MyWebservice.WSCore ws = new MyWebservice.WSCore();
#endif

    public static int GetDepts(out List<Dept> oListDepts)
    {
          System.Data.DataSet ds = ws.GetDepts();

          // Continue doing other stuff
    }
}

When debugging application, in the output window, I can see that an exception is thrown despite application is being executed correctly and performing the database query correctly.

Exception thrown:

an unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

This exception is thrown in the constructor within Reference.cs file auto-generated automatically by visual studio ide:

    public WSCore() {
        this.Url = global::My.Apps.WPF.CompanyManagement.Properties.Settings.Default.CompanyManagement_MyWebservice_Local_Testing_WSCore;
        if ((this.IsLocalFileSystemWebService(this.Url) == true)) {
            this.UseDefaultCredentials = true;
            this.useDefaultCredentialsSetExplicitly = false;
        }
        else {
            this.useDefaultCredentialsSetExplicitly = true;
        }
    }

InnerException says:

could not load file or assembly 'CompanyManagement.XmlSerializers, Version=1.6.0.3, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"CompanyManagement.XmlSerializers, Version=1.6.0.3, Culture=neutral, PublicKeyToken=null

StackTrace:

at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)

Willy
  • 9,848
  • 22
  • 141
  • 284
  • I believe You can avoid it by tick in JustMyCode. https://stackoverflow.com/a/1177040/1859959. If not, than there is more into it. – ntohl Jan 16 '18 at 16:25
  • 1
    Just an FYI: as a matter of good practice, you should avoid calling into a web service in a view model constructor. Wait until the view is first loaded. If, for some reason, your view does not load cleanly, your effort will be wasted, and the results will not be observed anyway. – Mike Strobel Jan 16 '18 at 17:42
  • @ntohl thanks for the link. – Willy Jan 17 '18 at 08:10

0 Answers0