[英]How to call a method from another C# library project in Visual Studio?
When I am trying to call a method of another project class file, I am getting the following error当我尝试调用另一个项目 class 文件的方法时,出现以下错误
I have 2 C# library projects inside same solution file.我在同一个解决方案文件中有 2 个 C# 库项目。
Inside each project I have a class file.在每个项目中,我都有一个 class 文件。
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?我的问题是,如何从另一个方法调用一个项目的 class 方法?
Thanks in advance:)提前致谢:)
Is your current project class file exist in the actual directory?您当前的项目 class 文件是否存在于实际目录中? 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.另外,请记住将您的方法 class 列为公开。
Example Below:下面的例子:
public class GetUserDetails
{
//methods
}
First check the target framework and verify that the two C# library projects have the same framework.首先查看目标框架,验证C#这两个库工程是否有相同的框架。
Did you miss deploying or referencing any assembly (DatabaseUtil.dll) in the old version?您是否错过了在旧版本中部署或引用任何程序集 (DatabaseUtil.dll)?
Check to make sure that the referenced assembly exists in your bin folder.检查以确保引用的程序集存在于您的 bin 文件夹中。 If it does exist, check if it is 32-bit or 64-bit.
如果确实存在,请检查它是 32 位还是 64 位。
Go to References in Solution Explorer in Visual Studio. Go 到 Visual Studio 中解决方案资源管理器中的引用。 Select the assembly which is getting complained.
Select 收到投诉的程序集。 Set its Copy Local to true in its Properties page.
在其属性页面中将其 Copy Local 设置为 true。 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张勇
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.