Question

Ok, a bit stumped here, and instead of banging my head any more on this, I thought I'd toss this out to all the bright people here.

I'm using Entity Framework and c# for a WinApp solution, and the core of the problem is that the darned thing runs fine on my system, but after I deploy it, it fails. Even when I install the deployed app on my development system, it fails. I find that a bit disturbing.

To the nuts and bold of the issue. The user performs a search, I build a query, tap SQL via the ExecuteStoreQuery call and return a generic list of SearchResult objects.

The call:

retVal = ctx.ExecuteStoreQuery<SearchResults>(sql).ToList();

Alternate call also generates the same error:

ObjectQuery<DbDataRecord> c = ctx.CreateQuery<DbDataRecord>(sql);

The Error:

************** Exception Text **************
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly()
   at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load()
   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.MetadataWorkspace.ImplicitLoadAssemblyForType(Type type, Assembly callingAssembly)
   at System.Data.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, MergeOption mergeOption, Object[] parameters)
   at AMMCred.Data.Search.GetSearchResults(SearchTerms terms)
   at AMMCred.frmMain.openProviderInfoToolStripMenuItem_Click(Object sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

SearchResults is a custom object, like so:

public class SearchResults : IEquatable<SearchResults>
{
    private Guid id = Guid.Empty;
    public Guid PROV_MPI_NO
    {
        get { return id; }
        set { id = value; }
    }
    private string iPA = "";
    public string IPA
    {
        get { return iPA; }
        set { iPA = value; }
    }
    private string firstName = "";
    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }
    private string middleName = "";
    public string MI
    {
        get { return middleName; }
        set { middleName = value; }
    }
    private string lastName = "";
    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }
    private string license = "";
    public string License
    {
        get { return license; }
        set { license = value; }
    }
    private string provId = "";
    public string ProvId
    {
        get { return provId; }
        set { provId = value; }
    }
    /// <summary>
    /// Used to help identify duplicates in a collection
    /// </summary>
    /// <param name="other"></param>
    /// <returns></returns>
    public bool Equals(SearchResults other)
    {
        return (this.PROV_MPI_NO == other.PROV_MPI_NO && this.License == other.License);
    }
}

And finally, here is the select part of the SQL being used to obtain the search results:

SELECT a.PROV_MPI_NO, b.COMPANY_ID AS IPA, a.FIRSTNAME,a.MI,a.LASTNAME, b.PROVID, c.LICENSE

The problem seems to be coming from within Entity Framework as it's binding the results of the SQL to the custom object. I've verified that the custom object field names are the same as the SQL fields in case that mattered, which it didn't seem to.

It's darn near time for me to leave, and I'll be pondering this all weekend, so I'll probably check back in from time to time to answer any questions anyone might have.

Like I said, I'm completely stumped at the moment and would totally appreciate anyone's insight.

Thanks in advance!

Wayne

UPDATE 11/14/2011---------- Ran the Assembly Binding Log Viewer tool and came up with the following lead. Looks like Microsoft.Practices.Unity isn't loading. Thing is, I never once referenced these Practices assemblies in ANY application, but it seems that System.Data.Entity does...go figure. It's a lead...any info on this new development is so very appreciated.

*** Assembly Binder Log Entry  (11/14/2011 @ 3:10:52 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Users\***me***\AppData\Local\Apps\2.0\1ND1AZ7G.HEJ\CWDQKK8A.LVO\ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4\AMMCred2.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = ***me***
LOG: DisplayName = Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Users/***me***/AppData/Local/Apps/2.0/1ND1AZ7G.HEJ/CWDQKK8A.LVO/ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = AMMCred2.exe
Calling assembly : Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\***me***\AppData\Local\Apps\2.0\1ND1AZ7G.HEJ\CWDQKK8A.LVO\ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4\AMMCred2.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/***me***/AppData/Local/Apps/2.0/1ND1AZ7G.HEJ/CWDQKK8A.LVO/ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4/Microsoft.Practices.Unity.DLL.
LOG: Attempting download of new URL file:///C:/Users/***me***/AppData/Local/Apps/2.0/1ND1AZ7G.HEJ/CWDQKK8A.LVO/ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4/Microsoft.Practices.Unity/Microsoft.Practices.Unity.DLL.
LOG: Attempting download of new URL file:///C:/Users/***me***/AppData/Local/Apps/2.0/1ND1AZ7G.HEJ/CWDQKK8A.LVO/ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4/Microsoft.Practices.Unity.EXE.
LOG: Attempting download of new URL file:///C:/Users/***me***/AppData/Local/Apps/2.0/1ND1AZ7G.HEJ/CWDQKK8A.LVO/ammc..tion_0000000000000000_0002.0000_456d6de62e1c40e4/Microsoft.Practices.Unity/Microsoft.Practices.Unity.EXE.
LOG: All probing URLs attempted and failed.
Was it helpful?

Solution

Based on your bind result, it looks like you are not deploying Microsoft.Practices.Unity.DLL with your application. And it looks like this is referenced from Microsoft.Practices.EnterpriseLibrary.Common, which is why you don't have a direct reference.

Here is the MSDN article that describes the various dependencies that the Enterprise Library has.

Update

I just checked the direct dependencies of System.Data.Entity using ildasm.exe (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin) and it definitely does not reference the enterprise library. I would have been extremely surprised if it had, because they generally don't create dependencies between System DLLs and optional product DLLs (just for this reason).

Are you pulling in other DLLs/references that may include this? If you aren't sure, you can use ildasm.exe, navigate to the DLL, then open it's manifest. It's a little hard to read, but you are looking for references like:

module extern 'System.Data.dll, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

and

.assembly extern System.Data

OTHER TIPS

The error is a load exception.

Since this works in development, but not in the deployed program, it is probably due to the dll not being included.

Go into your VS project, expand the references and check the properties of each dll, make sure that copy local = true for the dll's that are not being deployed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top