ASP.NET API failing to publish on azure - c#

I'm trying to publish an C# API to azure, I followed all the steps in this documentation here but for some reason when I publish the application the build succeeds and crashes when this below line gets executed
Generating swagger file to 'C:\Users\user\Projs\API\bin\Release\netcoreapp3.1\swagger.json'.
and the only error log that gets printed is
Failed to generate swagger file. Error dotnet swagger tofile --serializeasv2 --output "C:\Users\user\Downloads\Projs\API\bin\Release\netcoreapp3.1\swagger.json" "C:\Users\user\Downloads\Projs\API\bin\Release\netcoreapp3.1\API.dll" v1
Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Be sure that the Startup.cs for your application is calling AddSwaggerGen from within ConfigureServices in order to generate swagger file. Visit https://go.microsoft.com/fwlink/?LinkId=2131205&CLCID=0x409 for more information.
This is my startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(
"v1",
new Microsoft.OpenApi.Models.OpenApiInfo { Title = "My API", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseSwagger(c =>
{
c.SerializeAsV2 = true;
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("v1/swagger.json", "MyAPI V1");
});
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
This is my .csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
<UserSecretsId>d844b2a8-00b0-473d-8f97-9dca9f2899bd</UserSecretsId>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Folder Include="Model\" />
<Folder Include="Context\" />
<Folder Include="Contracts\ServiceResponse\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.SignalR" Version="2.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.13" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
</ItemGroup>
</Project>
I have tried solutions from these links but none of them worked
Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies
https://github.com/Azure/azure-functions-vs-build-sdk/issues/160
Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Is there a way to fix this?
Update:
I tried a solution that was told by a user in the thread to add binding redirects, I added a web.config and a app.config and added the bindinds but it still fails to publish
Update 2:
I couldn't find a solution so I installed .net 5.0 and it worked

You can use the latest version of Swashbuckle.AspNetCore. I found the official workaround here from Swashbuckle on GitHub:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2006
Add a global.json file to your Web API project
Put this in it:
{
"sdk": {
"version": "3.1.406",
"rollForward": "latestPatch"
}
}

Related

Azure API deployment issue - Swashbuckle SwaggenGen Error

I've got a problem when trying to deploy my App Service to Azure from VS 2022. Each time I'm getting this error:
I'm using .NET 6 as my target framework and I've got the Swashbuckle.AspNetCore package updated to the newest version. The app service is published with success, but the error pops up when trying to update the API.
In my version of the project there is no Startup.cs but Program.cs, and the way I'm implementing the Swagger generation is:
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
I've browsed through similar posts and based on them I can add that I am not fetching any environment variables too.
I've also tried using UseSwaggerUI() like this but I get the same error anyway:
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
Weird thing is that the deployment works for my colleague and it worked for me until last week when it stopped when nothing in the Program.cs was changed on the way.
My Program.cs:
var builder = WebApplication.CreateBuilder(args);
var azureKeyVaultUrl = builder.Configuration[AppConfigurationConst.AzureKeyVaultUrl];
var logAnalyticsWorkspaceId = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.LogAnalyticsWorkspaceId);
var logAnaliticsAuthenticationId = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.LogAnaliticsAuthenticationId);
var CrmConnectionString = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.OneCrmConnectionString);
var logger = new LoggerConfiguration()
.WriteTo.AzureAnalytics(logAnalyticsWorkspaceId, logAnaliticsAuthenticationId)
.Enrich.FromLogContext()
.CreateLogger();
var serviceClient = new ServiceClient(CrmConnectionString);
builder.Logging.AddSerilog(logger);
logger.Information("Start ALGOI App Service");
builder.Services.AddControllers().AddNewtonsoftJson();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IAuthenticationService, AuthenticationService>();
builder.Services.AddSingleton<IWebClientService, WebClientService>();
builder.Services.AddScoped<ICreateSessionService, CreateSessionService>();
builder.Services.AddScoped<ICreateFolderService, CreateFolderService>();
builder.Services.AddScoped<IDeleteFolderService, DeleteFolderService>();
builder.Services.AddScoped<IVerifyFolderService, VerifyFolderService>();
builder.Services.AddScoped<IUndoFolderService, UndoFolderService>();
builder.Services.AddSingleton(serviceClient);
builder.Services.AddApplicationInsightsTelemetry(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]);
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
And my .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>{usersecretsid}</UserSecretsId>
<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Connected Services\**" />
<Content Remove="Connected Services\**" />
<EmbeddedResource Remove="Connected Services\**" />
<None Remove="Connected Services\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="JsonSubTypes" Version="1.9.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Graph" Version="4.34.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.48.1" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.16.0" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.16.0" />
<PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.0.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Polly" Version="7.2.3" />
<PackageReference Include="RestSharp" Version="106.13.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.AzureAnalytics" Version="4.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="TypeSafe.Http.Net.HttpClient" Version="2.2.16" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="someprojectpath" />
<ProjectReference Include="someprojectpath" />
<ProjectReference Include="someprojectpath" />
</ItemGroup>
<ItemGroup>
<Content Update="local.settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
appsettings.json:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "domain",
"TenantId": "tenantid",
"ClientId": "clientid",
"Scopes": "access_as_user",
"CallbackPath": "/signin-oidc",
"ClientSecret": "Client secret from app-registration. Check user secrets/azure portal.",
"ClientCertificates": []
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AzureKeyVaultUrl": "keyvaulturl",
"AllowedHosts": "*",
"MicrosoftGraph": {
"BaseUrl": "https://graph.microsoft.com/v1.0",
"Scopes": "user.read"
},
"ApplicationInsights": {
"ConnectionString": "appinsightsconnectionstring"
}
}
EDIT:
I've found out that the cause of the error are those lines:
var azureKeyVaultUrl = builder.Configuration[AppConfigurationConst.AzureKeyVaultUrl];
var logAnalyticsWorkspaceId = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.LogAnalyticsWorkspaceId);
var logAnaliticsAuthenticationId = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.LogAnaliticsAuthenticationId);
var CrmConnectionString = AzureKeyVaultHelper.GetAzureKeyVault(azureKeyVaultUrl, AppConfigurationConst.OneCrmConnectionString);
I've since changed them to get values directly from configuration instead of keyvault:
var azureKeyVaultUrl = builder.Configuration.GetValue<string>(AppConfigurationConst.AzureKeyVaultUrl);
var logAnalyticsWorkspaceId = builder.Configuration.GetValue<string>(AppConfigurationConst.LogAnalyticsWorkspaceId);
var logAnaliticsAuthenticationId = builder.Configuration.GetValue<string>(AppConfigurationConst.LogAnaliticsAuthenticationId);
var CrmConnectionString = builder.Configuration.GetValue<string>(AppConfigurationConst.OneCrmConnectionString);
When running locally, it takes the values correctly and assignes them to the variables. But it seems that when deploying it encounters a problem with that. In line var serviceClient = new ServiceClient(CrmConnectionString); when I change the variable to static string it works correctly, but when using the variable the startup.cs error pops up (only when deploying). Same thing with initializing logger which uses the log analitycs values. Again, locally runs with no problems, only the deployment crashes.
I have created a sample ASP.NET Core 6.0 Web API and able to deploy the Application to Azure App Service without any errors.
Generally, this type of error occurs when there is any error in the code or Configuration issues.
In my version of the project there is no Startup.cs but Program.cs
.Net6 Core Folder Structure:
Yes, we need to Configure the code related to Swagger in Program.cs itself.
Check the below steps and make sure you are following the same to deploy without any issues.
Select the ASP.NET Core Web API template.
Select Enable openAPI support.
My .csproj file :
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
My Program.cs file :
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
Output of Deployed Azure App Service:

Azure Functions Swashbuckle: Failed to resolve assembly 'Microsoft.AspNetCore.Mvc.Core' during rebuild

I want to add OpenAPI specification to my Azure Functions app. For that I wanted to use AzureExtensions.Swashbuckle since it can auto generate the specification and display it via swagger-ui.
When I first install the package via nuget everything works fine. The specification is generated automatically, and I can view it through the swagger-ui.
As soon as I rebuild my project / solution, it doesn't build anymore. The following error message is prompted during the build:
3>C:\Users\Agent1\.nuget\packages\microsoft.net.sdk.functions\3.0.13\build\Microsoft.NET.Sdk.Functions.Build.targets(32,5): Error : Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.AspNetCore.Mvc.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type)
at Mono.Cecil.TypeReference.Resolve()
at MakeFunctionJson.AttributeExtensions.IsWebJobsAttribute(CustomAttribute attribute)
at MakeFunctionJson.ParameterInfoExtensions.<>c.<ToFunctionJsonBindings>b__1_0(CustomAttribute a)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MakeFunctionJson.ParameterInfoExtensions.ToFunctionJsonBindings(ParameterDefinition parameterInfo)
at MakeFunctionJson.MethodInfoExtensions.<>c.<ToFunctionJson>b__6_1(ParameterDefinition p)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at MakeFunctionJson.MethodInfoExtensions.ToFunctionJson(MethodDefinition method, String assemblyPath)
at MakeFunctionJson.FunctionJsonConverter.GenerateFunctions(IEnumerable`1 types)+MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Error generating functions metadata
I'm using AzureFunctions V3 with .NET Core 3.1.
This is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<OutputPath>../../dist/apps/api</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AzureExtensions.Swashbuckle" Version="3.3.2" />
<PackageReference Include="CSharpFunctionalExtensions" Version="2.18.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.0.0-beta.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.17" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />
<PackageReference Include="Scriban" Version="4.0.1" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Security" Version="4.8.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I already deleted my local .nuget directory, cleaned nuget cache and updated other packages but no luck.
If you added [FromQuery] or any other attribute to your azure function "controller signature" it could happened.
You can try to remove the [FromQuery] attribute.
You can refer this on-going github issue about the same problem.

An error occurred while accessing the Microsoft.Extensions.Hosting services when adding or updating migration

I have downloaded one of my old projects and when I tried to run the Update-Database from the Package Manager Console I get the following message
Build started... Build succeeded. An error occurred while accessing
the Microsoft.Extensions.Hosting services. Continuing without the
application service provider. Error: Value cannot be null. (Parameter
's') No DbContext was found in assembly 'BusinessLogicLayer'. Ensure
that you're using the correct assembly and that the type is neither
abstract nor generic.
The difference between now and when I have used the application last time is that I have reset windows, and reinstalled all the programs back.
The application runs normally and I managed to add the migrations using
CreateHostBuilder(args)
.Build()
.MigrateDatabase<DataContext>()
.Run();
and all tables have been created and populated with the seed data.
The last time I have been working on this project everything was working just fine.
This is how I connect to the DB
services.AddDbContext<DataContext>(optionsBuilder =>
optionsBuilder.UseNpgsql("User ID=postgres;Password=my_actual_pass;Server=localhost;Port=5432;Database=medication_platform3;Integrated Security=true;Pooling=true;"));
Constructor for DataContext
public DataContext(DbContextOptions<DataContext> options)
: base(options) { }
DataAccessLayer
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Migrations\**" />
<EmbeddedResource Remove="Migrations\**" />
<None Remove="Migrations\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="Migrations\20201207230245_InitialMigration.cs" />
<Compile Include="Migrations\20201207230245_InitialMigration.Designer.cs" />
<Compile Include="Migrations\DataContextModelSnapshot.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessObjectLayer\BusinessObjectLayer.csproj" />
</ItemGroup>
</Project>
appsettings.json
{
"JwtKey": "SOME_RANDOM_KEY_DO_NOT_SHARE",
"JwtIssuer": "http://localhost:5001",
"JwtExpireDays": 1,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
I can provide more information if needed.
After using update-database -verbose
I was able to track the line with the problem.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
int port = int.Parse(Environment.GetEnvironmentVariable("PORT"));
....
}
This was a configuration made for the deployment and I forgot to change this line to
int port= 5001

.NET Core 2.1.5 HTTP Error 502.5 - Process Failure on Deploy

deploying from VS version on the app service is: 2.1.403
and version on my local is: 2.1.403
here is a copy of the relevent section of the .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<UserSecretsId>952fa24f-1cbc-4017-8cdc-4b99e3671be7</UserSecretsId>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<RuntimeIdentifiers>win10-x64;</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Compile Remove="NewFolder\**" />
<Content Remove="NewFolder\**" />
<EmbeddedResource Remove="NewFolder\**" />
<None Remove="NewFolder\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="24.3.0" />
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="5.1.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
<PackageReference Include="Microsoft.AspNetCore.All"/>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
</ItemGroup>
I've tried:
using a self-contained deployment
specifying the version of the packages to 2.1.5 (though i've read this is not necessary)
my runtime.config in the build artifacts looks good:
{
"runtimeOptions": {
"tfm": "netcoreapp2.1",
"framework": {
"name": "Microsoft.AspNetCore.All",
"version": "2.1.5"
},
"configProperties": {
"System.GC.Server": true
}
}
}
so what am I missing here?
This fixed the issue:
<PackageReference Include="Microsoft.AspNetCore.All Version="2.1.1"/>
Though it could be a red herring as I have no idea why specifying the app version would fix (I thought the point of the shared framework was to dynamically pull in the versions you need.)
Also if it helps anyone: 2.1.5 is the release number and NOT THE VERSION OF THE SDK (it corresponds to 2.1.403)

HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver

I want to create a connection with MySQL server using FluentNHibernate in ASP.NET Core, but I get an exception.
My Fluent configuration:
var config = Fluently.Configure()
.Database(MySQLConfiguration
.Standard
.ConnectionString(cs => cs
.Server(dbServer)
.Database(dbName)
.Username(dbUsername)
.Password(dbPassword)))
.Mappings(x =>x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
.BuildSessionFactory();
Exception:
FluentNHibernate.Cfg.FluentConfigurationException: "An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail."
InnerExceptions:
HibernateException: Could not create the driver from NHibernate.Driver.MySqlDataDriver, NHibernate, Version=5.0.0.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
TargetInvocationException: Exception has been thrown by the target of an invocation.
TypeLoadException: Could not load type 'System.Data.Common.DbProviderFactories' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Project config:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentNHibernate" Version="2.0.3" />
<PackageReference Include="Iesi.Collections" Version="4.0.2" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="MySql.Data" Version="6.10.4" />
<PackageReference Include="MySql.Data.Entity" Version="6.10.4" />
<PackageReference Include="MySql.Web" Version="6.10.4" />
<PackageReference Include="NHibernate" Version="5.0.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
Link to deps.json: http://pastebin.com/pn67pa6y
What should I do?
FluentNHibernate does not support .NET Core (issue), because NHibernate has not (PR).
NHibernate PR is scheduled for v5.1, due by December 15, 2017 at the time of this writing.
mstancombe has a fork for .NET Core, but you have to build it yourself.

Categories

Resources