how to run properly C# code on console app using VS code? - c#

I'm trying to view very basic code looping through models. but, every time I run VS code console app I get this error
The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
The build failed. Fix the build errors and run again.
I use the following command to run the app
dotnet run // to reun console application
what's wrong with the code !!
using System;
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>();
}
}

All you need to know is inside the message ;)
The build failed. Fix the build errors and run again.
-> You are not running your app. It crashes already at the build.
The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
-> You did not Import the type List<>.
-> As you can see in the link below List<> can be imported by "using System.Collections.Generic". This should fix it.
https://learn.microsoft.com/de-de/dotnet/api/system.collections.generic.list-1?view=net-5.0

the error message is telling you exactly what you need to do, just add with the other using directives:
using System.Collections.Generic;

Related

Algolia - Push Data

Following the example of how to push data to algolia, tried to connect only to Algolia with SearchClient, have installed the Algolia with .NET CLI (dotnet add package Algolia.Search) in VS Code.
The code is the follow:
using System;
using System.Threading.Tasks;
using Algolia.Search;
using System.Net.Http;
using Newtonsoft.Json.Linq;
namespace Example
{
class Program
{
static async Task Main(string[] args)
{
SearchClient client = new SearchClient("SUMI5AMP4H", "Admin API Key");
SearchIndex index = client.InitIndex("demo_ecommerce");
Console.WriteLine("Hello World!");
}
}
}
with command dotnet run
that returns:
Program.cs(13,13): error CS0246: The type or namespace name
'SearchClient' could not be found (are you missing a using directive
or an assembly reference?)
Program.cs(14,13): error CS0246: The type or namespace name
'SearchIndex' could not be found (are you missing a using directive or
an assembly reference?)
The project was created with dotnet new console
So having the Algolia.Search package installed how does it not recognize SearchClient and SearchIndex?
Was able to figure it out, needed to take look at the package of the Algolia.Search, so to find the location search for Algolia.Search.dll as defined in the project.assets.json.
The path is the follow C:\Users\{user}\.nuget\packages\algolia.search\6.3.0\lib\netstandard2.0 that where the package/dll is located now to see the code installed JetBrains dotPeek and opened the dll and search for SearchClient Class that was in Clients namespace.
So change using Algolia.Search; to using Algolia.Search.Clients; and already works and recognizes.
As you discovered, there was an issue with the provided snippet. I've just updated it and my colleagues deployed it. You should now see the correct snippets appear on the https://www.algolia.com/doc/onboarding/ page.
Thank you very much for letting us know.

can't add System.Drawing.dll reference

Ok, so I'm on this bug for the last 4 hours and I dont know what to do..
I'm using Visual Studio Community 2017 and I opened Consol App(.net core) project. also I'm working on windows 8.1 OS.
I wanted to use Image from the System.Drawing namespace and it keeps giving me that error:
"the type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)"
I downloaded the System.Drawing.dll from https://www.dllme.com/dll/files/system_drawing_dll.html
(to the desktop) and then right click on the right project->add->Reference..->Browse..->System.Drawing.dll->OK
then I saw in the project (in the Solution Explorer) in the project dependencies->Assemblies->System.Drawing so I guess it works right?!
I'm still getting the same error and can't use the System.Drawing namespace, any suggestions?
using System;
using System.Net.Sockets;
using System.Drawing;
namespace client2
{
class Program
{
static void Main(string[] args)
{
try
{
//read image
Image image = new Image("C:\\image\\amir.jpg");
}
}
}
}
System.Drawing is not part of the cross-platform parts of .NET (Core). It depends on GDI+ which is part of Windows. There are plenty of alternatives out there.
Aside: Never download DLLs from an untrusted source.

iOS Run errors s Xamarin Live Player and Hanselman.Forms

I created an app based off the Hanselman Forms app. I'm trying to get it to run with the new Xamarin iOS Live Player and i'm getting runtime build errors.
To make sure it wasn't something i broke i did a fresh install of Hanselman Forms and Visual Studio 2017 Preview and connected the iPhone live player.
The build compiles fine with VS.
Trying to run the debug app with Live Player on iPhone gives the following errors.
The following errors were encountered when building and running your app:
• TweetStore.cs: The type or namespace name 'ITweetStore' could not be found (are you missing a using directive or an assembly reference?)
• TweetStore.cs: The type or namespace name 'Tweet' does not exist in the namespace 'Hanselman.Portable' (are you missing an assembly reference?)
• LaunchTwitter.cs: The type or namespace name 'ILaunchTwitter' could not be found (are you missing a using directive or an assembly reference?)
• AppDelegate.cs: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)
OK
The packets have been refreshed.
I've removed the bin/obj files to do a fresh build.
I've removed the reference, built clean, got similar errors in VS, added the reference back in and the VS build succeeds.
Android works fine.
Any ideas as to what i'm missing?
This is a known issue and is being worked on by the Xamarin folks.
Details at the following link. https://forums.xamarin.com/discussion/95825/ios-run-time-errors-type-or-namespace-name-not-found-with-xamarin-live-player-and-hanselman-forms/p1?new=1
Check that you have selected a Startup Project that matches your device type (iOS or Android) and that the configuration matches that device type (eg. Debug|iPhone Simulator for iOS).

How to use a DLL create from txt and compiled with Developer Command Prompt?

I generate cs files ( classes ) with the same namespace (EDR_Config). After I generate them, I compile them using Developer Command Prompt for VS2012.
The command line is :
csc /target:library /out:EDR_Config.DLL AssemblyInfo.cs
EdrClassInitializator_CFG.cs EdrEquationsDecoder_CFG.cs EdrTreeCreator_CFG.cs
Everything looks great till I add a reference to the c# project. When I try to write
using EDR_Config;
it tell me: Error 1 The type or namespace name 'EDR_Config' could not be found (are you missing a using directive or an assembly reference?)
Why is that happening? Or how can I solve it?

What QuickBooks SDK 13.0 namespace is required to instantiate QBSessionManager?

I have downloaded QuickBooks SDK 13.0 and am trying to build a very simple C# application that connects to QuickBooks via QBSessionManager.
I am using Visual Studio Express 2013. I have the following lines of code in the Load function of my very simple Form.
QBSessionManager sessionManager = new QBSessionManager();
sessionManager.OpenConnection("", "Application");
When I try to compile, I get
The type or namespace name 'QBSessionManager' could not be found (are you missing a using directive or an assembly reference?)"
I see lots of sample code that starts with instantiating QBSessionManager, but nothing that identifes the namespace or reference I need to specify.
Am I missing something really obvious?
Add the file QBFC13Lib.dll to your project requirements.
The file can be found in the c:Program Files(x86)\Common Files\intuit\QuickBooks directory of a standard install of quickbooks.

Categories