创建类库
我正在使用 Visual Studio 2010 并尝试创建一个类库,然后在应用程序中使用该类库,该应用程序将使用 TaskFactory 创建任务并执行新创建的类库中的类函数。但是我在应用程序中收到实例未定义错误。
类库:
程序集名称:GPStream
根命名空间:TFStream
具有不同类的项目: GPStream:
gStream.vb,
解析器T.vb,
insertDB.vb
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.ComponentModel
Imports System.Net.Mail
Imports System.Threading
Imports System.Threading.Tasks
Public Class gStream
Private Shared settings As New System.Configuration.AppSettingsReader
' application configuration variables'
Public Sub New()
getConfigurations()
End Sub
...
End Class
Imports System.IO
Imports System.Web
Imports TFStream
Imports System.Configuration
Imports System.Threading
Imports System.Threading.Tasks
Public Class Form1
Private gp1 As TFStream.GPStream.gStream = New TFStream.GPStream.gStream()
...
End Class
我确实将其添加为参考。
类库:程序集名称GPStream,根命名空间GPStream 项目名称GPStream,主类gStream
I am using visual studio 2010 and tried to create a class library which I then use in an application that will create tasks using the TaskFactory and execute the class functions from the newly created class library. However I get the instance not defined errors in the application.
CLASS LIBRARY:
Assembly Name: GPStream
Root namespace: TFStream
Project with different classes:
GPStream:
gStream.vb,
parserT.vb,
insertDB.vb
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.ComponentModel
Imports System.Net.Mail
Imports System.Threading
Imports System.Threading.Tasks
Public Class gStream
Private Shared settings As New System.Configuration.AppSettingsReader
' application configuration variables'
Public Sub New()
getConfigurations()
End Sub
...
End Class
Imports System.IO
Imports System.Web
Imports TFStream
Imports System.Configuration
Imports System.Threading
Imports System.Threading.Tasks
Public Class Form1
Private gp1 As TFStream.GPStream.gStream = New TFStream.GPStream.gStream()
...
End Class
I Do have it added as a reference.
Class library: Assembly name GPStream, Root Namespace GPStream
Project name GPStream, Main Class gStream
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我将提供一个可能更简单的示例,我希望它能帮助您实现目标。
假设我们有一个业务实体项目,我们希望在 WinForm 项目中使用它。然后我们有两个项目,为了简单起见,在同一个解决方案中。
我的 WinFormApp 项目的命名空间是:
MyCompany.MyProject.WinFormApp
并且:
MyCompany.MyProject.BusinessEntities
用于类库。让我们从包含以下两个类的类库开始:在会计中,这两者从不同的角度使用,即针对客户的
应收账款
和针对供应商的应付账款
。可以分配适当的命名空间来反映这一现实。Customer 类应如下所示:
然后,Supplier 类:
还有 CreditTerms 枚举,此处可以将其分配给我们购买的供应商和我们销售的客户。从这个角度来看,此类可能位于项目的根目录中以说明其常见用途。
然后,我们的 WinFormApp 项目应类似于以下内容:
请注意,我已明确导入
MyCompany.MyProject.BusinessEntities
和MyCompany.MyProject.BusinessEntities.AccountReceivable
以说明差异CreditTerm
枚举和Customer
类之间的命名空间。因此,我没有导入Supplier
类的命名空间,这迫使我指向查找该类的位置。最后,我可以使用
MyCompany.MyProject.BusinessEntities.Customer
命名空间将与客户相关的所有内容分组到同一命名空间下,同时将 Customer 类放在 Customer 命名空间内。但是,即使在导入名称空间时,您也必须编写以下内容:编写时想到了另一件事。尝试构建/生成/重新生成类库,然后将其添加为引用。也许您引用类库的项目无法找到二进制文件,除非您确实通过项目引用引用了它。
请随时提出任何有关被误解的细节的问题,甚至可以说我自己可能误解了您的问题和担忧。
我真的希望这有帮助!
Okay, I'll have it with a perhaps simpler sample which, I hope, will help you achieve your goal.
Take it we have a business entities project which we want to use within our WinForm project. We then have two projects, say within the same solution for simplicity sake.
The namespace of my WinFormApp project is:
MyCompany.MyProject.WinFormApp
And:
MyCompany.MyProject.BusinessEntities
for the class library. Let's begin with the class library which contains the two following classes:In accounting, these two are used from a different point of views which are
Account Receivable
for the Customer andAccount Payable
for the Supplier. Proper Namespace could be assigned to reflect this reality.The Customer class shall look like this:
Then, the Supplier class:
And the CreditTerms enumeration which here can be assigned to both a Supplier from which we buy, and a Customer to which we sell. Under that perspective, this class could either be at the root of your project to illsutrate its common use.
Then, our WinFormApp project should look something similar to:
Notice here that I have expressly imported the
MyCompany.MyProject.BusinessEntities
andMyCompany.MyProject.BusinessEntities.AccountReceivable
to illsutrate the differences of namespace between theCreditTerm
enumeration and theCustomer
class. Therefore, I have not imported the theSupplier
class' namespace, which obliges me to point to the location where to find the class.In the end, I could have had
MyCompany.MyProject.BusinessEntities.Customer
namespace to group everything that regards a customer under the same namespace while having the Customer class inside the Customer namespace. But then, even when importing the namespace, you would have to write the following:Another thing comes to mind while writing. Try to build/generate/regenerate the class library, then add it as a reference. Perhaps your project where the class library is referenced can't find the binaries, except if you did reference it through a Project Reference.
Please feel free to ask any question about misunderstood details or so, or even to say I myself have perhaps misunderstood your question and concerns.
I really DO hope this helps!
最后一个
Imports
语句有效吗?如果是这样,则表明 GPStream.gstream 是一个命名空间,而不是一个类。您的类可能具有不同的名称或嵌套在该名称空间内(您尝试过 GPStream.gstream.gstream 吗?)。Does the last
Imports
statement work? If so, that indicates thatGPStream.gstream
is a namespace, not a class. Your class probably has a different name or is nested inside that namespace (have you triedGPStream.gstream.gstream
?).