I am trying to port everything from Entity Framework 6.3 to Entity Framework Core 2.1.2 and this is my first experience with EF Core.
I have 2 projects one is my core or infrastructure project with all the entity models, DB Context and repositories and the other one is an asp.Net MVC which is my startup project and using all the services from the core project. Both projects are using .NetStandard Library 2.0.3 and targeted .Net Framework 4.6.2. And I have .Net Core SDK 2.2 on my machine.
The problem:
1- Converted everything to Entity Framework Core (All the entity mappings, contexts and repositories) and all the stuff seems fine, both projects build successfully.
2- starting first migration targeting existing database and entity models. Now while the migration process building both projects I am getting a strange error on asp.net MVC project as following:
An instance of analyzer
Microsoft.EntityFrameworkCore.RawSqlStringInjectionDiagnosticAnalyzer
cannot be created from
C:\Users\user\.nuget\packages\microsoft.entityframeworkcore.analyzers\2.1.2\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll
: Could not load file or assembly 'Microsoft.CodeAnalysis,
Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The system cannot find the file specified.
3- Now everytime you build the Asp.net project, you get the same error.
I really have no idea about this RawSqlStringInjectionDiagnosticAnalyzer and why this being even used by the projects, I have spent 2 days so far on this problem search all over the Internet, some people experienced somewhat similar problems (like this one) but could not found any solution, some of the stuff that I did was:
Updated my VS to the latest version (15.9.7), no luck
Tried to reference different versions of EF Core including Analyzer for both projects, no luck
I know Microsoft.CodeAnalysis dll should be a VS internal mechanism, nevertheless tried to reference it manually, no luck
Tried to include Microsoft.CodeAnalysis nuget package, no luck
Also there were other packages that I have tried, couldn't remember the names now, no luck
Please help me I am tired of adding and referencing different packages and binaries, I can't even grasp the problem.
I have realized this should be a warning and not an error so I found out that the "Treat warning as error" options in the project settings is enabled so that's reasons I am getting this as an error, however, still do not know the reason behind this warning.
Related
This is going to be one of those questions for which there are hundreds of answers, so please bare with me as I have tried most of them!
I have been breaking up a very large project into smaller components with the view to slowly migrate it all to .NET Core.
Some Projects in my solution are now .NETstandard class libraries, and there are also some .Net Framework (4.7.8) projects.
I was getting on quite well today when suddenly I started getting this:
Could not load file or assembly 'ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The version installed in my projects is (was - read on...) 5.8.0.0
Now, I am not new to this error, I've found it before and it usually relates to either a project reference file, web.config or packages.config referencing a .DLL with a different version than that of the file in the /bin directory.
So I have been through all (34) project folders and deleted servicestack.text.dll in every project.
I have uninstalled it via NuGet in every project and reinstalled it.
I have checked every project's packages.config file and where they are .NETStandard projects, the project files and made sure that there are not references to ServiceStack.Text v 5.0.0.0
I have rebuilt, cleaned and restarted the solution, visual studio and my computer many times!
Then I noticed something...
In my .Net Framework projects, under References, if I click on the ServiceStack.Text file and view the Reference Properties, it shows Version: 5.0.0.0, but the Path is directing it at 5.8.0.0.
In the .NETStandard projects, it shows the correct version.
So then I thought maybe 5.9 can't work in the Framework projects, so I uninstalled it from every project and installed v 5.0.0.0 in every project. This then wouldn't build because Visual Studio threw errors in the .NETStandard projects saying "downgrade detected, please restore the updated version"
SO then I installed 5.9 (which is now the latest version) into all the .NETStandard projects, leaving 5.0.0.0 in the .NET Framework ones.
Now it will build, but the FileNotFound exception throws again when I try to run it.
So I have tried;
Everything using ServiceStack.Text 5.9
Everything using ServiceStack.Text 5.0
.NET Framework projects using 5.0 and .NETStandard (2.0) projects using 5.9
Uninstalling and reinstalling multiple times
Deleting all obj directories, cleaning and rebuilding
Checking all project and packages files
Wasted most of the day on this, so turned to SO... I do hope someone can help!
Right.... Answering my own Question again...
After a lot of messing about I found out what was happening, and it was nothing to do with Visual Studio builds, or .package file conflicts
The reason the error suddenly appeared was a call to Dump() in something I was testing, which had another call to Dump() in a preceding function referencing a different .NET Framework. Whilst according to Microsoft this (mixing Frameworks) works, ServiceStack has different versions and it caused a version conflict.
In case anyone else runs into this, here's what I have found…
Pseudo code example… a function in a .NET Standard Project (2.0)
Function Blah() as Something
… do something
Log(TestResult.Dump())
Return Something
End Function
And then a .NET Framework (4.7.8) Project which consumes this and again tries the Dump the result:
Sub DoSomething()
Dim Something = Blah()
Write(Something.Dump())
End Sub
The two frameworks require different versions of ServiceStack.Text and therefore throw a confusing, though I guess correct, FileNotFoundException in the running project.
I’m sure to run into this one again….!
I have a solution with:
A project that handles business logic through crud functions. At some point the project uses System.Runtime.Caching
Other webforms, MVC and RESTservice projects. (irrelevant to the topic)
A newly created Xamarins.Forms project targeting .netstandard2.0
My problem is that when I reference the business logic project in the Xamarin.forms project then the Xamarin.Android project errors that it can not resolve the reference System.Runtime.Caching referenced by the business logic project.
It suggests that I add a NuGet package or assembly reference for System.Runtime.Caching, or remove the reference to the business logic project.
I have tried installing the package for both the Xamarin.Forms project and the related Xamarin.Android project. But it does nothing.
I am in a bit of halt here since I am unable to figure what the problem is and better yet how to sovle it.
System.Runtime.Caching doesnt seem to be part of .Net standard hence you can not add it .Check the nuget log when you try to add it.
You might be calling web project/API project code directly from xamarin forms, dont do that. You need to isolate the two.
I've created a new project in Visual Studio 2013.2 with WebAPI and MVC enabled. Right out of the box, compiling the generated project and running gives me the exception. Looking around here, I've come across the following two questions:
Mvc 5.1 MissingMethodException System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached
System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached
Both these answers involve assembly redirects; however, in my case the assembly redirects are present and I'm still getting an issue. My problem is that the GAC is loading version 3.00.11001.0 which is listed under assembly version 3.0.0.0 and my application wants 3.20.20520.0 which is also listed as assembly version 3.0.0.0. (Note that in diagnosing the project I installed the 5.2 pre-release nuget package, but I had the same problem with the original versions, I just don't have those readily available)
Since the GAC is preferred over the bin directory, it seems that my development machine will always pull the wrong file.
Is it safe to remove these files from the GAC? It appears that these are required for Visual Studio to produce Razor intellisense
Removing the Assemblies from the GAC did behave exactly as expected. The Razor intellisense for the project stopped working; however, the application began functioning properly.
You have to add the reference of System.Web to get it working.
So I'm trying to take a VS2008 MVC1 project to MVC3.
Here are the steps I'm trying to do.
Use conversion to to convert vs2008 mvc1 to vs 2008 mvc2 (success)
Tool: http://weblogs.asp.net/leftslipper/archive/2010/03/10/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2-rtm.aspx
Open vs2008 sln in vs2010 to convert (failed on my main app project)
Convert from .Net3.5 to .Net 4.0
Use tool to covert to MVC3
On step two, it fails on my main project, and then will not open the project with the error.
The Project <project path> cannot be opened
The project type is not supported by this installation
I found some StackOverflow posts abotu similar issue with RC1 and RC2, but installaed my MVC2 from the webplatform installer and so it should eb the latest, not the RC.
I assume this line is my problme, anyone know how to fix it?
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
I tried posting my csproj, but it excedded the max lines.. if there is a part neede to diagnose this just let me know.
Thanks,
Cal-
Personally I use the following migration path *:
Ensure that I have ASP.NET MVC 3 RTM Tools Update installed
Open the ASP.NET MVC 1.0 project in Visual Studio 2010
The migration wizard kicks in and asks me if I want to convert to .NET 4.0 and I say Yes
Make sure that the System.Web.Mvc assembly referenced in my project is V2.0.0.0. If it is still the old I remove it and add the correct version
At this stage I ensure that I have a working ASP.NET MVC 2.0 application and close Visual Studio.
There is one final step left. For it, depending on my mood, I do one of the following:
Do the migration manually by following the upgrade guide
Use the ASP.NET MVC 3 Project Upgrade Tool
* To answer this question I did the previous steps on a real ASP.NET MVC 1.0 project and it was successfully upgraded to ASP.NET MVC 3
Okay I did it both ways and got the same result.
I did figure it out, here's what was going on. Be aware that steps 1 and 3 are probably all that's needed to fix it, but I'm including step two, both for clarity of my debugging process and completeness in case it's required and my assumptions are false.
Even though MVC# was installed, and showed as installed in the Add removed programs, MVC 3 was not showing up as a reference. I unininstalled, reinstalled and rebooted and it started showing up.
I had to modify the project Type Guids in he CSPROJ file, first I deleted them one at a time till the Main app project was able to load, then I recovnerted. All projects except the main one worked, but it didnt' convert. It did not covnert becuase of an unrecognized project Type Guid.
Becasue it didnt convert I got this error:
The type 'System.Web.Mvc.ViewMasterPage' is ambiguous: it could come from assembly 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Mvc\v4.0_3.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll' or from assembly 'C:\Windows\assembly\GAC_MSIL\System.Web.Mvc\1.0.
Note the Coverted did not throw and error, it merely logged that the project did not get convereted. You have to look at the logs carefully to notice.
Luckily you can run the converter on the same soloution multiple times. that's how I noticed this.
I had to modify the Project Type guids again, because of the unrecognized type guid again. I just created a new MVC3 project and edited the CSPROJ to get the correct type guids.
{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
Note: this is what the guids already looked like, but I copied them from an existing good project and pasted them in the file and it started working, my best guess is there was an invisible character put in there by the conversion process.
After this I reconverted and it worked perfectly, and the errors went away.
Thanks,
Cal-
I want to learn to use Fluent NHibernate, and I'm working in VS2010 Beta2, compiling against .NET 4, but I'm experiencing some problems.
Summary
My main problem (at the moment) is that the namespace FluentNHibernate isn't available even though I've imported all the .dll assemblies mentioned in this guide.
This is what I've done:
1. I downloaded the Fluent NHibernate source from here, extracted the .zip and opened the solution in VS. A dialog asked me if I wanted to convert the solution to a VS2010 solution, so I did.
2. I then went into each project's properties and configured all of them to compile for .NET 4, and built the entire solution.
3. I copied all the .dll files from /bin/Debug/ in the FluentNHibernate to a new folder on my local hard drive.
4. In my example project, I referenced FluentNHibernate.dll and NHibernate.dll from the new folder.
This is my problem:
If I right-click on FluentNHibernate in the References list and select "View in Object Browser...", it shows up correctly.
Now, when I try to create a mapping class, I can't import FluentNHibernate. This code:
using FluentNHibernate.Mapping;
namespace FluentNHExample.Mappings
{
}
generates an error on the using statement, saying
The type or namespace 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?).
The FluentNHibernate assembly is still in the list of References of my project, but if I try to browse the assembly in Object Browser again, it can't be found.
What is causing this?
I also had similar problem.
"Error List" window displayed:
The type or namespace name 'FluentNHibernate' could not be found (are you missing a using directive or an assembly reference?)
But "Output" window was displaying detailed information:
warning MSB3253: The referenced assembly "FluentNHibernate" could not be resolved because it has a dependency on "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
In my case; I had created a console application project which was targeting ".Net Framework 4 Client Profile" by default, so changing to ".Net Framework 4" fixed issue for me.
I'm unable to observe this behavior in my build, could it be related to this problem: Weird override problem with Fluent NHibernate and .NET 4
If so you could try http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/ae4013d711d2e4ad as a potential fix.
Isn't there a better way to fix this problem?
I don't want to reference System.Data.OracleClient. So I shouldn't have to target the full .Net framework if I don't even want that reference.
Can't I target the Client Profile of the .Net framework, but add a compiler warning exception somewhere so that it just skips that warning? I know it won't cause a runtime problem because I don't use Oracle.
I get identical problem which says there's also a dependency on System.Web. Same story, this is for a Windows WPF app, so I don't need System.Web. Can't I just target the Client Profile and somehow convince the compiler to keep going?
Thanks,
Hugh
EDIT: I figured this out! I had to compile NHibernate myself though. Opened the 2.1.2 code in Visual Studio and deleted everything that says "Oracle" or "System.Web" and I ended up getting it to build. I do not have to target the full .Net Framework now.
We had this issue and the issue went away if we removed the obj and bin folder from the project which was referencing the NHibernate using project.
So we have 'project1' which uses NHibernate to produce project1.dll.
'project2' references project1.dll.
Problem resolved if we removed the obj/bin folder from project2.
Can't say why, but our solution now compiles fine.
Mike.