The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data'

丶灬走出姿态 提交于 2019-12-07 05:30:02

问题


When trying to run my code, I receive the following error:

CS0234: The type or namespace name 'OracleClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

I have included references to System.Data.dll and System.Data.OracleClient.dll, but I am still getting this error.

The error is being caused by the line using System.Data.OracleClient in my namespace declaration.


回答1:


The using System.Data.OracleClient directive means that that namespace should be considered when trying to determine what non-full names mean.

Adding a reference, means you add a reference to a given assembly, in this case System.Data.OracleClient.dll. From VisualStudio, SharpDevelop or MonoDevelop you will see a references folder in the project explorer view. Right click and "Add Reference" (VisualStudio and SharpDevelop) or "Edit References" (MonoDevelop), and add in System.Data.OracleClient.dll

If using nant you'll need to edit your nant script.

Assemblies and namespaces overlap, but aren't quite the same. The reference means you can use e.g. System.Data.OracleClient.OracleDataReader because the project now knows what assembly the code for that lives in. The using directive means you need only type OracleDataReader. There tends to be a heavy match between assemblies and namespaces because that makes life easier for everyone, but there are both times when an assembly has classes from more than one namespace, and when a namespace is split over more than one assembly. A classic example is that mscorlib has a lot of classes from System, System.Collections, System.IO etc. that you couldn't really hope to build a .NET project without (including some that .NET uses itself), while System.dll has a bunch more from exactly the same namespaces that you could feasibly get by without using (but you still will 99% of the time).

Unless you're writing an absolutely massive library though, with thousands of classes covering overlapping use-cases, your own assemblies should work with a single namespace - or at most a single one with some other namespaces within that one, like JaredksGreatCode having JaredksGreatCode.UserInterface within it - per single DLL.




回答2:


The following worked for me:

Visual Studio --> WEBSITE --> Add Reference... --> Framework --> System.Data.OracleClient [check this option]




回答3:


I had to add a reference to the Oracle.DataAccess.dll, and then I had to manually associate all the references to OracleClient.blahblah with Oracle.DataAccess.Client.blahblah.

Hopefully this helps someone else.




回答4:


Add a reference into your web config file as shown below. This works for me.


<!--REFERENCES-->
<compilation debug="true" targetFramework="4.5">
  <assemblies>
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </assemblies>
</compilation>



回答5:


You add reference on System.Data.OracleClient.dll.



来源:https://stackoverflow.com/questions/12218027/the-type-or-namespace-name-oracleclient-does-not-exist-in-the-namespace-syste

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!