简体   繁体   English

C#Visual Basics参考不可用

[英]C# visual Basics references not available

I can't even get off the ground.I DO KNOW HOW TO ADD REFERENCES, (this."""mshtml""" NOT[working]) 我什至无法动手。我知道如何添加参考,(此。“”“ mshtml”“”“不[工作])

using System;
using system.text;
using mshtml; // i cant seem to access this

I'm confused on why when I type mshtml it's in capitals, MSHTML . 我对为什么当我输入mshtml时使用大写的MSHTML感到困惑。 The problem I'm having is I'm just using a variety of tutorials but can't seem to even start them as this is my first problem. 我遇到的问题是我只是使用各种教程,但似乎甚至无法启动它们,因为这是我的第一个问题。

I have manually browsed when adding references to my application but it doesn't seem to work. 将引用添加到我的应用程序时,我已经进行了手动浏览,但是它似乎不起作用。 I keep getting the capital letter version, except there is no capital letter version of MSHTML.dll in my directories on my PC. 我一直得到大写字母的版本,但PC上的目录中没有MSHTML.dll的大写字母的版本。 If for some reason I don't have this file can it been downloaded for free safely or are my tutorials just too old? 如果由于某种原因我没有此文件,可以安全地免费下载该文件,或者我的教程太旧了吗?

Also just to let you know I understand where these files are meant be, in regards to folders locations ect. 也只是为了让您知道,就文件夹位置等而言,我了解这些文件的含义。 I thought if I just add the reference in to my project it should just be there. 我想,如果我只是将引用添加到我的项目中,就应该在那里。

I think you have a misunderstanding by your terms 'capital letter version'. 我认为您对术语“大写字母”有误解。

The name of a dynamic link library, although usually indicative of its purpose and aptly named, isn't strictly tied to the contents of the assembly. 尽管动态链接库的名称通常可以指示其用途并恰当地命名,但它并不严格地与程序集的内容绑定。 You can call it what you want (within reason and limits of the system) and the code inside remains the same. 您可以根据需要(在系统的原因和限制内)调用它,并且内部的代码保持不变。

If you've added a reference to a 'MSHTML.dll' file, then it is very probable that a namespace of 'mshtml' is defined - I didn't say ideal, but probable. 如果您添加了对“ MSHTML.dll”文件的引用,则很有可能定义了“ mshtml”命名空间-我说的不是理想的,但可能是。 Casing within the code does matter though - so if, for instance, Intellisense is showing you a case-variant version of what you're typing then it's probably that. 不过,代码中的大小写确实很重要-因此,例如,如果Intellisense向您显示您所键入内容的大小写不同,则可能是这样。 Either way, it won't be what you've been typing if you ignore it. 无论哪种方式,如果您忽略它都不是您一直在键入的内容。

If you could reference the tutorials you were following then it would likely be easier to see what the actual problem was. 如果您可以参考所遵循的教程,那么可能会更容易了解实际问题所在。 Other than that, go ahead with the code that it provides. 除此之外,继续它提供的代码。

As an aside, I'd recommend some reading up on Assemblies in .NET . 顺便说一句,我建议您阅读.NET中的Assemblies

Thank you for pointing out that this is your first C# program. 感谢您指出这是您的第一个C#程序。 It helps us understand the level at which to try to answer. 它可以帮助我们了解尝试回答的级别。

First, I'd like to address a statement you made: 首先,我想谈一谈您的发言:

there is no Capital letter version of MSHTML.dll in my directories 我的目录中没有MSHTML.dll的大写字母版本

It seems that you're confusing Namespaces with .dll names, which is something I struggled with myself at first. 似乎您将命名空间与.dll名称混淆了,这是我起初为自己所苦的。 There's a full explanation here , but it may be too technical for beginner level developers. 有一个完整的解释在这里 ,但它可能是初学者的水平也开发技术。

In a nutshell, at the top of the file where your "using" statements are, you're telling the compiler where to look for certain classes and code by Namespace. 简而言之,在文件的“使用”语句所在的顶部,您告诉编译器在何处按名称空间查找某些类和代码。

A Namespace is a logical grouping of code. 命名空间是代码的逻辑分组。 For convenience and clarity, developers group similarly functioning code into Namespaces. 为了方便和清楚起见,开发人员将功能相似的代码分组到命名空间中。 For example, Data Access code is in the System.Data Namespace. 例如,数据访问代码位于System.Data命名空间中。

When adding a .dll you're adding an actual file reference. 添加.dll时,您要添加实际的文件引用。 In a less-confusing world, .dlls would be named to reflect the Namespaces contained within them. 在一个不太混乱的世界中,.dll将被命名为反映其中包含的命名空间。 However, it's not always that simple. 但是,它并不总是那么简单。 It' is perfectly possible for me to create a dll named "DaveStratton.dll" that contains Booyah.Encryption, Simple.Functions or any other Namespace I want. 我完全有可能创建一个名为“ DaveStratton.dll”的dll,其中包含Booyah.Encryption,Simple.Functions或我想要的任何其他命名空间。 There really is no correlation except by convention, and it's not enforced." 除了约定外,确实没有任何关联,并且没有强制执行。”

For example, if you look in the MSDN Library at the System.Data.SqlConnection class. 例如,如果您在MSDN Library中的System.Data.SqlConnection类中查找。
The Class name is actually SqlConnection, and it lives in the System.Data Namespace. 类名称实际上是SqlConnection,它位于System.Data命名空间中。 The System.Data Namespace is contained in the System.Data.dll. System.Data命名空间包含在System.Data.dll中。 (because the developers were following convention and did it this way for clarity.) Screenshot below: (因为开发人员遵循约定,并且为了清楚起见,所以这样做。)下面的屏幕截图:

在此处输入图片说明

If you look at other classes, you may find discrepancies. 如果您查看其他课程,可能会发现差异。

For example, the System.Configuration.SettingsBase class: The SettingsBase class in in the System.Configuration namespace, but if you look at the assembly information, you'll see that it's in System.dll. 例如, System.Configuration.SettingsBase类:System.Configuration命名空间中的SettingsBase类,但是如果查看程序集信息,则会发现它位于System.dll中。 And the System.Configuration.ConfigurationManager is in the System.Configuration.dll. 并且System.Configuration.ConfigurationManager在System.Configuration.dll中。


So, long story short, you need to know the Assembly (.dll) name when adding a reference in Visual Studio, but you need the class/assembly name when writing your code. 因此,长话短说,在Visual Studio中添加引用时,您需要知道程序集(.dll)名称,但是在编写代码时,您需要类/程序集名称。 In your using statement, you need capital letters because the Namespace is capitalized, ewven if the .dll isn't. 在using语句中,您需要使用大写字母,因为命名空间是大写的,如果.dll不是,则即使是大写也是如此。

it sounds like you need to add a reference to your project first. 听起来您需要先添加对项目的引用。 Open up your solution, in the right project explorer, expand references, right click references to add a reference. 打开您的解决方案,在正确的项目浏览器中,展开引用,右键单击引用以添加引用。 Now find the Microsoft.mshtml and add that as a reference. 现在找到Microsoft.mshtml并将其添加为参考。

有关使用问题,请参见此处 ,您需要为此特定的COM库1添加一个引用(右键单击项目,添加引用): 如何在VB.NET中使用MSHTML?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM