In my Main method of .net Core app Iam getting this error and I dunno where should I look for solution.
this is my main method:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
This is error message I am getting when hit F5 to fire project:
System.MissingMethodException: 'Method not found: 'System.IServiceProvider Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.'
I've just come across this issue using aspnet core 2.0, in my case upgrading the other default packages (AspNetCore, AspNetCore.Mvc, NetCore.App) to 2.0 did the trick, despite installing 2.0 the packages (apart from App insights) were 1.1.x initially
If you use Microsoft.AspNet.OData, this error occurs from NuGet version 7.5.15 and above. Downgrading to 7.5.14 may resolve this issue.
For .NET Core 3.1, for some reason Visual Studio wasn't giving me the hint that I need to add using Microsoft.Extensions.DependencyInjection;. Manually adding that fixed it for me.
Downgrade package ApplicationInsights to version 1.1.2 from 2.0 solved
I had similar issue when using Sql nuget and upgrading that fixed the issue.
IDbContextFactory had to be changed to IDesignTimeDbContextFactory
I also experienced this error with Microsoft.AspNet.OData version 7.5.17 and downgrading to 7.5.14 resolved this error.
Related
I am getting error on debug session start on my dot net core API project; since I updated visual studio to latest version 17.1.1. Following is the exception detail, it is showing on console. I tried by deleting temp, bin, obj folders but nothing worked. Has somebody faced such an issue or know how to fix?
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'ConfigurationManager'.
at Microsoft.Extensions.Configuration.ReferenceCountedProviderManager.AddProvider(IConfigurationProvider provider)
at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(IConfigurationSource source)
at Microsoft.Extensions.Configuration.ConfigurationManager.Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(IConfigurationSource source)
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.<>c__DisplayClass25_0.b__2(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at Program.$(String[] args) in Program.cs:line 40
It is because you use the old way of getting the settings from the configuration manager, like:
using (var serviceProvider = services.BuildServiceProvider())
{
...
}
If you remove these lines and just use the configuration as-is with
options = configuration.GetOptions<Object>("xxx");
it will work
we also had this issue since march 8.
is was introduced with the release of 6.0.3, see a github post about the issue : https://github.com/dotnet/aspnetcore/issues/40614
for now what we did is revert to the 6.0.2 version (this is a temporary work around, i will hope to figure out what was wrong asap)
for docker images:
FROM mcr.microsoft.com/dotnet/aspnet:6.0.2 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0.200 AS build
WORKDIR /src
if you are using it in yml also probably
use dotnetversion
DotNetVersion: "6.0.200" instead of "6.0.x"
6.0.200 is the sdk version of 6.0.2 framework https://dotnet.microsoft.com/en-us/download/dotnet/6.0
11/03/2022
see also this https://github.com/dotnet/core/issues/7259 were i have pinpointed the issue in our code and added a sample app to reproduce
if we look into that repo https://github.com/microsoft/ApplicationInsights-Kubernetes/blob/69f44c6ec3fda26d76a01836b851402e3f8a02ad/src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs
we indeed find the same piece of code on the other answers
i faced to this problem when i update my SDK both in docker and my window 11
my sdk is : 6.0.3
but i cant understand why this problem is happend
When I try to deploy my project it fails with the following message:-
Startup.cs(75,25): error CS1061: 'IMvcBuilder' does not contain a definition for 'AddRazorRuntimeCompilation'
and no accessible extension method 'AddRazorRuntimeCompilation' accepting a first argument of type 'IMvcBuilder'
could be found (are you missing a using directive or an assembly reference?)
I found an answer here How to fix 'IMvcBuilder' doesn't contain a definition for 'AddXmlDataContractSerializerFormatters' however after installing the suggested MVC formatter package(s) The issue persisted.
The only way I have been able to deploy is to comment out the following lines in my startup class
var builder = services.AddRazorPages();
if (Env.IsDevelopment())
{
builder.AddRazorRuntimeCompilation();
}
Maybe I need to update something on the deployment server? It is the organisation's first DotNet Core 3.1 application
You need to install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation, but not the latest version. Something compatible with .Net Core 3.x.
E.g.
Package Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 3.1.19
I am following a tutorial to become familiar with server side rendering involving asp.net core and react, but I am hitting a roadblock on the HelloWorld. I am doing this alongside another co-worker and he is not getting this same issue. I have uninstalled and reinstalled all dependencies with npm to make sure there were no installation issues.
I have tried to find some answer as to what I am missing, an import etc, but cannot seem to find anyone with the same exact issue. I had looked at similar IApplicationBuilder exceptions but the solutions they usually have is try this import statement etc etc. I have uninstalled and reinstalled all my dependencies with npm. I have recreated the project three times
Below is the Configure method from my Startup.cs file.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware();
} else {
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
}
app.UseWebpackDevMiddleware(); is throwing the following error:
"Severity Code Description Project File Line Suppression State
Error CS1061 'IApplicationBuilder' does not contain a definition for 'UseWebpackDevMiddleware' and no accessible extension method 'UseWebpackDevMiddleware' accepting a first argument of type 'IApplicationBuilder' could be found"
In Package Manager run Install-Package Microsoft.AspNetCore.SpaServices.Extensions
I am trying to implement external authentication in my Web-api project by following this link https://www.youtube.com/watch?v=WsRyvWvo4EI&t=609s
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() {
ClientId = "",
ClientSecret=""
});
The code above could not find GoogleOAuth2AuthenticationOptions class.. searching through the problem it appears that my microsoft.owin.security.google package is not updated. When i try to update it using NuGet, it fails to download the package showing the following error:
NuGet Error while downloading the Microsoft.Owin.Security.Goolge 4.0.0
How do i update the package and make the google authentication work
You need to upgrade your project Target Framework to at least .Net Framework 4.5.1
The following code:
Database.SetInitializer
(new MigrateDatabaseToLatestVersion<Db, Migrations.Configuration>(true));
using (var C = new Db())
{
Console.WriteLine(C.Usuarios.Count());
}
Works on a console test project but on the other console with self-hosting it fails with the Unable to update database to match the current model... migration error
Obviously the migrations are up to date since the other project runs fine and they both do the same configuration since the database model and the migration configuration are on a separated library
I tracked down the problem to the Newtonsoft.Json library.
The package Microsoft.AspNet.WebApi.Client depends on the version 6.0.4 of this library which seems to have conflicts with Entity Framework.
Just upgrading the Newtonsoft.Json with Install-Package Newtonsoft.Json solves the problem