C#DLL创建中的指令和程序集缺失错误 [英] The Directive and Assembly Missing Error in C# DLL creation
问题描述
你好,
我正在创建一个用C#创建的小项目。我通过使用DLL文件获得DLL文件,我必须调用函数和方法并将该项目作为新的DLL。我这样做但问题是C#代码转换为net模块它显示两个错误。我不清楚,请帮助我。
代码:
public int Add( int a,int b)
{
返回a + b;
}
错误:
Basic.cs(7,7):错误CS0246:类型或命名空间名称'添加'可以不是找到
(*你错过了使用指令或汇编参考吗?*)
Basic.cs(22,9) :错误CS0246:类型或命名空间名称'添加'无法找到
(您是否缺少使用指令或程序集引用?)
尝试的方法:
1.我将通过Project->添加参考。添加引用。
2.使用引用也使用。
Hello,
I am Creating a small project which is created in C#. I am having a DLL file by the use of DLL file, I have to call the functions and methods and Make that project as a new DLL. I done this But the problem is The C# code is converted to net module it shows two errors. I am not clear about that kindly help me over it.
Code:
public int Add(int a, int b)
{
return a + b;
}
Errors:
Basic.cs(7,7): error CS0246: The type or namespace name 'Add' could not be
found (*are you missing a using directive or an assembly reference?*)
Basic.cs(22,9): error CS0246: The type or namespace name 'Add' could not
be found (are you missing a using directive or an assembly reference?)
Tried Methods:
1. I will add the reference via Project-> Add Reference.
2. The using Reference also used.
推荐答案
以不同方式启动:使用VS在解决方案中添加一个新项目,并告诉它创建一个类库。然后它将创建一个带有默认class1的项目,您可以修改该项目以满足您的需求,因为它将包含有效的基本文件框架。当你构建它时,它将为你生成一个.NET DLL程序集,应该可以正常工作。
然后你可以添加对该项目的引用(或者生成的DLL )到你的otehr项目并直接通过他们的全名访问方法:MyAssemblyNamespace.MyClass.Add或通过在代码中添加适当的使用
语句:
Start differently: Use VS to add a new project to your solution, and tell it to create a class library. It will then create a project with a default "class1" which you can modify to fit your needs as it will contain a valid basic file framework. When you build it, it will produce a .NET DLL assembly for you that should work fine.
You can then add a reference to that project (or the built DLL) to your otehr project and access the methods either directly via their full name: MyAssemblyNamespace.MyClass.Add or by adding the appropriateusing
statement to your code:
using MyAssemblyNamespace;
...
MyClass mc = new MyClass();
mc.Add(...);
这篇关于C#DLL创建中的指令和程序集缺失错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!