C# Different but similar Namespaces cause errors - c#

I currently have to deal with two different namespaces.
The first namespace is from a class library and looks like this: Autodesk.DataManagement.Client.[...]
The second one is a wrapper library I am coding and has the namespace: My.Autodesk.Wrapper[...]
My problem is that this is throwing tons of errors because the IDE can't make a difference between my namespace and the namespace of the library (I use both libraries in the same class)
This is the error I get Error CS0234 The type or namespace name 'Connectivity' does not exist in the namespace 'My.Autodesk' (are you missing an assembly reference?)
EDIT for additional information:
Currently my library only contains a Connection Class and a IConnection interface.
Without referencing my wrapper library the code in the main project works fine:
But after referencing my library everything in the main project breaks:
It looks like it is mistaking my library with the Autodesk library just because I have the term Autodesk in my namespace.
What would be the solution? Do I really have to rename my library?

try using this format
using YourClass = My.Autodesk.Wrapper.[..].YourClass

Related

Can't add popular namespaces references to C# .DLL Class Library

My question in simple few lines:
I'm trying to build a compiled .dll C# Class Library that contains functions I want to easily call from other non-C# applications.
My functions depend on popular namespaces' Assemblies references like System.Windows.Forms and Microsoft.Office.Interop.OneNote.
When I try to add any of them to my class library, I get does not exist in the namespace error.
Also, they don't exist in Reference Manager (Screenshot 2).
Continued description:
Within normal C# application (that's compiled to .exe), I can easily include those Assemblies references using code lines like below:
using System.Windows.Forms; // works good in normal application
using Microsoft.Office.Interop.OneNote;
Also I am able to add References with References Manager (by right clicking the References node on Solution Explorer → then Select Add Reference → then search for the references I want to add) — in Visual Studio 2019 (Screenshot 1). I can find and add assemblies like System.Windows.Forms and Microsoft.Office.Interop.OneNote easily.
But within a C# Class Library (that's compiled to .dll), when I try to include System.Windows.Forms and Microsoft.Office.Interop.OneNote using the below lines:
using System.Windows.Forms; // gives errors in C# Class Library
using Microsoft.Office.Interop.OneNote;
I get errors:
CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?) MyLibrary C:\Path\to\MyLibrary\Class1.cs
CS0234The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) OneNoteLibrary C:\Path\to\MyLibrary\Class1.cs 15 Active
Also, these assemblies aren't shown at all when I try to add using References Manager (Screenshot 2).
Screenshot 1:
Screenshot 2:
Screenshot 3:

Can't find namespace in Global

I have the job of getting a legacy project working again. This project was done many years ago using Silverlight and C# Class Library's.
The error I am getting is to do with a namespace inside the project file called Silverlight.Business:
Code
using Tcx = global::MapTools.Xml;
Error:
The type or namespace name "MapTools" could not be found in the global namespace (are you missing an assembly reference?)
MapTools is a C# Class Library and Silverlight.Business is a Silverlight Library. Due to this I can't add a reference to MapTools inside the Silverlight project file.
The silverlight project does have a WCF RIA Service's Link but that does not connect to anything.
I am now wondering how the person that wrote the code has managed to call that namespace? I have tried researching how to add the MapTools.dll to the Global namespace but have not found anything.
Anyone have any ideas?
To do that there should be an some tool been used .
We had used in our projects a Portable library which allowed us to communicate through cross type of projects , below is the link :
https://msdn.microsoft.com/library/gg597391(v=vs.100).aspx

Getting an error with my model project and DAL specifically with my Text Template in C# .NET 4.5 and ObservableListSource

I am using .NET 4.5/4.6 and C#.
I am trying to follow the following sites Generic DAL and Entity Framework with my winforms application. I was able to implement link 2, however after implementing part of link 1 (specifically after moving my model Text Template, I have errors stating that The type or namespace name 'ObservableListSource<>' could not be found (are you missing a using directive or an assembly reference?)
What namespace do I need to reference at the project level to fix this for my solution or what reference do I need to include with my text template in order for the entities to contain no errors?
Assuming you're using this ObservableListSource the proper namespace would be System.Data.Entity
Found it. the answer is at the beginning of Databinding with winforms. Its a section of code that was overlooked several times and not a c# keyword.

Type or namespace not found. Visual Studio suddenly demands global prefix on using statements

It happened to me before and I never know why it happens.
Suppose you have a simple C# class with some using statements inside(!) the namespace definition. It worked flawlessly for hours. Now I worked on a completely different project and all of a sudden the former project won't compile anymore claiming a part of the namespace cannot be found anymore. R# then suggests to fix this by using global::...
The type or namespace name 'Internet' does not exist in the namespace 'Cmp.Internet.Portal.Web' (are you missing an assembly reference?)
so
using Cmp.Internet.Portal.Web.Common;
becomes
using global::Cmp.Internet.Portal.Web.Common;
I do understand what it means but I'm puzzled about why it happens.
And it should not even be necessary.
An example to make it more obvious...
Let's assume I have 3 projects.
Project.Core
Project.One (references Project.Core)
and Project.Two (references Project.Core)
Now Project.One can have using statements inside its namespace without using the global prefix. Project.Two cannot. Why? ...
I believe the problem occurred because different assemblies provided the same namespaces. It happened because we were in the middle of a refactoring and classes were moved between assemblies.
Once every namespace was provided by only one assembly the global:: prefix became superfluous.

How do I get an empty project to compile as a dll?

I created a new VS "empty" project, and in it made a class. I decided to try this out as a library, went into properties and set the output type to class library. It compiles to a dll, though when I add it as a reference to another project, typing in "using ..." doesn't have my new library in there. If I create a new library project, past my class in there, compile that into a dll, then it works fine. So what I want to know is, what settings to I need to change in a blank project to get it to act as a dll?
using directives are about namespaces, not assemblies.
If your library is empty, it's not contributing anything to a namespace, so a using directive won't find anything.
It's very important that you understand the difference between a namespace and an assembly - you could have library Foo.dll which only contains Bar.Xyz. You would add a reference in your project to Foo.dll, but a using directive for Bar.
As a more concrete example, the Enumerable class in the System.Linq namespace comes from System.Core.dll - but you still add the using directive for System.Linq, not System.Core. Indeed, if you try to add a using directive for System.Core, you'll get an error - because that namespace doesn't exist. (A namespace effectively doesn't exist if it has no members.)

Categories

Resources