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:
Related
I'm trying-out C# and .NET 5 for the first time, but I'm having trouble importing packages.
First of all I'm using VCode as my IDE and installed C# Extension (and enabled: Omnisharp: Enable Import Completion).
When I write a function using for example List, I don't get a recommendation to import:
using System.Collections.Generic;
It also doesn't recognize other classes in my project. Even when I import manually for example:
using WebApp.Model.Item;
I get an error like this:
The type or namespace name 'Item' could not be found (are you missing a using directive or an assembly reference?) C:\Users\ljhha\Documents\IT\C\WebApp\WebApp\WebApp.csproj
I also trying the same in Visual Code and get the same error.
I Build, Rebuild used Debugging, re-open the IDA. So I'm out of options?
Please check the full code here on github
I am trying to create a form in C#.
Unfortunately, I can not use Visual Studio for this effort.
The program I am using has a live script c# compiler that allow user to write and compile code within the program. I am trying to use
using System.Windows.Forms;
but I get the following error
The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
Is there a way to reference System.Windows.Forms with out visual studio?
I tried this on a online compiler and got similar results so maybe there is a correlation?
On Mac Visual Studio - Xamarin Project, I get an error:
the type or namespace 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference)
I have tried to resolve it by using the nuget package manager. Specifically, click 'Packages' folder and click 'Add Packages...' and add Linq. Yet it still does not find Linq when I write 'using System.Linq' yet I can see 'System.linq' in the package folder under the project.
Tried : Refresh, Update, turn off and on
Why can't it find and use the package?
Edit: For similiar error 'HttpStatusCode' where it not found under 'System.Net' yet I have the dll (Version 2.0.5.0) found. I tried to install a new nuget package for it, System.Net.Primitives (Version 3.0.9.0) where 'HttpStatusCode' is stored under this new version. When I reference System.Net.Primitives it does not work.
Example:
'\\ The type or namespace name 'Primitives' does not exist in the namespace 'System.Net'
Using System.Net.Primitives;
Using System.Net;
namespace code {
public class Example
{
\\ the type or namespace 'HttpStatusCode' could not be found
public HttpStatusCode HttpResponse;
}
}`
You need just to add System.Core to your References.
In one of my project I solved it by following way:
Open solution explorer. Right click references, Click on assemblies, select system.xml.linq.
Add the reference assembly to the project. Clean and rebuild.
It should serve the purpose.
Add this .nuget to your Solution. Micosoft.Net.Http.
I have a solution with about 12 projects, one is set as the startup project and this contains the main window. At the moment all of my IValueConverters are inside this project.
I now want to move them into a separate project that will hold only converters. This way I will be able to reuse them across all the projects, not just the main window.
I have created a new project (class library)
I have imported WindowsBase
I have Included a reference to System.Windows.Data
I am using Visual Studio 2010 Express with .NET 4
I get the error:
"Error 3 The type or namespace name 'IValueConverter' could not be found (are you missing a using directive or an assembly reference?)
"
You need to add a reference to PresentationFramework.dll, that's where IValueConverter is actually defined.
Looking at the documentation you can find that information at the top:
Namespace: System.Windows.Data
Assembly: PresentationFramework (in PresentationFramework.dll)
Please have a look here. I'm sure you're missing the library PresentationFramework.dll in your project.
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.)