Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > ORM Profiler Section > Bugs & Issues> EF 6 with .NET 4
 

Pages: 1
Bugs & Issues
EF 6 with .NET 4
Page:1/1 

  Print all messages in this thread  
Poster Message
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 05-Mar-2014 18:22:48.  
Hi, we're using EntityFramework.dll version 6.021211.0 on some projects that must target .NET Framework 4.

SD.Tools.OrmProfiler.Interceptor.EFv6 was built against .NET Framework 4.5, and referencing it causes an error.

Would it be possible to get a version of that DLL built against .NET 4?

Thank you!
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 06-Mar-2014 17:59:26. Goto attachments  
Of course! this is indeed something we didn't anticipated, thanks for the suggestion. Normally, one would go for .net 4.5 (as it's an in-place replacement for .net 4 anyway), but perhaps you can't yet so it's indeed a problem.

I've attached the .NET 4.0 build of the ef6 interceptor, which is build against .net 4.0. No async stuff is in this interceptor, so if you migrate your code to .net 4.5, you'll have to reference the normal efv6 interceptor to get async calls profiled. It's a release build so you don't have to download the full installer we'll post in an hour or so Regular Smiley


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 06-Mar-2014 18:06:32.  
You are awesome. Thank you very much! Regular Smiley

Otis wrote:
Of course! this is indeed something we didn't anticipated, thanks for the suggestion. Normally, one would go for .net 4.5 (as it's an in-place replacement for .net 4 anyway), but perhaps you can't yet so it's indeed a problem.

I've attached the .NET 4.0 build of the ef6 interceptor, which is build against .net 4.0. No async stuff is in this interceptor, so if you migrate your code to .net 4.5, you'll have to reference the normal efv6 interceptor to get async calls profiled. It's a release build so you don't have to download the full installer we'll post in an hour or so Regular Smiley

  Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 07-Mar-2014 18:28:33.  
When testing this, I'm getting the following error:

Code:
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.Odbc'. 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.
Source=EntityFramework
StackTrace:
     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)
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
     at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
     at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
     at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.WrappingDependencyResolver`1.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
     at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
     at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
     at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
     at System.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderServices(DbProviderFactory factory)
     at System.Data.Entity.Core.Common.DbProviderServices.GetProviderServices(DbConnection connection)
     at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.<ResolveManifestToken>b__0(Tuple`3 k)
     at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
     at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection)
     at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
     at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
     at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
     at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
     at System.Data.Entity.Internal.InternalContext.Initialize()
     at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
     at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
     // Back to custom code in our DbContext descendant


This is with EntityFramework.dll version 6.0.21211.0.

Our DbContexts are code first, and we do call base(connectionString) in the constructor. Do we need to do the v4.1 fix from your documentation?

Thank you!


  Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 07-Mar-2014 19:16:48.  
I've replicated this with a simple code first project to insure that it's nothing in our custom code.

I also tried porting the same project to .NET 4.5, and got:

Code:
Unhandled Exception: System.InvalidCastException: Unable to cast object of type
'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.Sql
Client.SqlConnection'.
at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)


This appears to be the same issue reported in this recent thread:
EntityFramework 6 + ORMProfiler 1.5: throws InvalidCastException

Is that fix not yet incorporated in the release build?

Thank you!
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 08-Mar-2014 10:26:32.  
yes that fix is in the build you have. The tests here run fine, so I don't know exactly why it would fail on your end (latest EF build)

The first error you reported is about ODBC... not sure how/why that is.
The error you report in your last post suggests that the interceptor is initialized too late. Be aware that as soon as you create a context, EF will connect with the DB to create the DB if it's not there, which will already initialize the factories.


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 10-Mar-2014 19:58:28. Goto attachments  
I'm attaching a sample project that replicates the issue. The only dependency is that SQLExpress is installed.
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 09:37:25.  
We'll look into it.

Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 10:13:20.  
It crashes with the weird ODBC error indeed on .net 4, it works fine on .NET 4.5, with the .NET 4.5 build of EF6 and the same EF6 .NET 4.0 interceptor (so exactly the same code!). Odd! I have no idea where the ODBC error comes from, will look into this though...

Switching the project to .net 4.5 with the .net 4.0 build of EF6 still gives the same error. Will try with EF6 built from source to see what on earth is going on but it looks like a bug in their framework.

Btw, if you want to use .net 4.5, you should download the latest build from the website, as the build I gave you is the .net 4.0 specific build, which does have the fix for the issue you ran into on .net 4.5, the older one build for .net 4.5 on your harddisk of course does not.

Still looking into that odbc issue.
Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 11:48:42.  
I have filed an issue with the EF team, as it seems it crashes within their code. There are two issues: v6.1 fails no matter what due to an optimization they added https://entityframework.codeplex.com/workitem/2138

The ODBC issue is likely caused by another issue in their code where services aren't replaced or not used so it won't use code which should have been in place if the DbConfiguration.Loaded event was raised properly. As that doesn't seem to be the case in the .net 4.0 build of EF 6, it will try to find the factory, fails and makes the mistake to pick the first one in the provider table to report the error with, which is ODBC, hence the odd issue.

I have to confirm the second, ODBC, issue, but I'm pretty sure that's the cause of that one.

(edit) The services are replaced, however EF 6 uses a specific class for .net 4.0 for finding factories (Don't ask me why) which fails to do it properly using the services we register, so it picks the first row (which is also wrong) and as that's the ODBC factory, it fails with the odbc related message. Issue: https://entityframework.codeplex.com/workitem/2139

Dissapointed... Needless to say, I'm not amused.


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 11-Mar-2014 15:48:04.  
Thanks for looking into this. I've added my vote to your EF bug report.

I installed the latest version from the web site and I'm still getting an issue targeting .NET Framework 4.5. I've verified that I'm using the net45 DLL of the EntityFramework.6.0.2 package. SD.Tools.OrmProfiler.Interceptor.NET45.dll is version 1.5.14.306.

Again with a simple test program, I get:

Code:
Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
at System.Data.Entity.Core.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.PrepareEntityCommandBeforeExecution(EntityCommand entityCommand)
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction,
Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 16:25:54.  
This is with the example program you attached earlier? as that works OK with 6.0.2 and .NET 4.5... Will try again...

Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 11-Mar-2014 16:56:16. Goto attachments  
I've attached the 4.5 project I used. I was also unable to use the DropCreateDatabaseAlways initializer.
  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 17:02:28.  
Your example program from above (the first one), with EF 6.0.2 on .NET 4.5 with the profiler enabled, interceptor for EF 6 (the .net 4.5 one), 1.5.306, works fine. Queries are run, results are
Code:
Product One
Product Two

1 passed, 0 failed, 0 skipped, took 5,22 seconds (Ad hoc).


I changed nothing, only the connection string in the code a bit so it connects to my local sqlexpress2012 install. That's all.

I see you added a new project, will try that.


Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 11-Mar-2014 17:08:44.  
I see you referenced the wrong interceptor, you referenced the non-EF one (the .NET 4.5 one). We unfortunately had to split up the interceptors as the EF 6 one requires a reference to the EF 6 dll because it implements some EF 6 interfaces / classes however that's of course a burden for other frameworks as it requires an EF 6 reference.

When I reference the right interceptor (the SD.Tools.OrmProfiler.Interceptor.EFv6.dll) it works fine, with or without the initializer. If I uncomment the line:
Database.SetInitializer<PricingContext>(new EFInitializer());

it runs fine, and calls are picked up, e.g.

Code:
CREATE TABLE [dbo].[PRODUCT]
    (
         [PROD_ID] [int] NOT NULL IDENTITY,
         [PROD_NM] [nvarchar](max),
         CONSTRAINT [PK_dbo.PRODUCT] PRIMARY KEY ([PROD_ID])
    )


So referencing the right interceptor fixes it for you Regular Smiley
Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 11-Mar-2014 17:18:14.  
Oops. Sorry about that! You're absolutely right - it works perfectly, even showing the initialization/migration calls. Thank you very much! Regular Smiley


Otis wrote:
I see you referenced the wrong interceptor, you referenced the non-EF one (the .NET 4.5 one). We unfortunately had to split up the interceptors as the EF 6 one requires a reference to the EF 6 dll because it implements some EF 6 interfaces / classes however that's of course a burden for other frameworks as it requires an EF 6 reference.

When I reference the right interceptor (the SD.Tools.OrmProfiler.Interceptor.EFv6.dll) it works fine, with or without the initializer. If I uncomment the line:
Database.SetInitializer<PricingContext>(new EFInitializer());

it runs fine, and calls are picked up, e.g.

Code:
CREATE TABLE [dbo].[PRODUCT]
    (
         [PROD_ID] [int] NOT NULL IDENTITY,
         [PROD_NM] [nvarchar](max),
         CONSTRAINT [PK_dbo.PRODUCT] PRIMARY KEY ([PROD_ID])
    )


So referencing the right interceptor fixes it for you Regular Smiley



  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 13-Mar-2014 09:36:13.  
Good it's solved Regular Smiley

Both reported issues to MS are bugs in EF, one has a workaround, the other (related to v6.1) does not, so we have to look into how to make this work. I'll let you know when things are properly solved.
Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 19-Mar-2014 09:06:33.  
.NET 4.0 issue is still an issue. 6.1 bug workaround has been implemented now and was released yesterday (18-mar-2014)

Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 27-Mar-2014 14:04:51.  
Another workaround for EF 6.1 on .NET 4.0 is now available. (issue 2139). MS couldn't fix this, the workaround at least makes it work.
Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
TrueWill
User



Location:
Iowa
Joined on:
05-Mar-2014 17:36:53
Posted:
13 posts
# Posted on: 27-Mar-2014 16:53:34.  
It works! Thank you very much!! Regular Smiley

I read the thread on the MS bug report - it's disappointing that Microsoft is refusing to fix this issue and pushing the work off onto other vendors.

Otis wrote:
Another workaround for EF 6.1 on .NET 4.0 is now available. (issue 2139). MS couldn't fix this, the workaround at least makes it work.



  Top
Otis
ORM Profiler Team



Location:
The Hague, The Netherlands
Joined on:
22-Aug-2011 10:26:38
Posted:
613 posts
# Posted on: 28-Mar-2014 10:38:24.  
Yeah, it's not the first time this happens, so I'm used to it by now. I also have the feeling .NET 4.0 support for EF 6 doesn't have a high priority for them. Anyway, it works now Regular Smiley
Frans Bouma
ORM Profiler / LLBLGen Pro Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.09082011 Final.