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
Related
I am trying to implement Serilog for my Blazorserver project.
First and foremost, i follow the instructions as described in the link https://www.c-sharpcorner.com/article/log-data-into-file-using-serilog-framework-in-blazor-server-app/.
In this instruction the following lines appear in the second code block:
Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
Where the line .Useserilog() is newly added. The precompiler now throws the following error message:
"IHostBuilder does not contain a definition for 'UseSerilog'
I have added using Serilog and
using Serilog.Events in the Program.cs file (all "usings" are listed here):
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Serilog.Events;
Does anyone have any idea what could be causing the problem? Thanks!
UseSerilog is an extension method in the Serilog.Extensions.Hosting namespace so you will need to import that:
using Serilog.Extensions.Hosting;
You may also need to add the Serilog.Extensions.Hosting Nuget package.
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'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.
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.
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).