New embedded Firebird, code first, EF6 project results in SerializationException - ef-code-first

I'm trying to set up Firebird with EF6 as an embedded server for a simple app I'm writing but haven't been able to get it to work. I have a CLI project which is the app and the DAL project which is the DB. I added the NuGet packages to both and created a DbContext with a simple entity, and created an initial migration successfully, but when trying to run update-database to execute the migration I received this error in the Package Manager Console:
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'FirebirdSql.Data.FirebirdClient.FbException,FirebirdSql.Data.FirebirdClient, Version=4.10.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c'.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'FirebirdSql.Data.FirebirdClient.FbException,FirebirdSql.Data.FirebirdClient, Version=4.10.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c'.
Actually I just noticed that nothing works now... If I remove my migration and try to recreate it, I get this error. I was able to enable migrations and create one before, but now I can't. Bizarre.
All of my projects are targeting .NET 4.5.2 and they all have the same package versions. My solution/project path has no spaces or ampersands or weird characters in it. I've tried using my app project as the startup project and the DAL project and that didn't make a difference.
My packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="EntityFramework.Firebird" version="4.10.0.0" targetFramework="net452" />
<package id="FirebirdSql.Data.FirebirdClient" version="4.10.0.0" targetFramework="net452" />
</packages>
My App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="DAL.DbContext" providerName="FirebirdSql.Data.FirebirdClient" connectionString="User=SYSDBA;Password=masterkey;Database=SampleDatabase.fdb;DataSource=localhost;Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=1;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data>
</configuration>
The connection string I just found on the net so that might be wrong, but I couldn't find any documentation for it...
I've done code-first EF dozens of times with SqlServer before and never ran into this problem before, but this app won't have a real server to hit. Unfortunately this seems like a more general problem than Firebird or EF, but I'm not sure where to even look at this point.

I had this same exact issue and was able to figure out exactly what was going on with the help of the previous answer. It is a known bug and they have a fix for 6.2. The exception is hiding a deeper problem that may be difficult to know without a proper stack trace. A workaround is to upgrade your Entity Framework to the latest 6.2 pre-release build and see what the real problem is then revert back to your current build, in my case it was 6.1.3
Get the latest signed build from Entity Framework 6.2. You will need to add the NuGet repository https://www.myget.org/F/aspnetwebstacknightly/ . Detailed instructions for this step can be found here: https://github.com/aspnet/EntityFramework6/wiki/Nightly-Builds
Open the NuGet Package Manager for your solution
Check the 'pre-release' checkbox at the top of the NuGet Package Manager
In the project selection window select all of your project(s) that reference Entity Framework
In the version dropdown select the latest 6.2 build and click the 'install' button. This will uninstall your current version and install the pre-release version selected
Build your solution
Open the Package Manager Console and enter the command Update-Database
At this point you should see a detailed error message of what is wrong and it should give you a better idea of what you need to do to resolve the issue. In my case there was an issue with accessing a file and Visual Studio needed to be ran as an Administrator.
Once you resolve the issue you can either undo your changes to entity framework version or follow the steps above but updating your version to the previous version you were using.

This is known issue in EF. It's fixed in not-yet-release 6.2.

Related

SQLite 1.0.101.0 and entityframework 6.1.3, using LINQ, will not run

I have developed a windows service that worked well but wanted to add access to SQLite databases. I developed a data manager project within the windows service to add the SQLite data handling. This was developed using VS2015.
The entity framework side of things worked well and built a model of the SQLite database and the service would start and run properly. The connection to the database also worked but when an attempt was made to run a query, I got the following error:
"Schema specified is not valid. Errors:
Video.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."
The problem is that when I add the configuration and entity framework sections to the config file, the service won't start, giving the following error:
"The Media Sync Service service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion."
Here are the configuration and entity framework sections:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
Has anyone else had this problem? I would be very grateful for any advice as to how to fix this.

500.21 Bad module "ManagedPipelineHandler" in its module list

I am getting the error:
HTTP Error 500.21 - Internal Server Error
Handler "CloudConnectHandler" has a bad module "ManagedPipelineHandler" in its module list
my web.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="CloudConnectHandler" verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" resourceType="Unspecified" />
</handlers>
</system.webServer>
<system.web>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.0" batch="false">
<assemblies>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
</assemblies>
</compilation>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
<identity impersonate="true" />
<authentication mode="Forms" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compilers>
</system.codedom>
<appSettings>
<add key="CloudConnectAuthorization" value="xxxx" />
<add key="ConnectionInfo" value="xxxx" />
<add key="ConnectionString" value="xxxx" />
<add key="DefaultChannel" value="xxxx" />
<add key="LoginValidationConnectionString" value="xxxx" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="protobuf-net" publicKeyToken="257b51d87d2e4d67" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.640" newVersion="2.0.0.640" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There is a lot of advice out there indicating that asp.net is not installed correctly. The usual fix is to run:
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
or
%windir%\Microsoft.NET\Framework\v4.0.21006\aspnet_regiis.exe -i
I have run both, without any errors. I have restarted IIS, but the problem still persists. The site is using an application pool. The app pool is started, .net framework = 4.0, Managed Pipeline = Classic, Identity = LocalSystem.
I've spent the last couple hours trying to figure out what the problem is. I'm hoping someone can help.
Please follow these steps:
1) Run the command prompt as administrator.
2) Type either of the two lines below in the command prompt:
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
or
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
I ran into this error on a fresh build of Windows Server 2012 R2. IIS and .NET 4.5 had been installed, but the ASP.NET Server Role (version 4.5 in my case) had not been added. Make sure that the version of ASP.NET you need has been added/installed like ASP.NET 4.5 is in this screenshot.
To fix the problem, I tried to run
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
However It didn't work for me. I have to run another command line in CMD window as administrator. Here is the command:
dism /online /enable-feature /featurename:IIS-ASPNET45
or
dism /online /enable-feature /featurename:IIS-ASPNET45 /all
Hope it will help.
Try switching to Integrated mode. See the following thread:
IIS 7, HttpHandler and HTTP Error 500.21
I got this error on my ASP.Net 4.5 app on Windows Server 2012 R2.
Go to start menu -> "Turn windows features on or off". A wizard popped up for me.
Click Next to Server Roles
I had to check these to get this to work, located under Web Server IIS->Web Server-> Application Development (these are based on Jeremy Cook's answer above):
Then click next to Features and make sure the following is checked:
Then click next and Install. At this point, the error went away for me. Good luck!
This is because IIS 7 uses http handlers from both <system.web><httpHandlers> and <system.webServer><handlers>. if you need CloudConnectHandler in your application, you should add <httpHandlers> section with this handler to the <system.web>:
<httpHandlers>
<add verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" />
</httpHandlers>
and also add preCondition attribute to the handler in <system.webServer>:
<handlers>
<add name="CloudConnectHandler" verb="*" path="CloudConnect.aspx" type="CloudConnectHandler" preCondition="integratedMode" />
</handlers>
Hope it helps
I had this issue in Windows 10 when I needed IIS instead of IIS Express. New Web Project failed with OP's error. Fix was
Control Panel > Turn Windows Features on or off > Internet Information Services > World Wide Web Services > Application Development Features
tick ASP.NET 4.7 (in my case)
For me, I was getting this error message when using PUT or DELETE to WebAPI. I also tried re-registering .NET Framework as suggested but to no avail.
I was able to fix this by disabling WebDAV for my individual application pool, this stopped the 'bad module' error when using PUT or DELETE.
Disable WebDAV for Individual App Pool:
Click the affected application pool
Find WebDAV Authoring Tools in the list
Click to open it
Click Disable WebDAV in the top right.
This link is where I found the instructions but it's not very clear.
I had this problem every time I deployed a new website or updated an existing one using MSDeploy.
I was able to fix this by unloading the app domain using MSDeploy with the following syntax:
msdeploy.exe -verb:sync -source:recycleApp -dest:recycleApp="Default Web Site/myAppName",recycleMode=UnloadAppDomain
You can also stop, start, or recycle the application pool - more details here: http://technet.microsoft.com/en-us/library/ee522997%28v=ws.10%29.aspx
While Armaan's solution helped get me unstuck, it did not make the problem go away permanently.
if it is IIS 8 go to control panel, turn windows features on/off and enable Bad "Named pipe activation" then restart IIS. Hope the same works with IIS 7
I discovered that the order of adding roles and features is important.
On a fresh system I activate the role "application server" and there check explicitly .net, web server support and finally process activation service
Then automatically a dialogue comes up that the role "Web server" needs to be added also.
Install .NET framework as below, it will work .NET version 4.5 as well.
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ir
Some time only give aspnet_regiis.exe -i don't work so give aspnet_regiis.exe -ir in above path.

Entity Framework works on Local Server but not Remote

Ok so I have a website that uses ASP.net mvc, the problem I am having is with Entity Framework. I added all the references and got it to run on my local machine but when I publish it I get the following error.
System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I have double checked my references and I have EntityFramework.SqlServer and System.Data both added into my project. The connection string I use to connect to the data base and declare the service provide is below.
<connectionStrings>
<add name="[dataConnection]" connectionString="Data Source=[ip of host machine];Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Name we just have the name of the data base, this is also used in my web.debug.config
<connectionStrings>
<add name="[dataconnection]"
connectionString="Data Source=.;Database=[name];UID=[user];pwd=*******;MultipleActiveResultSets=True;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
I am pretty new to this entire thing and was just handed someone elses code so I am trying to learn on the flow. This is my first encounter with this so any direction would be appreciated.
I had the same problem in my integration test assembly (i'm using ms visual studio unit testing framework for this) and i've solved it by adding EF assemblies to deployment items in .testsettings file.
I've installed EF 6 alpha using Package Manager Console using:
Install-Package EntityFramework -Pre
Here is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
My connection string (i'm setting it in code): server=.\SIN;initial catalog=IntegrationTests;User ID=user;Password=pass;MultipleActiveResultSets=true;
I've looked at the EF assembly reference properties to see if they are set to "Copy Local" = True.
And finally i've checked out TestResults/../Out folder and found that there is no EntityFramework.SqlServer assembly there (SqlProviderServices class resides in it).
So i've just added both EF 6 assemblies to my deployment items and now everything is ok
You can try to copy EntityFramework.SqlServer assembly to your web server directory to see if it works.
Maybe this link can be helpful
P.S:
Make sure you don't have a reference to System.Data.Entity, because you'll be using one from GAC. EF 6 Alpha assemblies is not installed in GAC when you install them with Nuget. Target framework should be .NET 4.5.
Sorry for my bad english.
A question: which EF version?
Check your IIS pool .NET version... It should be the one that points to the .NET version of your published project... The assembly of EF should be in the .NET framework folder under Windows directory (AKA GAC)

System.Data.SQLite and SubSonic 3: Works great in VS2008, but not in VS2010

Last year, I used SubSonic 3 and SQLite in a VS2008 project very successfully and was quite pleased with the results. Just recently, I tried to setup SubSonic 3 and SQLite in a VS2010 project and have been met with the inner exception when trying to instantiate a new SimpleRepository:
The type initializer for
'System.Data.SQLite.SQLiteFactory'
threw an exception
Just to make sure I wasn't going crazy, I tried the exact same code and app.config file in VS2008 and no problem. Weird!
Currently, I'm using SubSonic 3.0.0.4 and the x64 version of System.Data.SQLite 1.0.73.0 (3.7.6.3) (though I tried the 32 bit version as well.) I added both DLLs as a Reference and set "Copy Local" to TRUE.
My App.Config looks like:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="myDatabase" connectionString="Data Source=C:\DB\mydatabase.db3" providerName="System.Data.SQLite"/>
</connectionStrings>
And my code looks like:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic.Repository;
namespace SubSonicSqliteTestConsole
{
class Program
{
static void Main(string[] args)
{
var repo = new SimpleRepository("myDatabase", SimpleRepositoryOptions.RunMigrations);
}
}
}
Any ideas?
I am using SubSonic 3 with Visual Studio 2010 and SQLite 1.0.66 and it works.
However there are a few things you have to do:
Your application has to be x86 (not AnyCPU) or you get a BadImageFormatException on 64 bit machines
You have to change the Target Framework from "Framework 4.0 Client Profile" to "Framework 4.0"
You have to add (or modify) this to your app.config file. SQLite won't work without the useLegacyV2RuntimeActivationPolicy flag set to true
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
My Factory initialisation code looks like this (it includes the Version and the PublicKeyToken). I got this settings from the machine.config file on my dev machine where I ran the setup and have choosen to integrate SQLite to Visual Studio 2010 (from the All Programs\SQLite folder). The file is located # %WinDir%\Microsoft.NET\Framework\<FrameworkVersion>\CONFIG
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
My connection strings contains slashes instead of backslashes in the path and contains a version
<connectionStrings>
<add name="connectionstringname"
connectionString="Data Source=c:/temp/mydatabase.db;Version=3;"
providerName="System.Data.SQLite"/>
</connectionStrings>
Hope that helps.
Update:
I see you use a x64 version of SQLite, so forget about the first hint. But I leave it, maybe it is helpful for others.
If I remember correctly, the "The type initializer for ... threw an exception" error message usually means that something in the static constructor for the type threw an exception. You might want to try opening System.Data.SQLite.SQLiteFactory in Reflector or dotPeek or JustDecompile or whatever tool you prefer, and see what its static constructor (.cctor) is doing. Do you have ti using .NET 4 in VS2010 and .NET 2/3 in VS2008? That might be part of the issue too.

Why might this ASP.NET profile section fail to dynamically compile?

When the following profile section is in my web.config, the first page request fail with FileNotFoundException and a bunch of error coming from the compiler (from the look of the stack trace). When the properties section is removed, everything works again (until I try to reference something from the Profile of course). The rest of the website is pre-compiled, assembly per page, not-updatable.
The problem has only been reproduced on one machine-- the same build worked on other highly similar machines.
Am I missing anything obvious?
<profile>
<providers>
<clear />
<add name="AspNetSqlProfileProvider"
connectionStringName="ConnectionString"
applicationName="OIWebApps"
type="System.Web.Profile.SqlProfileProvider"/>
</providers>
<properties>
<group name="UI">
<add name="MasterPage" defaultValue="Horizontal.master"/>
<add name="Theme" defaultValue="Default"/>
<add name="IsSessionWarningEnabled" defaultValue="True" type="System.Boolean"/>
<add name="UseTelerikMultilineTextBoxes" defaultValue="True" type="System.Boolean"/>
<add name="FontSize" defaultValue="Smaller" type="System.String"/>
</group>
</properties>
</profile>
I see "UseTelereikMultilineTextBoxes". Could it be that a file needed for Telerik is missing on this machine?
It failed to compile because of a missing native .dll It was extremely hard to identify because the page that was executing didn't directly use the .net dll that depended on the missing native .dll, and even more confusingly, only some pages raised the compile error instead of being raised on all pages.

Resources