WPF MVVM:从视图模型构造函数调用Web服务抛出' System.IO.FileNotFoundException'例外

时间:2018-01-16 16:21:01

标签: c# wpf web-services mvvm .net-3.5

在我的视图模型构造函数中,我使用BackgroundWorker模式创建一个后台工作器,然后通过刚刚创建的后台工作程序中的Web服务对数据库(Informix)执行查询:

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
}

我的MyDataHelper如下:

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
    }
}

调试应用程序时,在输出窗口中,我可以看到,尽管正确执行了应用程序并正确执行了数据库查询,但仍会引发异常。

抛出异常:

  

类型&#39; System.IO.FileNotFoundException&#39;的未处理异常   发生在mscorlib.dll

在Visual Studio ide自动生成的Reference.cs文件中的构造函数中抛出此异常:

    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说:

  

无法加载文件或程序集   &#39; CompanyManagement.XmlSerializers,Version = 1.6.0.3,Culture = neutral,   公钥=空&#39;或其中一个依赖项。系统找不到指定的文件。&#34;:&#34; CompanyManagement.XmlSerializers,   Version = 1.6.0.3,Culture = neutral,PublicKeyToken = null

堆栈跟踪:

  

在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,   证据集合安全,StackCrawlMark&amp; stackMark,布尔   forIntrospection)

0 个答案:

没有答案