Why does my Visual Studio show the error:
The type or namespace name ‘Compatibility’ does not exist in the namespace ‘Microsoft.VisualBasic’ (are you missing an assembly reference?)
when I do have Microsoft.VisualBasic.Compatibility component already referenced under the .NET tab of Add Reference dialog box.
My .net knowledge is at very basic level. I did google the issue but couldn’t find relevant solutions. Any help, hint, suggestion, links will be much appreciated.
EDIT
The project is actually an Outlook 2003 add-in in C#.
You havn’t shown the code that results in the error. However, the
Microsoft.VisualBasic.Compatibilityassembly only contains a single namespaceMicrosoft.VisualBasic.Compatibility.VB6. My guess is that you need to include this statement in your codeYou state that you .NET knowledge is at a very basic level so let me try to clarify a bit.
Adding a reference to an assembly in your project allows you to instantiate types defined in that assembly and execute code belonging to these types. Simplifying things a bit you can think of the assembly name as the name of the file with the code without the DLL extension. In this case the name of the assembly is
Microsoft.VisualBasic.Compatibility.To avoid identificer collisions .NET has the concept of a namespace. Namespaces are hierarchical in nature just as internet domain names are. The
Microsoft.VisualBasic.Compatibility.VB6namespace is in the top-levelMicrosoftnamespace with three subordinate namespaces.To refer to a type you need to qualify it by using the namespace, e.g the fully qualified name of the
ScaleModeenumeration isMicrosoft.VisualBasic.Compatibility.VB6.ScaleMode. However, you soon get tired of doing that and most of the time you will import all the types from a namespace by putting anusingstatement at the start of your source file as shown above. Then you can simply refer to theScaleModeenumeration in your code.The confusing part here is that the assembly name is almost the same as the namespace you need.