I am having a very difficult time tracking down the cause of a bad assembly reference issue in my C#/Azure application. What I'm looking for is not so much for someone to tell me the exact solution to my problem but how to find how what assembly the system is attempting to load and how to find out why it's doing this.
The problem came about when we upgraded Azure tools. What's really weird is that the error only occurs (from what I can tell) when I attempt to call a database function via Entity Framework. EF does all of this implicit assembly loading and some how it is getting confused and trying to load Microsoft.ServiceBus 1.8.0.0 (or is finding that assembly) instead of version 2.2.0.0.
We are using Entity Framework 4.0. And FYI, we can call stored procedures and do other kinds of queries just fine. It's only db function calls that cause this particular issue.
I have searched high and low through my application and can find no references to 1.8.0.0 and no stray 1.8.0.0 dlls anywhere. It's possible that we have an out dated reference to some 3rd party library that is holding on to a reference to 1.8.0.0 but I think this is unlikely.
Still, my goal here is not for someone to tell me that X is my problem, but to give me a clue as to how I can spy on Entity Framework and find out why it's trying to load that assembly and what it expects to find and what it is actually finding.
Here is my full stacktrace.
Could not load file or assembly 'Microsoft.ServiceBus, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at System.Data.Metadata.Edm.MetadataAssemblyHelper.SafeLoadReferencedAssembly(AssemblyName assemblyName) at System.Data.Metadata.Edm.MetadataAssemblyHelper.d__0.MoveNext() at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData) at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors) at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage) at System.Data.Metadata.Edm.ObjectItemCollection.ImplicitLoadAllReferencedAssemblies(Assembly assembly, EdmItemCollection edmItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly) at System.Data.Objects.ObjectContext.CreateQuery[T](String queryString, ObjectParameter[] parameters) at Pallas.FlightBridge.Services.Internal.Data.Model.FlightBridgeDatabaseContext.TripPermissions(Nullable`1 companyPersonId) in c:\Users\RMacgrogan\dev\flightbridge\BaseOps\trunk\FB Version 7.8\code\InternalServices\Data\Model\FlightBridgeDataModel.Designer.cs:line 3778 at Pallas.FlightBridge.Services.Internal.Data.Repository.TripRepository.GetTripAndOrdersAndTravelers(Int32 tripId, Int32 companyPersonId) in c:\Users\RMacgrogan\dev\flightbridge\BaseOps\trunk\FB Version 7.8\code\InternalServices\Data\Repository\TripRepository.cs:line 50