Random Dev Notes

December 15, 2013

Visual FoxPro Entity Framework Provider v2-Getting Started Using the EF Designer

Filed under: .Net Development — Tags: — Tom Brothers @ 3:41 pm

A new version of the Visual FoxPro Entity Framework Provider that targets EF6 is available.  The purpose of this blog post is to outline what you need to get started using the EF Designer with the new provider.  With the previous VFP EF Provider you could simply run the VfpEntityFrameworkProvider.msi installer and then have the provider available to you when you added a new “ADO.NET Entity Data Model” to your project.  But EF6 requires a little more setup to get started.  Most of this setup is handled by the VFPEntityFrameworkProvider2 NuGet Package.  So lets get started with the NuGet package and look at the details of what needs to be done.

 

Getting Started:

  • Install the VFPEntityFrameworkProvider2 NuGet package. 
    image
  • Make sure the VfpClient.dll and the VfpEntityFrameworkProvider.dll are set to copy local.  Normally I would just suggest this as a deployment option but now this is required to get the designer to work
    image

    Another requirement that the provider needs to be included in the config file (this is handled by the NuGet package). 

    image
  • Install the VfpEntityFrameworkProvider.msi which can be found in the packages directory. 
    image
  • Restart Visual Studio
  • If you try to add a new “ADO.NET Entity Data Model” you will find that the provider is not available.  The reason for this is that the EF6 Designer is looking for the EF Provider in the current project and is unable to find it until you build the project.  After building the project you will find that the provider is available when you try to add a new “ADO.NET Entity Data Model.” 
     
    image

* Here is a video showing everything mentioned in this post.

10 Comments »

  1. I’ve got this set up on my development machine and on IIS7.5, works great on the dev machine but it is giving me the following error through IIS:

    “Unable to cast object of type ‘VfpEntityFrameworkProvider.VfpConnection’ to type ‘VfpClient.VfpConnection’.”

    The project is an MVC4 Web API project using Entity Framework 6.

    The connection string is to a .dbc file on a network drive (application pool is authenticated to access network location) using provider name VfpEntityFrameworkProvider2, and I have the config string in web.config under set as

    I’m not sure why EF is trying to cast the type over from VfpEF to VfpClient… any suggestions?

    Comment by Shane Feather — July 14, 2016 @ 9:12 am

    • The VfpEntityFrameworkProvider.VfpConnection is derived from VfpClient.VfpConnection so that is odd that it is throwing that exception. My guess is that the VfpEntityFrameworkProvider.VfpConnection instance is null when that cast occurs. Could you provide a stacktrace?

      Comment by Tom Brothers — July 14, 2016 @ 3:33 pm

      • Wow… thanks for replying so quick… thought with being over a couple of years old it’d be a long shot… Anyways I solved it – brain fart on my part, your other setup instructions have a data annotation on the dbcontext declaration that I omitted.
        Added it and all was well – and you have saved my bacon. All the googling on earth and yours was the only workable solution I found for VFP and Entity Framework. Thanks!

        Comment by shanedf@outlook.com — July 14, 2016 @ 3:54 pm

  2. Created a Net 4.6.1 Framework web application using community 2015 and imported the Entity Framework Provider v2 using nugget package. Successfully connected to a free table and created the model.

    By using scaffolding created a Web API 2 controller with actions using Entity Framework. Projects compiled successfully.
    When launching the below error occurred. Please assist me. Thank You.

    The setup for build and release is ‘Any CPU’

    Server Error in ‘/’ Application.

    Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.BadImageFormatException: Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

    === Pre-bind state information ===
    LOG: DisplayName = VfpClient
    (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: VfpClient | Domain ID: 2
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/Users/gkanagar/school/AdvancedCSharp/WebFoxApplication1/WebFoxApplication1/
    LOG: Initial PrivatePath = C:\Users\gkanagar\school\AdvancedCSharp\WebFoxApplication1\WebFoxApplication1\bin
    Calling assembly : (Unknown).
    ===

    Comment by Ganga Ratnam — October 12, 2016 @ 10:04 am

    • Building as ‘Any CPU’ could be the problem. I know you need to build with x86 so that the VFP OLEDB provider will work. If changing the build doesn’t fix your problem then could you send me your code to see if I can debug the issue?

      Comment by Tom Brothers — October 12, 2016 @ 4:54 pm

      • Thank you so much for your quick reply!

        Built with x86 but still getting an error. Please see the stack trace.

        Server Error in ‘/’ Application.

        Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
        Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

        Exception Details: System.BadImageFormatException: Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

        Stack Trace:

        [BadImageFormatException: Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
        System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
        System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234
        System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108
        System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25
        System.Reflection.Assembly.Load(String assemblyString) +34
        System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49

        [ConfigurationErrorsException: Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
        System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772
        System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259
        System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163
        System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230
        System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +76
        System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +139
        System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
        System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +882

        [HttpException (0x80004005): Could not load file or assembly ‘VfpClient’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
        System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
        System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
        System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +712

        Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

        Comment by Ganga Ratnam — October 13, 2016 @ 8:11 am

      • Is your IIS Application Pool set to run as 32bit?

        Comment by Tom Brothers — October 14, 2016 @ 7:54 am

  3. You are a real smart hero!

    That did it. Thank you so much Tom, you have opened up a new path to me.

    Tools – Options – Projects and Solutions – Web Projects – Uncheck “Use the 64 bit version of IIS Express for web sites and projects”

    Comment by Ganga Ratnam — October 14, 2016 @ 8:33 am

  4. Good Morning,
    I’m using Visual Studio 2015 community, follow exactly all the steps https://randomdevnotes.com/2013/12/15/visual-foxpro-entity-framework-provider-v2-getting-started-using-the-ef-designer / # Postcomment
    Still trying to add a new “ADO.NET Entity Data Model” does not appear the option of using the “VFP Entity Framework Provider (EF6).”
    Is there any problem by having the VFP9.0 installing SP2 on the same machine?
    What can I be doing wrong?

    Any help will be welcome!

    Nelson

    Comment by Nelson — October 14, 2016 @ 10:21 am

    • I followed these stesp using VS Community edition and it worked fine for me. I had concerns with it working because previously Microsoft had another free VS edition called “VS Express” which wouldn’t allow me to register the VFP EF data provider. Did you get any errors when running VfpEntityFrameworkProvider.msi?

      Comment by Tom Brothers — October 14, 2016 @ 11:28 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: