Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NHibernate 5 with Asp NET Core 2: Getting an exception when calling OpenSession #1577

Closed
jgonte opened this issue Feb 16, 2018 · 7 comments
Closed

Comments

@jgonte
Copy link

jgonte commented Feb 16, 2018

Exception:
System.TypeLoadException: 'Could not load type 'System.Runtime.Remoting.Messaging.CallContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.'

Code:

public void ConfigureServices(IServiceCollection services)
{
    var mapper = new ModelMapper();

    mapper.AddMapping<SchoolMapping>();

    var mapping = mapper.CompileMappingFor(new Type[] 
    {
        typeof(School)
    });

    services.AddSingleton<ISessionFactory>(options => 
    {
        var configuration = new Configuration().DataBaseIntegration(db => 
        {
            db.ConnectionString = Configuration.GetConnectionString("DefaultConnection");

            db.Driver<SqlClientDriver>();

            db.Dialect<MsSql2012Dialect>();
        });

        configuration.AddDeserializedMapping(mapping, "Test");

        return configuration.BuildSessionFactory();
    });

    services.AddScoped(factory => factory
        .GetServices<ISessionFactory>()
        .Single()
        .OpenSession()); // <-- Here is where the exception happens

... Rest of code omitted for brevity

@fredericDelaporte
Copy link
Member

NHibernate does not support .Net Core yet.

@mazharqayyum
Copy link
Contributor

@fredericDelaporte can you please point to feature request to support .net core if there is any?

@fredericDelaporte
Copy link
Member

fredericDelaporte commented Feb 16, 2018

See #1572 where I have already writen an abstract of current state of works on .Net Core.

@jgonte
Copy link
Author

jgonte commented Feb 18, 2018

Since the issue I had was with the CallContext. I did some research and Remoting is not supported in NET Core
But looking at the code of NHibernate-Core I noticed they added
#if NETSTANDARD2_0 || NETCOREAPP2_0

So it looks that they are already supporting NET Core 2?

@fredericDelaporte
Copy link
Member

No. There are just some places where code for supporting it has already been merged, but the master branch is far from supporting it.

@jgonte
Copy link
Author

jgonte commented Feb 19, 2018

I have been experimenting with porting NHibernate to NET Core 2 and at least I got it to compile.
Of course it is not production ready :-)
I will continue playing with that

In case that can be of any help to somebody:
https://github.com/jgonte/nhibernate-netcore

@mazharqayyum
Copy link
Contributor

@fredericDelaporte Thanks for the insights! A move to .net core is something many people will be looking forward too. I hope that nhibernate will consider it in near future :)

@nhibernate nhibernate locked as off-topic and limited conversation to collaborators Feb 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants