I'm trying to get this library to work inside my project. I've downloaded it to my documents folder and in the same documents folder I've created a new C# console app with just a Program.cs to try and run it. I can compile the library as far as I know.
Now, I've imported the project into my project using:
dotnet add C:/blabla/documents/tachograph-reader-test-code/tachograph-reader-test-code.csproj reference C:/blabla/documents/tachograph-reader/src/tachograph-reader-lib.csproj
and this worked just fine. As the following piece of code is added to my project file:
<ItemGroup>
<ProjectReference Include="..\tachograph-reader\src\tachograph-reader-lib.csproj" />
</ItemGroup>
Now for the life of me, I can't figure out how to use the library?
Intellisense does not see the library in any way. the using keyword doenst work either. De namespace should be DataFileReader but I cannot use it, and it won't compile.
By the way, I'm using VS CODE not vs studio.
So, how do I use such a library inside my project?
The problem is not in your project reference. I guess you have to add these three namespaces as follow:
using System.IO;
using System.Text;
using System.Xml;
Your Program.cs should look like:
using System;
using System.IO;
using System.Text;
using System.Xml;
using DataFileReader;
namespace tachograph-reader-test-code
{
class Program
{
static void Main(string[] args)
{
...
}
...
}
}
Related
I was recently watching tutorials on C# where they mentioned that specifying either using System and then using Console.WriteLine or writing System.Console.WriteLine if you don't specify using <namespace> was necessary for proper namespace resolution to happen when writing programs otherwise the compilation would fail.
But when I'm using Visual Studio 2022, Console.WriteLine seems to work without specifying any namespace at all.
Is this some optimisation that Visual Studio 2022 does? Why is this working?
On top of this, if I use System.Console.WriteLine, VS 2022 also greys out System and says "name can be simplified".
Try this
using System;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
If you create c# project of asp.netframrwork. It will automatically generate the "using System" namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
}
}
}
If your console project is .NET 6 and above. Please refer to Exploring Ideas to Build Code While Learning Using Top-Level Statements.
Hope it helps you.
/* If I am building after deleting Newtonsoft.Json.dll then It works fine but after clean and build getting the same error?*/
using System;
using System.Web;
using System.Data;
using System.Collections;
using localhost;
using System.Text;
using System.Collections.Generic;
using System.Net.Mail;
using System.Net;
using BusinessLayerGDS.Model;
using BusinessLayerGDS.BAL;
using System.IO;
using System.Security.Cryptography;
using System.Linq;
using System.Configuration;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Xml;
**And The codes:**
Newtonsoft.Json.Linq.JObject objActualData=Newtonsoft.Json.Linq.JObject.Parse(strResponse);
What you need to do is go to:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Or where this folder is in your computer:
>
Temporary ASP.NET Files
I have seen some people configuring it under:
c:\Users[youruserid]\AppData\Local\Temp\Temporary ASP.NET Files
Or you may be using a different .net version than v4.0.30319
Inside this folder you may find some odd folder names one of those is the folder of your application, you need to find which on it is then you should delete what's inside the bin
If some files or folders are locked you may need to stop your IIS or IIS Express.
Go to back and rebuild your application; it should work fine then
Close VS
Open your .csproj file with a text editor
Look for all the hintpath tags for Newtonsoft
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Fix the hintpaths ALL - look carefully, it can be configured at multiple locations and Nuget was not bulletproof for me anyawy.
I'm trying to get a simple "Hello World" type WebSocket server running on my Mac using Visual studio for Mac OS X.
Where are the HttpContext.IsWebSocketRequest property and the
HttpContext.AcceptWebSocketRequest method? The documentation appears to say they are in HttpContext inside the System.Web dll but I've referenced that (as well as System.Net) and Visual studio can't find them.
Is there something I'm missing or have forgotten?
This is the code I've that's giving me problems.
using System;
using System.Web;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net.WebSockets;
using System.Collections.Generic;
public void ProcessRequest(HttpContext context)
{
if (context.IsWebSocketRequest)
context.AcceptWebSocketRequest(HandleWebSocket);
else
context.Response.StatusCode = 400;
}
The sample I'm following is: https://github.com/paulbatum/WebSocket-Samples/blob/master/AspNetWebSocketEcho/EchoHandler.ashx.cs
As far as I remember is not supported yet: http://go-mono.com/status/status.aspx?reference=4.5&profile=4.5&assembly=System
You can use one of the many third-party components available for Mono. I develop and maintain one of them https://github.com/vtortola/WebSocketListener
I'm using Visual Studio Code and .NET core on OSX.
HtmlAgilityPack.NetCore.1.5.0.1 has been installed to the project folder. All of my project files, HTMLAgilityPack.NetCore.1.5.0.1 and all of the dependencies are visible in the explorer pain. Yet I cannot create a reference to any HtmlAgilityPack assemblies.
The code is simple. It compiles and runs.
namespace ConsoleApplication
{
using System;
using System.Text.RegularExpressions;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello, world");
}
}
}
Is there a step beyond installing the nuget package that I need to perform to get this to work?
Unless I'm misunderstanding your question, this should be very straight forward. All you need to do is:
1: Add the nuget package into your project.json file like so, then run dotnet restore in the same directory as your project.json file to restore your newly added package.
...
},
"dependencies": {
"HtmlAgilityPack.NetCore": "1.5.0.1"
},
"frameworks": {
...
2: Add the following using statement to the top of your code.
using HtmlAgilityPack;
This works for me:
namespace ConsoleApplication
{
using System;
using HtmlAgilityPack;
public class Program
{
public static void Main(string[] args)
{
HtmlDocument doc = new HtmlDocument();
Console.WriteLine("Hello, world");
}
}
}
Note:
As you're using Visual Studio Code on OSX, you can reference a class and then press the shortcut CMD + . to bring up Visual Studio Code's tool window and automatically import your missing using statement.
I want to use novacode-docx in cs-script. how can I give correct reference to the assembly. I tried following but didn't work around the assembly reference missing.
//css_reference D:\lib\DocX.dll;
using System;
using System.Diagnostics;
using System.Windows.Forms;
class Script
{
[STAThread]
static public void Main(string[] args)
{
using (DocX doc = DocX.Create(#"C:\Users\name\Desktop\test.docx"))
{
doc.PageLayout.Orientation = Orientation.Landscape;
var table = doc.AddTable(12, 2);
doc.InsertTable(table);
doc.Save();
}
}
}
You cannot reference an explicit path like that for presumably security reasons. The assembly must be placed in one of the following locations and referenced as //css_reference DocX.dll;
File location The assembly to be loaded must be from one of the following locations (the order indicates the assembly search
priority):
the same directory where the script is
Default Script Library directory Script Library (%CSSCRIPT_DIR%\Lib)
Custom Script Library directory(s) (specified in the configuration console SearchDirs)
GAC
See here for more info: http://www.csscript.net/help/using_.net_assemblies.html
Drop the Docx.dll into the same folder as where the cs script is and try this:
//css_reference DocX.dll;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Novacode;
class Script
{
[STAThread]
static public void Main(string[] args)
{
using (DocX doc = DocX.Create(#"C:\Users\name\Desktop\test.docx"))
{
doc.PageLayout.Orientation = Orientation.Landscape;
var table = doc.AddTable(12, 2);
doc.InsertTable(table);
doc.Save();
}
}
}
DocX seems to be available on NuGet, so I would heavily recommend fetching the dependency from there rather than having it in a file on your local system. (This helps ensuring repeatable builds, should you share this code with others, with packaging your application, and it will also make it easier to upgrade DocX if a new version is released.)
If you're using Visual Studio, you can right-click the project in Solution Explorer and choose "Manage NuGet Packages..." to open a dialog that helps you install the package, or you can open Package Manager Console and enter Install-Package DocX.
If you're building on .NET Core without Visual Studio, just add "DocX": "1.0.0.19" to the dependencies node of your project.json.
When the package is installed, you can just do using DocX; like with any other namespace import.
Have you read this link
To add a reference in Visual C#
In Solution Explorer, right-click the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the components you want to reference, and then click OK.
Without VS:
Go to the csproj file there is a <ItemGroup> where references can be added:
<ItemGroup>
<Content Include="libs\...">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
...
There you can add libs.
both required in order to use docx.
//css_reference DocX.dll;
using Novacode;
You can also give reference to any place like
//css_reference D:\lib\DocX.dll;
using Novacode;