bubibubi / JetEntityFrameworkProvider

Microsoft Access (Jet) Entity Framework provider
89 stars 26 forks source link

Exception "Could not load file or assembly 'JetEntityFrameworkProvider' " when publish web api on IIS #18

Closed granadytos closed 7 years ago

granadytos commented 7 years ago

I'm getting the next exception when i published my web api solution over IIS, when i was working with visual studio it works very well, the execption showed up when i published the site and browsed it..

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

i followed the instruction to install .dll using GAC and change the machine.config (32bits and 64bits paths) when run the utility gacutil.exe /l JetEntityFrameworkProvider:

Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0 Copyright (c) Microsoft Corporation. All rights reserved. The Global Assembly Cache contains the following assemblies: JetEntityFrameworkProvider, Version=1.2.10.0, Culture=neutral, PublicKeyToken=756cf6beb8fe7b41, processorArchitecture=MSIL

and the machine.config file has the below lines

 <system.data><DbProviderFactories>
        <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>

        <add name="JetEntityFrameworkProvider" invariant="JetEntityFrameworkProvider" description="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider, Version=1.2.10.0, Culture=neutral, PublicKeyToken=756cf6beb8fe7b41" />

        </DbProviderFactories>
    </system.data>

NOTICE: i kept the version and publickeytoken all the same in all config files.

web.config lines:

 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="JetEntityFrameworkProvider" />
      <add invariant="JetEntityFrameworkProvider" name="Jet Entity Framework Provider" description="Jet Entity Framework Provider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider" />
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

this is the output messages when publish the solution

1>  zkaccess_webapi -> C:\Users\...\zkaccess_webapi\bin\zaccess_webapi.dll
2>------ Publish started: Project: zaccess_webapi, Configuration: Release Any CPU ------
2>Connecting to http://localhost/zaccessapi...
2>Transformed Web.config using C:\Users\...\zaccess_webapi\Web.Release.config into obj\Release\TransformWebConfig\transformed\Web.config.
2>Copying all files to temporary location below for package/publish:
2>obj\Release\AspnetCompileMerge\Source.
2>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\Users\...\zaccess_webapi\obj\Release\AspnetCompileMerge\Source -u -c C:\Users\...\zaccess_webapi\obj\Release\AspnetCompileMerge\TempBuildDir 
2>Copying all files to temporary location below for package/publish:
2>obj\Release\Package\PackageTmp.
2>Deleting existing files...
2>Publishing folder /...
2>Publishing folder Areas...
2>Publishing folder Areas/HelpPage...
2>Publishing folder Areas/HelpPage/Views...
2>Publishing folder Areas/HelpPage/Views/Help...
2>Publishing folder Areas/HelpPage/Views/Help/DisplayTemplates...
2>Publishing folder Areas/HelpPage/Views/Shared...
2>Publishing folder bin...
2>Publishing folder bin/amd64...
2>Publishing folder bin/amd64/Microsoft.VC90.CRT...
2>Publishing folder bin/roslyn...
2>Publishing folder bin/x86...
2>Publishing folder bin/x86/Microsoft.VC90.CRT...
2>Publishing folder Content...
2>Publishing folder fonts...
2>Publishing folder Scripts...
2>Publishing folder Views...
2>Publishing folder Views/Home...
2>Publishing folder Views/Shared...
2>Web App was published successfully http://localhost/zaccessapi
2>
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

what am i missing?

thank you!

bubibubi commented 7 years ago

The problem is related to 32/64 bits.
You can set 32 bits on IIS, opening IIS Manager, selecting the AppPool (or creating a new one to assign to the application), Advanced settings, General, Enable 32-bits application.

Some notes

granadytos commented 7 years ago

thank you, fix it !

i believe in love again !