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
Related
I am trying to go through this tutorial for on making sounds with waves using C#:
https://www.codeguru.com/dotnet/making-sounds-with-waves-using-c/
The first sample code it has you run is this, which is supposed to play a .wav file:
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.Devices;
namespace MyApp
{
class Program
{
static Audio myAudio = new Audio();
static void Main()
{
myAudio.Play("m:\\crooner2.wav",
AudioPlayMode.WaitToComplete);
}
}
}
In my code, the filepath and name of the .wav file was replaced with a different one, but otherwise the code is identical. However, I get an error regarding the second line of code: error CS0234: The type or namespace name 'Devices' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)
Without the Microsoft.VisualBasic.Devices call working, I have no way of running even the first exercise in the tutorial, and definitely no way of further progressing in using C# for sound manipulation.
I was expecting the code to run and play the .wav file. However, I got the error message instead.
As part of debugging, I came across this post on the Microsoft website:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/visualbasic#types-in-microsoftvisualbasicdevices-namespace-not-available
I'm not sure what to make of it. It seems like it's saying it could be solved by upgrading to .Net 5 or higher, but I'm already using .Net 5. It also seems like it saying that Microsoft.VisualBasic.Devices was made obsolete with .Net Core 3.0, so I'm not sure how upgrading would make it easier to use something that was made obsolete.
It also says that certain functionality in Microsoft.VisualBasic.Devices has equivalent functionality that can be called by other means. It gives specific replacement calls for Microsoft.VisualBasic.Devices.Clock and Microsoft.VisualBasic.Devices.Ports, but nothing for Microsoft.VisualBasic.Devices.Audio, which is what I want to use in my code.
I have tried this in both Visual Studio and Visual Studio Code and get the same errors either way.
With .NET Core, you generally add references via NuGet packages. There is no NuGet package for Microsoft.VisualBasic.Forms.dll, which the documentation clearly states that type is declared in. To get that assembly reference, I believe that you need to replace this line in your project file:
<TargetFramework>net5.0</TargetFramework>
with these lines:
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
After doing that, you should see Microsoft.WindowsDesktop.App.WindowsForms added under Dependencies -> Frameworks in the Solution Explorer and the relevant assembly is listed under that.
You have to use reference to "Microsoft.VisualBasic" in your project.
You have two way for do that :
1st way :
Right click on project references, select "Assemblys" => "Framework" and you can search (at top right) "basic" keyword, and select "Microsoft.VisualBasic" item.
After that you can compile your project and normally its works !
Screen for add references
2nd way :
Comment or delete "using Microsoft.VisualBasic.Devices;" instruction.
The class "Audio" should be underline to red, hover with your mouse and you have option by IDE which let you "using Microsoft.VisualBasic.Devices;".
References should be automatically added in project.
And now you can compile your project.
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:
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?
I'm using creating a .Net 4.0 application to post stuff to Twitter using the Tweetinvi API. I can't use packages, so I've downloaded the dll's and added them to my project:
Yet my includes are showing errors:
My error console shows:
Error 423 The type or namespace name 'Core' does not exist in the
namespace 'Tweetinvi' (are you missing an assembly
reference?) {...file...}.cs 10 17 ApiProviders
Can anyone tell me why this happens and how I could fix this?
Tweetinvi requires the Bcl.Async package. You need to add that too.
Check all the dependencies and make shure all are installed.
BUT as already said I highly recommend using NuGet for this. If you are not allowed to use the "public feed" you can download the packages and put them in a local folder and add this folder as a new feed in Visual Studio.
Have you tried downloading the project from the download page?
https://tweetinvi.codeplex.com/downloads/get/852208
I am currently working on windows application in c# and currently I met one problem.
I started to creating the windows application in notepad++ because I not able to use VS. I am using cmd to compile the code. I will add that I have one *.dll file, which is used by the application.
Now I am trying to move my code to VS. I created new solution and I used add existing item to include my code files. I also added reference to the *.dal file. I also added using namespace statment in my MainForm.cs file. Now I get problem because when I am tryind go tompile the code I got error:
The type or namespace name 'DataAccessLayer' could not be found
(are you missing a using directive or an assembly reference?)
I am wondering where I made mistake?
Original post here.
In the project properties, change the Dotnet framework from 2.0,3.0 or 3.5 to 4, compile and run!