I have this code:
using System;
using System.IO;
using RestSharp;
using RestSharp.Authenticators;
namespace MyProgram
{
class Program
{
static void Main(string[] args)
{
var client = new RestClient
{
BaseUrl = new Uri("www.newuri.com"),
Authenticator = new HttpBasicAuthenticator(username: "myusername", password: "mypassword")
};
var request = new RestRequest(Method.POST);
var response = client.Execute(request);
}
}
}
I'm coding using VS2017 and this program compiles perfectly on it. The problem is that I want to compile and run it via Command Prompt and when I try to run command:
csc Program.cs
I'm getting error:
Program.cs(3,7): error CS0246: The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?)
Program.cs(4,7): error CS0246: The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?)
Am I missing something when compiling via CMD?
If you compile with csc, you will need to manually specify the paths to all your references.
Few people compile by manually invoking csc. Instead, they use build software which understands the csproj file format and runs csc for them.
Can you try running msbuild or dotnet build? That will respect all your references you've added in Visual Studio.
Related
I inherited a bit of code:
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
I think is stems from a .net Core application. First I struggled with this bit (in the sense that I could not compile it in .Net Framework):
.SetBasePath(Directory.GetCurrentDirectory())
But I came across this. The accepted answer solved it. Now I am struggling with this bit (again in the sense that I cannot compile it in .Net Framework)::
.AddJsonFile("appsettings.json")
Is there a way to fix this please (usually I would get such data from App.Config ...)? Thanks.
PS:
More code plus error message:
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration.FileExtensions;
using Microsoft.Extensions.Configuration;
namespace SandboxSecurityToken
{
class Program
{
static void Main(string[] args)
{
...
static async Task RunAsync()
{
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
Severity Code Description Project File Line Suppression State
Error CS1061 'IConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no accessible extension method 'AddJsonFile' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)
This is .NET Standard code that should work just fine on .NET Framework 4.6.1 or higher.
You don't provide enough information, but I would guess you are missing reference to this NuGet package : https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/2.2.0
Or you might be missing proper using:
using Microsoft.Extensions.Configuration;
So that AddJsonFile extension method is found.
I have the following error:
Program.cs(15,72): error CS1061: 'ConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no accessible extension method 'AddJsonFile' accepting a first argument of type 'ConfigurationBuilder' could be found (are you missing a using directive or an assembly
The project is a dotnet core app, console application, using Azure Search SDK
The line of error is below:
using System;
using System.Linq;
using System.Threading;
using Microsoft.Azure.Search;
using Microsoft.Azure.Search.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Spatial;
namespace DemoSearchIndexer
{
class Program
{
static void Main(string[] args)
{
IConfigurationBuilder builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
IConfigurationRoot configuration = builder.Build();
...
The AddJsonFile extension method is available in NuGet:
Microsoft.Extensions.Configuration.Json
When building an ASP.NET Core application, which usually references Microsoft.AspNetCore.App (or, historically, Microsoft.AspNetCore.All), you get this "for free".
When building a console application, or something that doesn't reference the metapackages, you need an explicit reference to Microsoft.Extensions.Configuration.Json.
You also have to set appsettings file properties to "copy always".
See this for more infos.
I have created a Azure Function and it has below code in `run.csx'
using System;
using System.Runtime.Serialization;
using System.ServiceModel.Description;
using MongoDB.Bson.IO;
using MongoDB.Bson;
using MongoDB;
using MongoDB.Driver;
using System.Security.Authentication;
using System.Text;
using Newtonsoft.Json;
public static void Run(string myIoTHubMessage, ILogger log)
{
log.LogInformation($"C# IoT Hub trigger function processed a message: {myIoTHubMessage}");
}
I am having Project.json as follow
{
"frameworks": {
"net46":{
"dependencies": {
"Newtonsoft.Json": "10.0.3",
"System.ServiceModel.Primitives":"4.4.0",
"MongoDB.Bson": "2.4.0",
"MongoDB.Driver": "2.4.0",
"MongoDB.Driver.Core": "2.4.0"
}
}
}
}
I am getting below error while running the azure function
2019-01-11T10:01:14.846 [Error] run.csx(5,27): error CS0234: The type or namespace name 'Description' does not exist in the namespace 'System.ServiceModel' (are you missing an assembly reference?)
2019-01-11T10:01:15.108 [Error] run.csx(6,7): error CS0246: The type or namespace name 'MongoDB' could not be found (are you missing a using directive or an assembly reference?)
I even tried adding namespace like below but no luck
#r "Newtonsoft.Json"
#r "System.Xml"
#r "System.Xml.Linq"
#r "MongoDB"
It's probably caused by the difference of Function runtime.
project.json is used for functions on ~1 runtime where code targets at .NET Framework, while the function you create is on ~2 runtime which runs on .NET Core env. When we create a new Function app its runtime is set to ~2 by default now.
So the solution is simple, delete existing functions in the Function app and change Function runtime version to ~1(Find it in portal, Platform features>Function app settings). Then you could recreate an IoT Hub (Event Hub) trigger with steps above, things should work this time.
To work with Function 2.0, use function.proj to install packages.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="<packageName>" Version="<version>"/>
</ItemGroup>
</Project>
I tried to understand this tutorial: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
I can generate the proxy without any problems. Just as it is described.
But at chapter "Consume the OData service" it doesn't work. I have named the application and the proxy exactly as shown in the tutorial. How can I make odata available in namespace Microsoft?
Screenshot
Error CS0234 The type or namespace name 'OData' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 6 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
Error CS0246 The type or namespace name 'DefaultContainer' could not be found (are you missing a using directive or an assembly reference?) TrippinApp C:\TrippinApp\Program.cs 16 Active
I used:
Microsoft Visual Studio 2017 (Trial)
Microsoft.Data.Edm v5.8.3
Microsoft.Data.Odata v5.8.3
Microsoft.Data.Services.Client v5.8.3
System.Spatial v.5.8.3
WCF Data Services 5.6 Tools (are installed)
continuation:
#Evandro Paula:Thank you for your help! I have come a little further thanks to your help. But unfortunately I have not come to the goal yet.
I installed/updated:
Microsoft Visual Studio 2017 (15.7.1) (Trial)
Microsoft.Data.Edm v5.8.3 (I have not found a more recent one)
Microsoft.Data.Odata v5.8.3 (I have not found a more recent one)
Microsoft.Data.Services.Client v5.8.3 (I have not found a more recent one)
Microsoft.OData.Client v7.4.4 (installed)
Microsoft.OData.Core v7.4.4 (installed)
Microsoft.OData.Edm v7.4.4 (installed)
Microsoft.Spatial v7.4.4 (installed)
System.Spatial v.5.8.3 (I have not found a more recent one)
WCF Data Services 5.6 Tools (are installed)
Screenshot of NuGet
Now the results look like this:
Compiling works with Proxy (TrippinProxy.cs), but without Odata example. (Screenshot)
As soon as I copy the code from the tutorial, compiling does't work anymore. (Screenshot)
using System;
using Microsoft.OData.SampleService.Models.TripPin;
namespace TrippinApp
{
class Program
{
static void Main(string[] args)
{
DefaultContainer dsc = new DefaultContainer(
new Uri("http://services.odata.org/V4/(S(fgov00tcpdbmkztpexfg24id))/TrippinServiceRW/"));
var me = dsc.Me.GetValue();
Console.WriteLine(me.UserName);
}
}
}
source: http://odata.github.io/odata.net/#OData-Client-Code-Generation-Tool
Now the Namespace Microsoft.OData is found. But not Microsoft.OData.SampleService (Screenshot)
I need a little example. How can I initialize the proxy and add a product (CreateProduct)? Or how can I get the example from the tutorial up and running?
First, update the packages you mentioned on your question to their latest version. It looks like Visual Studio didn't use the latest version in your case. I'm using Visual Studio 2017 Enterprise Edition (version 15.7.3) for this test.
Microsoft.OData.Client (version 7.4.4)
Microsoft.OData.Core (version 7.4.4)
Microsoft.OData.Edm (version 7.4.4)
Microsoft.Spatial (version 7.4.4)
Once the packages are up to date, you will observe the following build error, which is related to issue https://github.com/OData/lab/issues/80:
Severity Code Description Project File Line Suppression State
Error CS0234 The type or namespace name 'EdmxReader' does not exist in the namespace 'Microsoft.OData.Edm.Csdl' (are you missing an assembly reference?) ODataClient C:\temp\NET\ODataClient\Connected Services\TrippingService\TrippingProxy.cs 510 Active
The resolution for this issue is available at https://github.com/juliopinto15/lab/commit/deb1254301a775eb6771b0bed672dd3f56f37cfe.
Just change the proxy (e.g. TrippingProxy.cs) generated code line below as part of method LoadModelFromString():
return global::Microsoft.OData.Edm.Csdl.EdmxReader.Parse(reader);
to
return global::Microsoft.OData.Edm.Csdl.CsdlReader.Parse(reader);
In my case, I deleted the NuGet cache folder, and it compiles now.
%LOCALAPPDATA%\Nuget\v3-cache
I worked with the same example (TripPinService) and got the same error. It looks like there is an error in the sample.
Instead of:
var context = new DefaultContainer(new Uri(serviceRoot));
You need to write:
var context = new Default.Container(new Uri(serviceRoot));
After that code runs without errors
I'm following tutorial, installed RanvenDB embeeded and write:
public static IDocumentStore archives =
new EmbeddableDocumentStore { DataDirectory = "~/DataStore" };
then I let VS to find where is EmbeddableDocumentStore so and I add:
using Raven.Client.Embedded;
No errors yet and everything looks fine. Then I build:
Archives.cs(10,20): error CS0234: The type or namespace name
'Embedded' does not exist in the namespace 'Raven.Client' (are you
missing an assembly reference?)
Compile complete -- 1 errors, 0 warnings
And now it's error and there is no Embedded...
If I remove package.config and run install Ravendb Embedded again it will become green (with no errors) again but just after I run build...
How to repair it?
(tested different version : same result)
Make sure that you are building for the FULL .NET framework, and not just the client profile.