I’m trying to upgrade EntityFramework from v4 to v6 in our silverlight application. Since we user WCF RIA Services we have to upgrade that to OpenRia (since property WCF RIA only supports EF5).
However whenever I try to install “OpenRiaServices.EntityFramework” in our Silverlight app, I get:
Could not install package 'OpenRiaServices.EntityFramework 4.3.0.0'. You are trying to install this package into a project that targets 'Silverlight,Version=v5.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I think this is because the dll, targets “.NET Framework”, while Silverlight apps target "Silverlight" - question is: is there any way around it?
Second problem - that may, or may not be related to the first - is that even after I installed OpenRia I get following error during comppilation:
Error 206 The type 'System.ServiceModel.DomainServices.Client.EntityQuery`1' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ServiceModel.DomainServices.Client, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Of course the above DLL is part of the old RIA implementation, and cannot be referenced, any way around this?
Is it at all possible to use EF6 with silverlight applications that use RIA?
We are using EF6 + OpenRia, but not through NuGet. All RIA dlls are stored in the "Lib" folder and referenced manually. Then I install "Open Ria Services Tooling and Templates", there is an VS extension, and not NuGet package.
.Ria (Silverlight 5) project has references:
OpenRiaServices.Data.DomainServices.dll (2.0.5.0)
OpenRiaServices.DomainServices.Client.dll (2.0.5.0)
OpenRiaServices.DomainServices.Client.Web.dll (2.0.5.0)
.Ria.Web (.NET 4.5 Class library) project has references:
OpenRiaServices.DomainServices.EntityFramework.dll (4.0.0.0)
OpenRiaServices.DomainServices.Hosting.dll (4.0.0.0)
OpenRiaServices.DomainServices.Server.dll (4.0.0.0)
On the end of .Ria project file I add the next element:
<Import Project="..\..\..\Libs\Silverlight\OpenRia\CodeGen\OpenRiaServices.Silverlight.CodeGen.targets" Condition="Exists('..\..\..\Libs\Silverlight\OpenRia\CodeGen\OpenRiaServices.Silverlight.CodeGen.targets')" />
(you must modify this string for your RIA .target reference)
EF 6.0.2 installed through NuGet.
Related
I'm building an ASP.NET MVC app with VS 2017, targeting .NET 4.7, and I'm trying to build my models inside of business library being referenced by the web application. So I'm trying to get many of the same classes that come with an MVC project by default into a brand new class library.
Particularly, I'm getting the following error:
This is very different from the previous times this question was posted:
The type or namespace name 'IClientValidatable' could not be found
The type or namespace name 'IClientValidatable' could not be found (are you missing a using directive or an assembly reference?)
Namely, in that they both are solved simply by including the using statement for System.Web.Mvc where IClientValidatable lives.
But I've definitely already done that... Here's the reference manager for the class library with the reference included available for .NET 4.7
As further proof, here's a side by side example of where I can pull in some classes from System.Web.Mvc, but not IClientValidatable
For reference sake, here's the configuration on the class library itself
So did this class move somewhere? Is it available with .NET 4.7?
So the real question seems to be not where did it go, but why the most recent framework is targeting such an old version.
When trying to add a reference to System.Web.MVC while targeting .NET Framework 4.7, the only available option is MVC v2.0.0.0 which is incredibly old. When seeding a new MVC app, it'll come with v5.2.3.0
Here's the Assembly Explorer with both libraries loaded. Common items will be highlighted in each, but IClientValidatable wasn't added until later.
And here's the VS 2017 Reference Manager where you can add references based on your current framework, showing the old MVC library for the new .NET version.
So the question then becomes....
Q: How can I add a reference that is not available in the list of assemblies for my framework?
A: Same way you'd add any other reference - you can browse to a dll or grab it from nuget.
DLL If you already have a web app, there are good odds you can find the dll in your existing packages directory at something like:
\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll
If you prefer Nuget, some minor annoyances are that nuget package names don't exactly sync up with the assemblies they install, it's not easy to browse or search which assemblies come with which packages, and they libraries and frameworks often come bundled with other things you might not need. All that said, you'll be looking for the package called:
Microsoft.AspNet.Mvc on Nuget
Which will install the following libraries:
I recently made some unit tests for my Asp.NET MVC application, or I tried to, it keep telling me "The type 'System.Web.Mvc.Controller' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral.' Then I tried to add a reference to the above mentioned, but was only able to choose version 4.0.0.0 and now it tells me that my project already uses version 5.1.0.0, which is a higher version. What to do?
Thanks a bunch!
MVC 5 comes in from a NuGet package. Just as it did with the main MVC web project in your solution. Install MVC via NuGet into your Test project, and you should be good to go.
An educated guess, but you might have obtained the newer version via a nuget package(some of the newer MVC project templates do this), and thus it is not installed in GAC. Use the nuget package manager for the MVC project to determine if this is the case, and if so then mystery solved.
In the test project you can add the same package, or use the addreference->Browse to browse into the nuget dependencies and poke around under the MVC project till you find the DLL(it will be in the file system somewhere under SolutionName/MvcProjectName/packages).
I created project with name Sorama.CustomAuthentication in that project I installed a package called c# CodeFirst Membership Provider via nuGet package manager.
You can see the reference that has been added to this project here
but it is not letting the CodeFirstMembershipProvider class inherit from MembershipProvider.
Error says MembershipProvider could not be found.
What am I missing?
It looks like you added this to a new Class Library project (i.e. not to the MVC project itself)? If so then most of the references they assume exist for the package (that would be in a template MVC project) are missing from your Class Library references.
That particular NuGet (currently at v1.0.0) frankly isn't a great package. It seems to be missing dependencies like EntityFramework and some .NET framework references, so once you get past this one you may have others to add as well, which will probably be:
From Nuget:
EntityFramework.dll, v5.0.0.0 (Install-Package EntityFramework -Version 5.0.0)
From the GAC (i.e. use the Add Reference context menu for the project, and in the dialog search in the Assemblies\Framework list for these names)
System.Web.dll, v4.0.0.0
System.Web.ApplicationServices.dll, v4.0.0.0
System.Configuration.dll, v4.0.0.0
In future you can work this out by asking Visual Studio to build the project, and looking at the build error messages, which will look like:
The type name 'MembershipProvider' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly.
The bit I have highlighted in bold tells you that it thinks the best match for your reference that you need is to System.Web.ApplicationServices, particularly v 4.0.0.0, and gives you the public key token as well.
Be sure to have a reference added to System.Web.ApplicationServices.dll
I am working on an open source project MvcSiteMapProvider getting it ready for deployment. It is a library package that supports MVC2, MVC3, and MVC4 as well as .NET 3.5, .NET 4.0, and .NET 4.5.
Based on Nuget Package: Use Different MVC Version When Available, I have come to the conclusion that I need to make a Nuget package for each version of MVC and let Nuget's internal version detection take care of the different .NET versions, like this:
MvcSiteMapProvider.MVC2
MvcSiteMapProvider.MVC3
MvcSiteMapProvider.MVC4
However, in addition to a library DLL, I have different files (Dependency Injection configuation, MVC DisplayTemplates, etc.) that need to be deployed to the target project. These files MUST NOT be updated when the new version of the main project is updated because they will likely contain end-developer edits that I don't want to overwrite.
So, it is clear that these need to be in their own Nuget packages for this and other reasons. However, these other packages need to depend on the main MvcSiteMapProvider.MVCx projects, just to ensure one of them has been installed.
It doesn't make sense to make a separate Nuget package for each version of MVC for each of these other packages - they are all exactly the same except for this one dependency. Ideally what I would like to do is make a single Nuget package that depends on either MvcSiteMapProvider.MVC2, MvcSiteMapProvider.MVC3, or MvcSiteMapProvider.MVC4 and if none of them are available, install the one that matches the MVC version of the target project, but how would I accomplish this? If that is not possible, what other options do I have than creating large number of Nuget packages (one for each MVC version dependency) that grows exponentially with each new MVC release?
To clarify, I have other Nuget packages like this:
MvcSiteMapProvider.Web
MvcSiteMapProvider.Configuration.Autofac
MvcSiteMapProvider.Configuration.Ninject
MvcSiteMapProvider.Configuration.StructureMap
MvcSiteMapProvider.Configuration.Unity
MvcSiteMapProvider.Configuration.Windsor
I am trying to avoid having to change that to:
MvcSiteMapProvider.MVC2.Web
MvcSiteMapProvider.MVC2.Configuration.Autofac
MvcSiteMapProvider.MVC2.Configuration.Ninject
MvcSiteMapProvider.MVC2.Configuration.StructureMap
MvcSiteMapProvider.MVC2.Configuration.Unity
MvcSiteMapProvider.MVC2.Configuration.Windsor
MvcSiteMapProvider.MVC3.Web
MvcSiteMapProvider.MVC3.Configuration.Autofac
MvcSiteMapProvider.MVC3.Configuration.Ninject
MvcSiteMapProvider.MVC3.Configuration.StructureMap
MvcSiteMapProvider.MVC3.Configuration.Unity
MvcSiteMapProvider.MVC3.Configuration.Windsor
MvcSiteMapProvider.MVC4.Web
MvcSiteMapProvider.MVC4.Configuration.Autofac
MvcSiteMapProvider.MVC4.Configuration.Ninject
MvcSiteMapProvider.MVC4.Configuration.StructureMap
MvcSiteMapProvider.MVC4.Configuration.Unity
MvcSiteMapProvider.MVC4.Configuration.Windsor
Looking at your source code, it seems like you are referencing multiple versions of the Microsoft.AspNet.Mvc package in MvcSiteMapProvider project. I am not sure this is working as you expect it to since there can be only one version of System.Web.Mvc that can be put in the bin folder during the compilation process (the latest version 5.0.0 will be used).
So any code in your package that depends on Mvc V3 or V4 is not really getting the dll it expects.
Since most of the packages you referenced above like Autofac also have integration package that target specific MVC versions,you may not have an option but to split your package into smaller packages like you mentioned in your post.
A better approach to this problem would be to separate the Core functionality provided by your package which does not have dependency on any version of MVC. You can then create different wrapper packages that depend on your core package and also on a specific version of Microsoft.AspNet.Mvc. And create similar packages for each different Configuration has a nuget dependency on third party packages like Autofac (eg Autofac.Mvc5) and its corresponding version of your MvcSiteMapProvider.MvcX package
The type 'System.ComponentModel.DataAnnotations.MaxLengthAttribute'
exists in both
[path...]\packages\EntityFramework.4.3.1\lib\net40\EntityFramework.dll
and
'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework
\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
Now, I have read on msdn that its safe to exclude the EntityFramework reference (which was added through the nuget package). However, when I do that, I cant create a DBContext properly as the DbModelBuilder class lives in the EntityFramework dll. Also, some other critical classes are missing when I remove the EntityFramework refference so this is old and irrelevant solution now.
Update (disambiguation): Both System.ComponentModel.DataAnnotations.dll and EntityFramework.dll include System.ComponentModel.DataAnnotations.MaxLengthAttribute. The problem is that each dll also includes other classes that are critical to EF code-first design. For example:
EntityFramework.dll:
- System.Data.Entity.DbModelBuilder
System.ComponentModel.DataAnnotations.dll:
- System.ComponentModel.DataAnnotations.RegularExpressionAttribute
Add this statement to top of your class
using System.ComponentModel.DataAnnotations;
System.ComponentModel.DataAnnotations namespace is distibuted across the EntityFramework.dll and System.ComponontModel.DataAnnotations.dll. So you need to add a reference to both of that in your project to make use of DataAnnotations.
The MaxLenth attribute is present in EntityFramework.dll. So make sure you have that reference to that dll present in your project references section.
EDIT : As of .NET framework 4.5, this namespace is moved to the System.ComponentModel.DataAnnotations.dll. So If you use .NET Framework 4.5 with Entity Framework 4.3.1 or less, You will run in to this conflict. The solution is to switch to Entity framework 1.50 beta 1/ 2 release if you want to stick with .NET 4.5 or downgrade to .NET 4 to use EntityFramework 4.3.1.
From the msdn documentations.
Starting with Entity Framework 5.0 Beta 1, the EntityFramework.dll
does not contain definitions for data annotations. These definitions
were moved to System.ComponentModel.DataAnnotations.dll and are
defined in the System.ComponentModel.DataAnnotations.Schema namespace.
I didn't have the option of upgrading the project to use EF5, or downgrading the build machine to .Net Framework 4.
There is a way to solve this though! It turns out when you install Visual Studio 2012 it adds the following folder (amongst others).
C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0
In VS if you open a project targetting 4.0 and look at the properties of your reference to System.ComponentModel.DataAnnotations you'll see that the path is pointing to the above location, rather than the GAC.
This folder contains the original Framework 4.0 assemblies. If they're present on the machine then MSBuild etc., upon building a project targeting 4.0 will reference these rather than the modified ones that 4.5 puts into the GAC.
In our case this meant we could fix the problem by copying that folder from a dev machine with VS installed up to our build server in the same location. (N.b. We only needed to copy this folder, there was no need to install VS on the build server).
More info here: http://marcgravell.blogspot.co.uk/2012/09/iterator-blocks-missing-methods-and-net.html
Hope this helps someone else!