I'm trying to compile a project I've written in C# script, in the azure portal(can't get any other environment to work).
I'm trying to reference the cosmos table API within my function:
#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"
#r "Microsoft.Azure.WebJobs"
#r "Microsoft.Azure.WebJobs.Extensions"
#r "Microsoft.Azure.WebJobs.Extensions.Storage"
#r "Microsoft.Azure.Cosmos.Table"
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host.Bindings.Runtime;
using Microsoft.Azure.Cosmos.Table;
But it gives me the following error:
[Error] run.csx(6,1): error CS0006: Metadata file 'Microsoft.Azure.Cosmos.Table' could not be found
2019-09-26T13:50:37.115 [Error] run.csx(14,23): error CS0234: The type or namespace name 'Cosmos' does not exist in the namespace 'Microsoft.Azure' (are you missing an assembly reference?)
How can I make azure function find the reference?
This namespace is not included in Azure function. You need to add the dll file to Azure function app by yourself. Refer to this article for the detailed steps.
Related
I am trying to implement single sign on using OIDC as per GitHub but I keep getting the error:
'WebHostBuilder' does not contain a definition for 'UseKestrel' and no accessible extension method 'UseKestrel' accepting a first argument of type 'WebHostBuilder' could be found (are you missing a using directive or an assembly reference?)
when implementing the SystemBrowser.cs code
using IdentityModel.OidcClient.Browser;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//other code
//simplified code extract below
IWebHost _host = new WebHostBuilder()
.UseKestrel()
.UseUrls(_url)
.Configure(Configure)
.Build();
//other code
According to this it should be part of the Microsoft.AspNetCore.Hosting?
Is there something I'm missing or a NuGet package I need installing? The packages installed so far are:
Any assistance would be appreciated.
The default asp.net core application could work well because the Microsoft.AspNetCore.Hosting package and other related package integrated in the framework.
I test a console application with asp.net core and reproduce your issue.Install the Microsoft.AspNetCore.Hosting together with Microsoft.AspNetCore.Server.Kestrel.
You could download on NuGet Package Manager by searching for the package name or download on Package Manager Console by using the command in the following reference:
https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/2.2.0?_src=template
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 am trying to download a file from google drive using C# .net. I am using the example code from https://developers.google.com/drive/web/manage-downloads
The code does not compile and giving definition error for IAuthenticator
error CS0234: The type or namespace name 'Authentication' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'IAuthenticator' could not be found (are you missing a using directive or an assembly reference?)
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Authentication;
public static System.IO.Stream DownloadFile(
IAuthenticator authenticator, File file) {
I also tried
service.Files.Get(fileId).Download(myFileStream);
However this is giving error on "file already used by process"
Has anyone successfully used the C# example to download file?
PS: I have installed required nuget pacakages
PM> install-package Google.Apis.Auth
Attempting to resolve dependency 'Google.Apis.Core (≥ 1.9.0)'.
Attempting to resolve dependency 'Microsoft.Bcl (≥ 1.1.9)'.
Attempting to resolve dependency 'Microsoft.Bcl.Build (≥ 1.0.14)'.
Attempting to resolve dependency 'Microsoft.Bcl.Async (≥ 1.0.168)'.
Attempting to resolve dependency 'Microsoft.Net.Http (≥ 2.2.22)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Google.Apis.Auth 1.9.0' already installed.
GoogleDrive already has a reference to 'Google.Apis.Auth 1.9.0'.
IAuthenticator authenticator Used For SDK.There is not much detail on IAuthenticator in google Api But You can Use for API
fileID="asd383d8ied2edj82dnc0v";
Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Execute();
return service.HttpClient.GetStreamAsync(file.DownloadUrl).Result;
When i try to build and run my project i get the following build errors:
HourScreen.cs(13,13): Error CS0433: The imported type `System.Net.WebRequest' is defined multiple times (CS0433)
HourScreen.cs(17,17): Error CS0433: The imported type `System.Net.WebResponse' is defined multiple times (CS0433)
The lines on which the errors happen look like this:
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
I include the following into the project:
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Preferences;
using Android.Graphics;
I think one of the includes must be playing up but i have no idea which. Removing one causes a huge load of other errors. Can anyone see where im going wrong?
EDIT:
I've included the build log: http://pastebin.com/FrmzfhcY
HourScreen.cs(167,17): error CS0433: The imported type `System.Net.WebResponse' is defined multiple times
/Developer/MonoAndroid/usr/lib/mono/2.1/System.dll (Location of the symbol related to previous error)
/Mono for Android/Bups_Urenverantwoording 1.0/Bups_Urenverantwoording/bin/Debug/System.Net.dll (Location of the symbol related to previous error)
The log has your answer. Mono for Android provides it's own System.Net stack in System.dll but you're also including other assemblies, like System.Net.dll which includes the same type.
Since you also reference System.Windows.dll I assume you're trying to include some code from Silverlight (or Moonlight) and that won't work. At least not for for System.Net.dll (not sure what you're trying to use from System.Windows.dll).