Is it possible to use RIA Services and EntityFramework.Migrations together in a project? - entity-framework

On NuGet there are packages:
EntityFramework.Migrations
EF 4.3.1
EF 4.1
RIA Services, which depends on EF < 4.2.
EntityFramework.Migrations doesn't work, because it is now included in EF 4.3+
I'm using Code First approach, so I need the DbDomainService<> class, which is not available, when RIA Services aren't installed.
Are there any standalone downloads for the above to manually reference in my project?
EDIT:
I removed RIA from NuGet packages, updgraded EF to 4.3.1 and then referenced RIA EntityFramework lib from toolkit manually as suggested here: Can I use RIA Services with Entity Framework 4.3?
Unfortuately now I'm getting the following error:
The following exception occurred creating the MEF composition container:
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
The default code generator will be used.

I guess that your problem is related to the T4 code generator of Ria Services. You can however get an idea of the type it can't load attaching your debugger (if you use VS don't forget to "Break on ALL Thrown CLR Exception) to the compilation of client side assembly (msbuild MyClientProjectThatContainTheProxy.csproj. )
However, if you just want to "try something", put this
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.3.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
in your web.config, to tell the CLR how to resolve depndencies.
More info here: http://mcasamento.blogspot.it/2012/10/entity-framework-5-code-first-and-wcf.html

Related

Impossible to migrate the "System.Directory.Services.Protocols" dll from version "4.0.0" to "5.0.1" with nuget (.net framework 4.8)

I have a project that uses the "System.Directory.Services.Protocols" dll which is in version 4.0 and references the framework:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.DirectoryServices.Protocols.dll.
I want to update the dll because there is a security hole in 5.0.0 fixed in 5.0.1.
But when I update with nuget (after removing the reference from my project), everything goes correctly (I don't get any error) but the referenced dll is still the one from framework 4.8.
I tried to reference it manually by adding it from the "net-standard 2.0" package directory
Packages\System.DirectoryServices.Protocols.5.0.1\lib
| net45\ <empty>
| netstandard2.0\System.DirectoryServices.Protocols.dll
but it doesn't work any better.
I thought the 4.8 framework was compatible with .net standard 2.0, so why doesn't it select this dll?
Encountered the same issue with fx4.8 and System.Directory.Services.Protocols nuget package version 6.0.1.
I think the problem is the incorrect package.
Try to bind version using app.config, for example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.DirectoryServices.Protocols" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.1" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

PostSharp.Sdk.CodeModel.BindingException

When compiling my project, which is having a Postsharp aspect (OnMethodBoundaryAspect) getting the error as
"Unhandled exception (4.0.41.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.BindingException: Cannot get the reflection object".
But this error message appears only on few machines, and the same project file is compiling successfully on most of the other machines.
I am using Visual studio 2013 and .net framework 4.5.
Postsharp dll version is 4.0.41
Please suggest the possible reason for this or any fix for this.
Thank you
<dependentAssembly>
<assemblyIdentity name="PostSharp"
publicKeyToken="b13fd38b8f9c99d7"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.39.0"
newVersion="4.0.39.0" />
</dependentAssembly>
app.config is the first place I would look for errors of this nature. Make sure the references are correct.
Unfortunately though, I still get this error i some cases that I can't discover why yet.

Only NUnit error: Could not load file or assembly 'EntityFramework'

I get an error message in NUnit when I try to run a specific test. The error looks like this:
ChatProj.Tests.MessageRepositoryTests.Logg_LoggWorking_AssertView:
System.IO.FileLoadException : Could not load file or assembly 'EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Here is a picture
I've looked at the 2 projects in my solution, and I'm refrencing EF 6.0.0.0 in both. I've tried to look up the PublicKeyToken=b77a5c561934e089 and this is what I found in my solution. It's extra weird because I've no problem debugging or building the webapp, and the other unittests are testing within the same project (same EF version) and not reciving this error (as you can see in the picture from before).
Any idea what could be causing this problem?
UPDATE:
I think I figured it out. I was using nuget.org/packages/FakeDbSet which was using a command like : var mockItemList = new InMemoryDbSet { new Message {MessageID = 5000, Name ="Erland", MessageString ="Foo Bar", MessageDate = DateTime.Now} }; which somehow is an old way of faking entity framework code. Can be seen here: i.imgur.com/f6dnJbq.png
First, ensure that the EF DLL is actually getting pulled into the bin folder for the test application. If it is and the DLL is for EF v6, do you see version redirects for EF in your app.config for the test project? Something like this?
<configuration>
<!-- Leave the rest of the configuration file alone and just add the runtime area as follows: -->
<runtime>
<assemblyBinding>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
If not, try pasting that into the app.config.
Sorry, it's hard to fully diagnose without more information.

PowerTools Beta 3 fails

I was trying to generate "views" to enhance the performance of my application. The application is Silverlight 4 linked with RIA services to the Server. The server application started with EF 4.1 + RIA Services.
I installed "EF Power Tools Beta 3 v0.7.0.0" and could generate my views with no problem. But I soon realized that EF 4.1. was not able to benefit from the precompiled views. EF >= 4.2 was required.
Through NuGet I saw an update for RIA Services (RIAServices.EntityFramework.4.2.0) which used EF 5. I installed and got everything working but when I try to generate views I get an exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
I've tried reinstalling PowerTools. No luck
I've downloaded source code for PowerTools and debugged the Exception. Apparently PowerTools was trying and could not find the old EF version. The LoaderExceptions property read:
{System.IO.FileNotFoundException: Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
I've investigated the PublicKeyToken and confirmed that it is the same as the EF 5 (EF 4.4 target=.NET 4) dll found in my "bin" output map. But PowerTools is looking for EF 4.1.. why?
My web.config file has this:
<sectionGroup name="system.serviceModel">
<section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" allowDefinition="MachineToApplication" requirePermission="false" />
</sectionGroup>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
and:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.4.0.0" newVersion="4.4.0.0" />
</dependentAssembly>
</assemblyBinding>
I've also tested changing the PublicKeyToken in Web.config just to confirm that I get another error from PowerTools thus PowerTools seems to parse my Web.config.
Update:
I've created a new Web project and added all Model code files as links. Same connectionstrings. Now i can build views.. strange.. same references.
When I add the views to my original project the RIA services won't start. Removed views and they started again.

Could not load file or assembly 'EntityFramework' after downgrading EF 5.0.0.0 --> 4.3.1.0

After too hastily upgrading to EF 5.0.0.0 RC and being stuck with a .NET 4.5 project that wouldn't deploy to Windows Azure (.NET 4.0 and below), I decided to downgrade to EF 4.3.1.0.
I'm unsure of the best way to perform this type of migration but my strategy is to use "Manage NuGet Packages" identify which projects reference the package, uncheck the package from each project, install the replacement and recheck the correct projects.
Unfortunately, after doing this, my solution produced the titular "FileLoadException".
Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's
manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I searched through the solution files particularly packages.config for references to EF 5.0.0.0 RC but could find none.
After failed attempts to find references to EntityFramework in repositories.config and elsewhere, I stumbled upon a reference in Web.config as I was editing it to help with my diagnosis.
The bindingRedirect referenced 5.0.0.0 which was no longer installed and this appeared to be the source of the exception. Honestly, I did not add this reference to Web.config and, after trying to duplicate the error in a separate project, discovered that it is not added by the NuGet package installer so, I don't know why it was there but something added it.
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
I decided to replace this with the equivalent element from a working project. NB the references to 5.0.0.0 are replaced with 4.3.1.0 in the following:
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
</dependentAssembly>
This worked!
I then decided to remove the dependentAssembly reference for the EntityFramework in its entirety. It still worked!
I would still be interested in answers to these questions:
What added the dependentAssembly for EntityFramework to my Web.config
Any consequence(s) of removing these references
I'd be interested to learn.
I have this issue, and all I did was make sure that I was referencing the right .Net framework in all the projects then just change the web.config from
From
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
To
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false"/>
All works..
I had the same issue when updating an older project. Here's what I did to resolve it:
Converted all projects to .NET 4.5.
Uninstalled the NuGet package for Entity Framework 5.
Reinstalled the NuGet package for Entity Framework 5.
Cleaned the solution.
Rebuilt the solution.
The projects that used Entity Framework 5 and .NET 4 were installing the Entity Framework dll version 4.4. Once I switched the .NET version to 4.5 on the project, the dll version would be 5.
My problem came from older projects being on .NET 4 and a newer project running .NET 4.5 so there were 2 dll versions of EF in my solution.
Hope this helps someone...
I had a similar issue running unit tests using MSTEST under Jenkins. The fix in my case was to remove "Version=6.0.0.0, " as shown below:
Old:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=xxxx" requirePermission="false" />
New:
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Culture=neutral, PublicKeyToken=xxxx" requirePermission="false" />
I had to make this change is several App.config and Web.config files in my multi-project solution.
While Building a Project, if in the project properties it shows that it is build under Target.NET Framework 4.5, update it to 4.6 or 4.6.1. Then the build will be able to locate Entity Framework 6.0 in the Web.config file. This approach solved my problem.
Selecting Target framework from Project Properties
If you used the Visual Studio 2012 ASP.NET Web Forms Application template then you would have gotten that reference. I'm assuming it's the one you would get via Nuget instead of the framework System.Data.Entity reference.
I received the exact same error message. Except that my error message said "Could not load file or assembly 'EntityFramework, Version=6.0.0.0...", because I installed EF 6.1.1. Here's what I did to resolve the problem.
1) I started NuGet Manager Console by clicking on Tools > NuGet Package Manager > Package Manager Console
2) I uninstalled the installed EntityFramework 6.1.1 by typing the following command:
Uninstall-package EntityFramework
3) Once I received confirmation that the package has been uninstalled successfully, I installed the 5.0.0 version by typing the following command:
Install-Package EntityFramework -version 5.0.0
The problem is resolved.
I had similar issue with selenium:
I downgraded my selenium using NuGet and got the same error message. My solution was to remove the newer version lines from the app.config file.
I got same issue. I was getting the System.Data.Entity.Infrastructure; error which is only part of v5.0 or later. Just right click the Reference and select "Manage NuGet Package" . In the Installed Package option , uninstall the Entity FrameWork which is already installed and Install the 5.0 version. It solve the problem. I was trying manually get the System.Data.Entity reference , which was not success.
public Configuration()
{
AutomaticMigrationsEnabled = false;
// register mysql code generator
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}
I find out that connector 6.6.4 will not work with Entity Framework 5 but with Entity Framework 4.3. So to downgrade issue the following commands in the package manager console:
Uninstall-Package EntityFramework
Install-Package EntityFramework -Version 4.3.1
Finally I do Update-Database -Verbose again and voila! The schema and tables are created. Wait for the next version of connector to use it with Entity Framework 5.
I had a similar issue:
On my ASP.NET MVC project, I've added a Sql Server Compact database (sdf) to my App_Data folder. VS added a reference to EntityFramework.dll, version 4.* . The web.config file was updated appropriately with the 4.* configuration.
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
I've added a new project to my solution (a Data Access Layer project). Here I've added an EDMX file. VS added a reference to EntityFramework.dll, version 5.0. The App.config file was updated appropriately with the 5.0 configuration
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
On execution, when reading from the database the app always thrown the exception Could not load file or assembly 'EntityFramework, Version=5.0.0.0 ....
The issue was fixed by removing the EntityFramework.dll v4.0 from my MVC project. I've also updated the web.config file with the correct 5.0 version. Then everything worked as expected.
In your references click on the EntitiyFramework .
Go to properties and set the specific version to False.
It worked for me.