vb.net 调用 ac# 方法出现错误

我正在尝试从 vb.net 项目访问 c# 方法。


c#项目有以下代码:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using MeF.Client;


public class LoginClass

{

    // lines of code that are giving errors  (when commented there’s no error)

    private ServiceContext context = new ServiceContext();

    public string etin;

    public string appSysId;


    static void Main(string[] args)   

    { 

        LoginClass.CreateServiceContext();

    }


    //bla, bla, bla

}

vb.net 项目有这个:


Imports AimEFileCore


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


        Dim Process As New AimEFileCore.LoginClass

        Process.CreateServiceContext()

    End Sub

运行代码时出现以下错误


System.IO.FileNotFoundException:“无法加载文件或程序集“MeFWCFClient,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。该系统找不到指定的文件


引用了 Mef dll!


当我评论上面三行时,它就像一个魅力。


弑天下
浏览 160回答 3
3回答

哈士奇WWW

看起来您调用的方法是静态的。你在vb.net中试过这个吗?AimEFileCore.LoginClass.CreateServiceContext()您正在实例化 LoginClass 但没有定义公共方法 - 至少在您显示的代码中没有定义,所以我假设它包含以下内容:public static void CreateServiceContext(){  ... }因为这就是 C# 代码的建议。

达令说

using MeF.Client;这就是罪魁祸首。在您的项目中引用该 DLL。然后在上面添加:Imports MeF.Client

慕的地6264312

我相信您需要转到“项目属性”,References并检查是否有引用的 MeFWCFClient(dll)的正确引用。您可以将其添加到此对话框中,您也许可以使用 Nuget,或者只需将其复制到二进制文件夹。
打开App,查看更多内容
随时随地看视频慕课网APP