问题描述
我已经在asp.net/C#网站上工作了一段时间,并决定将我的SQL C#代码放入类库(.dll)中。问题是,当我尝试将其添加到vs2010中的网站应用程序中时,会看到它,但是却无法同时显示。我的意思是,Web应用程序告诉您它是作为引用添加到引用文件夹下的,但是在编译代码时它将说您没有引用。
I have been working on an asp.net/C# website for a while and decided to put my SQL C# code into a class library (.dll). The problem is, when I try to add it to my website application in vs2010 it sees it, but doesn't at the same time. What I mean is the web application tells you that it is added as a reference under the reference folder, but when compiling the code it will say you don't have the reference.
添加参考的方法是右键单击解决方案,然后选择添加参考。我浏览参考(.dll文件),然后添加它。
The way I add the reference is by right clicking the solution and selecting "add reference". I browse for the reference (.dll file) and then add it.
这是错误:
CS0246: The type or namespace name SQL_lib could not be found (are you missing a using directive or an assembly reference?)
我做到了将dll文件代码中包含的所有引用添加到Web应用程序中,这样就不可能...我真的不知道发生了什么。预先谢谢您:-)
I did add all the references in the web application that the dll file code had so it can't be that... I really don't know whats going on. Thank you in advance :-)
编辑:
Web应用程序唯一一次显示找不到的时间该引用是在完成编译后才执行的。在浏览器中,它显示上面的错误。当我进入代码时,出于某种原因,我在代码中看不到带下划线的错误标记,并且可以在引用中访问该类。我将进一步研究它。
The only time the web application shows that it cannot find the reference is when it is done compiling and just executed. In the browser it shows the error above. When I go into the code I see no underlined error markings in the code for some reason and I can access the class within the reference. I will further look into it...
此外,在基于aspx的cs文件和纯cs文件中也存在错误。
Also it has the error in aspx based cs file and plain cs files.
推荐答案
我遇到了类似的问题,并在这里找到了解决方法。此处的答案对我不起作用,但这是我为解决该问题所做的工作。
I struggled with a similar problem and found my way here. The answers here didn't work for me, but here is what I did to solve it.
我不得不将文件添加到GAC。
I had to add the file to the GAC.
gacutil.exe /i MyFile.dll
然后您可以获取版本和
gacutil /l MyFile
全局程序集缓存包含以下程序集:
The Global Assembly Cache contains the following assemblies:
然后您取值并将它们复制到aspx页的顶部进行注册,然后包含。
Then you take the values and copy them into the top of your aspx page to Register and then include.
这篇关于将自定义.dll类库添加到asp.net/C#网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!