Reputation: 15623
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#.
Upvotes: 0
Views: 3177
Reputation: 106796
You havn't shown the code that results in the error. However, the Microsoft.VisualBasic.Compatibility
assembly only contains a single namespace Microsoft.VisualBasic.Compatibility.VB6
. My guess is that you need to include this statement in your code
using Microsoft.VisualBasic.Compatibility.VB6;
You 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.VB6
namespace is in the top-level Microsoft
namespace 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 ScaleMode
enumeration is Microsoft.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 an using
statement at the start of your source file as shown above. Then you can simply refer to the ScaleMode
enumeration in your code.
The confusing part here is that the assembly name is almost the same as the namespace you need.
Upvotes: 2
Reputation: 62248
Not very clear, but it seems that you're referencing in the code defined in another assembly and VS reports an error, even if that assembly regularly linked to main project.
Considering that you're talking about Outlook 2003 add-in in, the most frequent case is that that assembly/project is not in a corresponding .NET runtime version. For example your main project has .NET Framework 4.0 version, assembly/project has 2.0 version.
Hope this helps.
Upvotes: 1
Reputation: 46555
Are you by any chance targeting the .NET 4 Client Framework, and does changing it to the full framework fix it?
Upvotes: 2