Hibernating Rhinos

Zero friction databases

Entity Framework June 2011 CTP (v4.2) is now supported in Entity Framework Profiler

When Entity Framework June 2011 CTP was out, we were asked by our users to provide support for it in the Entity Framework Profiler.

As we started to investigate how to provide support for it, we discovered that it’s not that easy task to do. The way that Entity Framework Profiler appender works in nutshell is by replacing the instances of DbProviderFactory (like SqlClientFactory or OracleClientFactory) that the client has on his machine with a custom provider factory that wrap the original provider factory. This wasn’t easy task to do, because Entity Framework June CTP made a few assumptions that make our life more complicated. Specifically:

  • There is an assumption that the provider factory type is not a generic type. This broke our code which is uses a generic provider factory type which wrap each of the providers factories that the client have on the fly, since the client can use any provider factory that he wants.
  • Even if we use non-generic providers for each of the client’s providers, we found out that each provider should be compiled in a separate assembly because of the way that Entity Framework matches providers.

We’re working with the Entity Framework team in order to find a solution for this in the future versions, but in the mean time if you’re using the Entity Framework June 2011 CTP we temporary worked around this issue with a temp API that by providing a non-generic provider factory of type SqlClientFactory, which means that in the meantime you’ll be able to use the Entity Framework profiler only with Sql Server:


In addition, you’ll need to add the following assembly redirection to your config file in order to instruct the profiler to use the correct version of Entity Framework:

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <assemblyIdentity name="System.Data.Entity" publicKeyToken="b77a5c561934e089" culture="neutral" />
            <bindingRedirect oldVersion="" newVersion="" />

The main problem is that we can’t currently easily support providers other than SqlClient, if you do need that support on the new CTP, please let us know, and we will provide you with a custom version for that purpose. Considering that this is a CTP version, we decided to provide a partial solution that will work for most of our users and we’re working with the Entity Framework team in order to find a better solution.

Happy Profiling

The Hibernating Rhinos Team


Frans Bouma
07/28/2011 10:07 AM by
Frans Bouma

It's already broken in v4.1 Update 1: public static string GetProviderInvariantName(this DbConnection connection) { Type type = connection.GetType(); if (type == typeof(SqlConnection)) { return "System.Data.SqlClient"; } AssemblyName name = new AssemblyName(type.Assembly.FullName); foreach (DataRow row in DbProviderFactories.GetFactoryClasses().Rows) { string str = (string) row[3]; AssemblyName name2 = new AssemblyName(str.Substring(str.IndexOf(',') + 1).Trim()); if ((string.Equals(name.Name, name2.Name, StringComparison.OrdinalIgnoreCase) && (name.Version.Major == name2.Version.Major)) && (name.Version.Minor == name2.Version.Minor)) { return (string) row[2]; } } throw Error.ModelBuilder_ProviderNameNotFound(connection); }

We have the same problem with our profiler. Stacktrace: [FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)] System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) +0 System.Reflection.AssemblyName..ctor(String assemblyName) +80 System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection) +349 System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +57 System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +159 System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +61 System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) +117 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +423 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +63 System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() +15 System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() +40 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +315 System.Linq.Enumerable.ToList(IEnumerable`1 source) +58 ...

using dbproviderfactory table overwriting with generic types (as it's required to do so), like everyone else is using. The EF team says they're looking into it (whatever that's worth). it's... seriously messed up.

Fitzchak Yitzchaki
07/28/2011 10:12 AM by
Fitzchak Yitzchaki

Try to use EntityFrameworkProfiler.TempApi_InitializeForV42_CTP(); also for v4.1. It's should work fine as long you're using SqlClientFactory.

Frans Bouma
07/28/2011 10:42 AM by
Frans Bouma

I know, I'm not a user, just a messenger, as I'm in the same boat as you.

V4.2 has no provider support at all (as stated on their blog), but v4.1 should. I've contact the EF team about this on the data-access insiders mailing list of Microsoft. They're typically slow with fixing things, but this is such a major screw up that I hope this will be fixed soon. I'll blog about this in the next hour, to get more attention for this mess.

07/30/2011 03:47 PM by

Dont work with SQLCE4 and EF4.1 Update 1

Ayende Rahien
07/30/2011 06:02 PM by
Ayende Rahien

Oh, I just noticed that you are using SQL CE. I am afraid that the changes made by the EF Update 1 has made it impossible to support multiple providers, we are currently only supporting SQL Server with EF Prof on Update 1 or 4.2. We are working with the EF team to try to resolve this, and hope to have an answer soon.

Comments have been closed on this topic.