简体   繁体   中英

vb.net calling a c# method is giving errors

I am trying to access c# method from a vb.net project.

The c# project has the following code:

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
}

The vb.net project has this:

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

When running the code I get the following error

System.IO.FileNotFoundException: 'Could not load file or assembly 'MeFWCFClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified

A Mef dll is referenced!

As soon as I comment the three lines above, it works like a charm.

I believe you need to go to Project Properties, References and check whether you have there a correct reference for referenced MeFWCFClient (a dll). You can add it within this dialogue, you might be able to use Nuget, or simply copy it to binary folder.

It looks like the method you are calling is static. Have you tried this in vb.net?

AimEFileCore.LoginClass.CreateServiceContext()

you are instantiating LoginClass but there are no public methods defined - at least not in the code you are showing, so I've assumed it contains this:

public static void CreateServiceContext()
{
 ...
}

as that's what the C# code would suggest.

using MeF.Client;

Thats the culprit. Reference that DLL in your project.

在此处输入图片说明

Then on top add:

Imports MeF.Client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM