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.
Related
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.
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"
}
}
I got a pretty simple dot-net-core Project. This includes a little MockServerLibrary based on kestrel, that returns some simple REST-replies in unittests.
The complete setup works fine on dotnetCore2.2. Switching to dotnetCore3.0 produces an error in the startup of the Server:
Output stream: Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Hosting.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Das System kann die angegebene Datei nicht finden.
File name: 'Microsoft.Extensions.Hosting.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at ServerMock.RestMockStarter.RunServer(String[] args)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
but only, if this is done by the [OneTimeSetup] of the unit-test project. When I start the MockServer's main-Method stand alone, the server starts fine.
My Assumption is, that the Server-Start fails, because the ServerMock is a
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8</LangVersion>
</PropertyGroup>
(...)
but the unitTestProject is
<Project Sdk="Microsoft.NET.Sdk">
(...)
<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>
(...)
This seems not to a problem in 2.2, because we needed a explicit reference to the packages in the ServerMock
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="2.2.0" />
</ItemGroup>
As far as I understand, these refereces aren't needed anymore (far more: the need to be removed with 3.0), but it seems that they can't be loaded automatically, when started from my unit tests.
Maybe the error is already, that the ServerMock is directy referenced by the unitTest-Project:
<ItemGroup>
<ProjectReference Include="..\ServerMock\ServerMock.csproj" />
and the ServerStart is pretty hard-wired in the [OneTimeSetup]:
await RestMockStarter.RunServer(null);
I already tried to change the type of the unitTest-Project to Microsoft.NET.Sdk.Web, but then it's not longer possile to start/see any unitTests (at least with Rider, so I think this is not the way I should try to fix the problem)
I was able to solve the problem:
(1) Changed the ServerMock-project's csproj-file to
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
From that point I assume it became a "usual" dot-net-core project, and with <FrameworkReference Include="Microsoft.AspNetCore.App" /> the references to the web-extensions are again explicit.
(2) Added
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
to the unit-test's csproj too.
(3) On that point it became al litte frustrating, because the error still occured, but deleting the bin/obj-folder then suddenly helped.
Community,
I'm setting up the dotConnect for MySql Provider from Devart in combination with Entity Framework Extensions from zzzprojects.
Unfortunately the connection is not stable, by using AddDbContextPool.
The connection is stable by using AddDbContext.
I have tried to register the Provider over options.ReplaceService
but don't know which type i have to use.
The reason i have tried to Register the Service explicit is by using 'BulkSaveChangesAsync'. I get the error 'The Provider could not be resolved. You must explicitly set the Provider.'
It would be great if someone has advice for me ?
services.AddDbContextPool<DbContext>(options =>
{ options.UseMySql(Configuration.GetConnectionString("Default"));
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});
Dependencies:
<ItemGroup>
<PackageReference Include="AutoMapper" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="6.0.0" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.3.6" />
<PackageReference Include="AWSSDK.S3" Version="3.3.31.10" />
<PackageReference Include="CsvHelper" Version="12.1.2" />
<PackageReference Include="Devart.Data.MySql.EFCore" Version="8.13.1402" />
<PackageReference Include="Devart.Data.MySql.EFCore.Design" Version="8.13.1402" />
<PackageReference Include="Microsoft.AspNetCore.All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="2.5.1" />
</ItemGroup>
Errors:
1.Unstable Connection:
System.NullReferenceException: Object reference not set to an instance of an object.
at Devart.Data.MySql.MySqlConnection()
at Devart.Data.MySql.MySqlConnection.Open()
Use Entity Framework Extensions
The Provider could not be resolved. You must explicitly set the Provider.
at at Z.BulkOperations.BulkOperation.()
at at Z.BulkOperations.BulkOperation.Execute()
at at Z.BulkOperations.BulkOperation
Disclaimer: I'm the owner of the project Entity Framework Extensions
Devart for MySQL is not yet supported in EF Extensions
That's why you currently get that error. We will look at it on our side to try to support it.
System.NullReferenceException: Object reference not set to an instance of an object.
at Devart.Data.MySql.MySqlConnection()
dotConnect for MySQL v8.13.1422 includes the following fixes:
The bug with incorrect exception message on opening connection, when ConnectionString is not set, by .NET Standard compliant assemblies is fixed
The bug with reopening connections in EF Core 2 is fixed
My computer is (lsb_release -a):
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.4.1708 (Core)
Release: 7.4.1708
Codename: Core
and my dotnet core version (dotnet --version) is:
2.1.105
and my openssl version is:
openssl
OpenSSL> version
OpenSSL 1.1.0h 27 Mar 2018
when I try to load my server I get the following error:
Exception has occurred: CLR/System.DllNotFoundException
Exception thrown: 'System.DllNotFoundException' in Microsoft.AspNetCore.Cryptography.Internal.dll: 'Unable to load DLL 'kernel32.dll': The specified module or one of its dependencies could not be found.
(Exception from HRESULT: 0x8007007E)'
at Microsoft.AspNetCore.Cryptography.SafeHandles.SafeLibraryHandle.UnsafeNativeMethods.LoadLibraryEx(String lpFileName, IntPtr hFile, UInt32 dwFlags)
at Microsoft.AspNetCore.Cryptography.SafeHandles.SafeLibraryHandle.Open(String filename)
My .csproj is:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<NeutralLanguage>pt-BR</NeutralLanguage>
<Authors>Cogtive Team</Authors>
<Company>Cogtive Opex Software</Company>
<Product>Cogtive Core Api V2</Product>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.0\Cogtive.Core.Api.V2.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.ApplicationInsights.HostingStartup" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="2.3.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cogtive.Core.Application\Cogtive.Core.Application.csproj" />
</ItemGroup>
</Project>
rpm -q openssl returns:
openssl-1.0.2k-8.el7.x86_64
rpm -qa | grep openssl returns:
xmlsec1-openssl-1.2.20-7.el7_4.x86_64
openssl-devel-1.0.2k-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
openssl-libs-1.0.2k-8.el7.x86_64
It was working fine until recently but now I can't make it work again.
my computer probably updated a library or something and now it's not working anymore.
any idea?
That OpenSSL version looks very surprsing. Here is what I have on CentOS:
[omajid#localhost ~]$ rpm -q openssl
openssl-1.0.2k-8.el7.x86_64
[omajid#localhost ~]$ openssl
OpenSSL> version
OpenSSL 1.0.2k-fips 26 Jan 2017
Where did you get 1.1? Can you downgrade to 1.0? .NET Core is incompatible with 1.1.x: https://github.com/dotnet/corefx/issues/9855