Cannot use external references with C# Console Application

最后都变了- 提交于 2019-12-05 20:19:13

问题


I have tried all the suggestions below but still no joy.

I'm now trying a console application, and let me explain exactly what I'm doing.

  1. I create a new console project in VS 2010
  2. I add a number of references (dll's) some that aren't mine such as Castle.Winsor and N2 CMS dlls
  3. in the console app I can add using statements indicating I am using name spaces within the referenced DLLs
  4. I start writing code.
  5. As soon as I compile all the code that uses the referenced DLLs immediately complains with "The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)"

I have tried setting the dlls to copy to local always, I have copied the DLL into the same directory, I have tried added reference by project and adding a reference to the DLL's themselves

I don't get this problem with a web application project or a ASP.net project they always work fine, only something that is compiled to an EXE like a console app or windows service.

there must be something I'm missing or I would have got this working by now.


回答1:


Change the project Target to a non Client Profile target. Right click the Project and select Properties, you should see a list of Framework versions. As you are using VS2010, the Console project you've created by default targets .NET Framework 4.0 Client Profile, change that to .NET Framework 4.0.




回答2:


Check if Copy Local is set to true for the referenced assembly.




回答3:


First, as to your question, its hard to know exactly what you're doing wrong, but from the fact that you're using an underscore in an assembly name (and probably in namespaces and type names), it suggests you're rather new to the .NET world.

This suggests that you're adding references to other projects in your solution by browsing to the compiled assembly, rather than by adding a Project Reference. When adding a reference, you must select the Project tab rather than browsing for the assembly.

Even if you don't believe this is the issue, remove all references and re-add project references to make absolutely sure. Assumption, asses etc.

Once you've done that, I'd strongly suggest remove all the underscores from your types, namespaces and assemblies. You might want to go read the framework design guidelines, too.




回答4:


Open your .Proj(Windows service project file) file in notepad and check whether your assembly location(data_object) is the same which you are pointing.

When you open .Proj file in notepad you can check for,

Project reference,

        <ProjectReference Include="C:\StackOverflow\StackOverflow.csproj">

And if you giving dll or exe refrence then

 <Reference Include="StackOverflow, Version=1.0.0.0, Culture=neutral,       processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion>
  <ExecutableExtension>.exe</ExecutableExtension>
  <HintPath>C:\StackOverflow\bin\Debug\StackOverflow.exe</HintPath>
</Reference>

I suggest you to give exact location including drive name like above example.

Other option you may try,

 1. Clean and rebuild
 2. Add Project reference if you already tried dll reference
 3. Check whether the folder (referred assembly location) is Read Only then remove it. 


来源:https://stackoverflow.com/questions/4572043/cannot-use-external-references-with-c-sharp-console-application

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