How to call a method from another C# library project in Visual Studio?

899 Views Asked by At

When I am trying to call a method of another project class file, I am getting the following error enter image description here

  • I have 2 C# library projects inside same solution file.

  • Inside each project I have a class file.

  • I have added reference of one project inside other.

There are NO compile time or build errors. During runtime, it is throwing the following exception (Image attached above)

My question is, how does one able to call a class method of one project from another method ?

Thanks in advance :)

2

There are 2 best solutions below

1
JJSIMCYBERTECH On

Is your current project class file exist in the actual directory? The physical file might not be on the disk itself so it has this error message.

Simply put if your physical file exist in your directory, and if you wanna call that method in, be sure to put the namespace at the top and import that reference from your solution explorer.

Also, Do remember to include your method class as public.

Example Below:

public class GetUserDetails
{
//methods
}
0
DanielZhang-MSFT On

First check the target framework and verify that the two C# library projects have the same framework.

Did you miss deploying or referencing any assembly (DatabaseUtil.dll) in the old version?

Check to make sure that the referenced assembly exists in your bin folder. If it does exist, check if it is 32-bit or 64-bit.

Go to References in Solution Explorer in Visual Studio. Select the assembly which is getting complained. Set its Copy Local to true in its Properties page. And I suggest you try the suggestions in this thread.

If the above methods are not successful, please provide the relevant code to reproduce the problem.

Daniel Zhang