Giter VIP home page Giter VIP logo

Cannot config correctly with runtime error: System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection cannot be cast, due to assemblies conflict between 'Z.EntityFramework.Classic' and 'EntityFramework.dll'. about entityframework-classic HOT 16 CLOSED

zzzprojects avatar zzzprojects commented on June 1, 2024
Cannot config correctly with runtime error: System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection cannot be cast, due to assemblies conflict between 'Z.EntityFramework.Classic' and 'EntityFramework.dll'.

from entityframework-classic.

Comments (16)

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

We will look at it but I'm afraid that even if we fix it you will still have the issue.

If we fix it for EF Classic, the issue will keep being raise probably for EF6.

I have assigned a developer to check it.

Best Regards,

Jonathan

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

We successfully reproduced the issue.

Obviously, we don't expect both projects are used in the same project.

One problem is that both libraries share the same config section <entityFramework>

One solution on your side is to have different config depending if you use Entity Framework or Entity Framework Classic since library name & version are different.

Perharp a better solution that we tested could be to allow you to customize the config section such as:

EntityFrameworkManager.ConfigSectionName = "entityFrameworkClassic";

and providing a config file like this:

<configuration>
  <configSections>    
    <section name="entityFrameworkClassic" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, Z.EntityFramework.Classic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280" requirePermission="false" />   
  </configSections>
  <entityFrameworkClassic>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,  Z.EntityFramework.Classic">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />
    </providers>
  </entityFrameworkClassic>
</configuration>

It's something that would work for you?

from entityframework-classic.

ClarkHsu avatar ClarkHsu commented on June 1, 2024

Hi Jonathan,
Thanks for your quick response!

I believe letting us to config the section sounds good.

Cheers,
Clark

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Great,

We will release a version supporting it tomorrow night.

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

The v7.0.18 has been released.

You can now specify a section name by using the ConfigSectionName options.

Examples:

Z.EntityFramework.Classic.EntityFrameworkManager.ConfigSectionName = "entityFrameworkClassic";
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="entityFrameworkClassic" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, Z.EntityFramework.Classic, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280" requirePermission="false" />
  </configSections>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,  EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <entityFrameworkClassic>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory,  Z.EntityFramework.Classic">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />
    </providers>
  </entityFrameworkClassic>
</configuration>

Let me know if everything works as expected.

Best Regards,

Jonathan

from entityframework-classic.

ClarkHsu avatar ClarkHsu commented on June 1, 2024

Hi Jonathan,
Thumbs up for your quick action!

Indeed, 7.0.18 has eliminated the exception as title describe, but it still not works by other issues.
Condition1 (exactly using your config), will get

No Entity Framework provider found for the ADO.NET provider with invariant name 'Effort.Provider'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderServicesResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)

since it's finding the provider 'Effort.Provider', I changed the config to
Condition2

<providers>
  <provider invariantName="Effort.Provider" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

changes are only in section, then I got

Unable to cast object of type 'Effort.Provider.EffortConnection' to type 'System.Data.SqlClient.SqlConnection'.
   at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
   at System.Data.Common.DbCommand.set_Connection(DbConnection value)
   at System.Data.Entity.Internal.InterceptableDbCommand.set_DbConnection(DbConnection value)
   at System.Data.Common.DbCommand.set_Connection(DbConnection value)

also an attempt to using
Condition3

<provider invariantName="Effort.Provider" type="System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer" />

but, got

The 'Instance' member of the Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, Z.EntityFramework.Classic.SqlServer, Version=7.0.0.0, Culture=neutral, PublicKeyToken=afc61983f100d280' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
    at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(Type providerType)

test code is :

public void TestMethod1()
{
        EntityFrameworkManager.ConfigSectionName = "entityFramework";
        var dbConnection = DbConnectionFactory.CreateTransient();

        TestContext context = new TestContext(dbConnection);

        var category = context.TestCategories.Add(new TestCategory { Name = "123", Description = "one two three" });
}

internal class TestContext: DbContext
{
        static TestContext()
        {
        }
        public TestContext(DbConnection dbConnection)
                : base(dbConnection, false)
        { }
}

It seems no matter when I touch the EF6 things, issues will be raised by it. Could you evaluate whether it can be fixed - by any other small-scale code changes- at your side?

Cheers,
Clark

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Thank Clark for reporting,

We will look at how to make it work with Effort.

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

Unfortunately, we are not able to reproduce the Condition1.

The Condition2 and Condition3 are expected error since the Effort.Provider is not a SQL Connection.

With Z.EntityFramework.Effort, did you used the following package: https://www.nuget.org/packages/Z.EntityFramework.Classic.Effort/

You cannot use Effort.EF6 with EF Classic since the Effort package has been built with EF and not EF Classic. Perharp that's the issue?

Best Regards,

Jonathan

from entityframework-classic.

ClarkHsu avatar ClarkHsu commented on June 1, 2024

Hi Jonathan,
Could you please try this piece of code?

[TestMethod]
public void TestMethod1()
{
        EntityFrameworkManager.ConfigSectionName = "entityFramework";
        var dbConnection = DbConnectionFactory.CreateTransient();

        TestContext context = new TestContext(dbConnection);
       
        var category = context.TestCategories.Add(new TestCategory { Name = "123", Description = "one two three" }); //Exception thrown here
}

and use System.Data.Entity.DbContex as the base class of context

internal class TestContext:  System.Data.Entity.DbContex
{
        public DbSet<TestCategory> TestCategories { get; set; }
        public TestContext(DbConnection dbConnection)
                : base(dbConnection, false)
        { }
}

public class TestCategory
{
       public short Id { get; set; }
       public string Name { get; set; }
}

Cheers,
Clark

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Still working great,

I will make my developer try it tomorrow and we will provide you with a project if we are still unable to reproduce it.

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

I believe we successfully reproduced the issue.

After digging in some issue on Effort, I found one similar to your: zzzprojects/EntityFramework-Effort#42 (comment)

We are currently looking about how we can make a solution that will not involve code on your side.

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

We didn't success to make it works without additional code but that's certainly something we will continue to dig over next week.

The issue happens normally when an EF Classic context is initialized and the Effort provider has not been yet registered. The provider cannot anymore be registered and that cause the issue.

One way to make it works in unit tests is making sure the Effort.Provider.EffortProviderConfiguration.RegisterProvider(); is the first command called by the assembly. For example, by using the [AssemblyInitialize] attribute.

[AssemblyInitialize]
public static void Initialize(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext)
{
    Effort.Provider.EffortProviderConfiguration.RegisterProvider();
}

Let me know if you succesfully make it work or you need more help.

Best Regards,

Jonathan

from entityframework-classic.

ClarkHsu avatar ClarkHsu commented on June 1, 2024

Hi Jonathan,
Sorry for my late response. But this solution's result is negative. Will still get error of

    at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderServicesResolver.GetService(Type type, Object key)
   at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)

And I am sure Effort.Provider.EffortProviderConfiguration.RegisterProvider(); is called at the very beginning using your hint of [AssemblyInitialize]

Cheers,
Clark

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

Is the issue happen for Entity Framework or Entity Framework Classic? (or maybe both).

For EF Classic, we already coded something that will automatically integrate EF Effort. Only a few more test tomorrow is required before we release this fix.

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

Do you have an update on this issue?

from entityframework-classic.

JonathanMagnan avatar JonathanMagnan commented on June 1, 2024

Hello @ClarkHsu ,

This issue will be closed since we believe it's resolved.

If you have more information, feel free to provide it and we will re-open the issue.

Best Regards,

Jonathan

from entityframework-classic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.