I am using EF6 with Asp.net core and I am getting error when I call to db through dbcontext :
System.NotSupportedException: Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
at System.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderInvariantName(DbProviderFactory factory)
at System.Data.Entity.Infrastructure.DependencyResolution.DefaultInvariantNameResolver.GetService(Type type, Object key)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection)
at System.Data.Entity.Internal.InternalConnection.get_ProviderName()
at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at CoreWithEF.controllers.SampleController.GetStudentDetails() in C:\Users\biradm1\Documents\Visual Studio 2017\Projects\CoreWithEF\CoreWithEF\controllers\SampleController.cs:line 27
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()} System.NotSupportedException
The error Unable to determine the provider name... can indicate the .csproj for the Core project is not set correctly per the instructions on Get Started with ASP.NET Core and Entity Framework 6.
In my case I was working with Core 2.2 project and trying to leverage Entity Framework 6 from .Net Framework 4.7.1 class library, but failed to change the Core .csproj file from <TargetFramework>netcoreapp2.2</TargetFramework> to <TargetFramework>net471</TargetFramework>.
When I finally made the target framework change, the next error to appear was Microsoft.AspNetCore.All 2.2.1 is not compatible with net471 (.NETFramework,Version=v4.7.1). I removed the NuGet Microsoft.AspNetCore.All package, which then created a lot of missing reference build errors.
To resolve the build errors I had to google the missing type to find the assembly name, add that specific NuGet package, rebuild, then keep repeating the process until all of my build errors were resolved.
Every project is different, but here were the packages I had to add to fix my build issues after removing Microsoft.AspNetCore.All:
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
After build issues were resolved and the project built successfully, my DotNet Core 2.2 API was able to return data using Entity Framework 6 from the class library project.
To summarize, the System.NotSupportedException occurred because the generated Entity Framework classes (in the .NET Framework 471 class library) were being accessed by the DotNet Core version of Entity Framework and not the .NET Framework 4.7.1 version of Entity Framework.
Before making the changes listed above, evaluating System.Data.Common.DbProviderFactories.GetFactoryClasses().Rows in the Immediate debug window showed an empty collection of providers. After making the changes, the Factory Classes included the Odbc, OleDb, Oracle, SqlServer providers.
More specifically if you evaluate the rows individually, you should see the providers are from the Full .NET Framework.
For example: System.Data.Common.DbProviderFactories.GetFactoryClasses().Rows[3].ItemArray (for me) showed it came from "System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”.
update both project EntityFramework Package
for example 6.4.4 version
As stated at previous answer: Entity Framework 6 doesn't support .NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.
You can try NHibernate for .Net Core projects.
I try use the WsdlService type provider from FSharp.Data on OSX in a .net core 2.1 console app, and get this error:
../Test.fs(16,16): Error FS3033: The type provider
'FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an
error: The .NET SDK 4.0 or 4.5 tools could not be found (FS3033)
(Sync)
I try to apply the workaround at https://github.com/fsprojects/SQLProvider/tree/master/tests/SqlProvider.Core.Tests/MsSql after read the issue at https://github.com/Microsoft/visualfsharp/issues/3303. This is my project file (simplified):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<ReleaseVersion>0.5</ReleaseVersion>
</PropertyGroup>
<PropertyGroup>
<FscToolPath>/Library/Frameworks/Mono.framework/Versions/Current/Commands</FscToolPath>
<FscToolExe>fsharpc</FscToolExe>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Data" Version="2.4.6" />
<PackageReference Include="FSharp.Data.TypeProviders" Version="5.0.0.6" />
</ItemGroup>
</Project>
Alternatively, what to use for manually do SOAP calls in F#?
Short Answer - Nope it isn't.
This is due to several reasons, the main one being svcutil.exe which the type provider uses to generate the type information. Doesn't generate code that is compatible with the .NET Core WCF libraries Dotnet Wcf. There is a new version of this being worked on but the last I checked it didn't work correctly outside of Visual Studio.
When the above work is completed or at least at a state where it is dependant of Visual Studio shouldn't be too hard to change the current TypeProvider to get it to work on .NET core.
As for actually making SOAP calls I typically use SOAP UI to generate the Envelope and save it it to a local file then just use the XML provider or simple string replacement to fill in the body of the envelop, then send it using a HTTP Client
My question is basically: is it possible to use Entity Framework Core (and migrations) inside a .NET Standard 2.0 library project? (not a core project)
I currently have 2 projects:
ASP.NET Core main project: I don't want anything with databases or EF inside this project, so I added a reference to the .NETstandard2.0 DAL project
.NETStandard2.0 data access layer project: EF Core with database migrations project for accessing the database. The main project uses this project to get data from the database.
For the .NETStandard DAL project, I use the following settings and classes: the .csproj file contains the dependencies for EF and migrations:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
After calling dotnet restore, I created a DbContext descendant:
class MyTestContext: DbContext
{
public MyTestContext(DbContextOptions<MyTestContext> options) : base(options)
{
}
public DbSet<Class1> Class1Table { get; set; }
}
And added a DbContextFactory with IDesignTimeDbContextFactory like:
class DbContextFactory : IDesignTimeDbContextFactory<MyTestContext>
{
public MyTestContext CreateDbContext(string[] args)
{
var builder = new DbContextOptionsBuilder<MyTestContext>();
builder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=efmigrations2017;Trusted_Connection=True;MultipleActiveResultSets=true",
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(MyTestContext).GetTypeInfo().Assembly.GetName().Name));
return new MyTestContext(builder.Options);
}
}
Okay, so far everything works fine and the .NETStandard project builds successfully.
Now I want to create my first migration by executing:
dotnet ef migrations add InitialCreate
This throws an error:
If I understand the error message correctly, EF Core can only be used in .NET Core and .NET Framework projects and NOT in .NETStandard projects?
If that is true, how can I separate the EF database logic from my other applications?
If not, how can I get the migrations to work?
Thank you in advance
You have two options.
One: Use your ASP.NET Core project as the startup project.
dotnet ef migrations add InitialCreate --startup-project ..\MyWebApplication
Two: Cross-target .NET Core in your class library. (Edit the *.csproj)
<PropertyGroup>
<!-- Note: This property name becomes plural. -->
<TargetFrameworks>netcoreapp2.0;netstandard2.0</TargetFrameworks>
</PropertyGroup>
I have a small web application. Which was working fine until I added two genericHandler in my application.
I have made the following changes for the http handler
<system.web>
<authentication mode="Forms" >
<forms protection="All" timeout="720" defaultUrl="Default.aspx" loginUrl="Login.aspx" >
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<!--Code Log Handler-->
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" type="InfoDomeNewUI.Handler.SendOWA" path="SendOWA.ashx" />
<add verb="*" type="InfoDomeNewUI.Handler.SendSOS" path="SendSOS.ashx" />
</httpHandlers>
<customErrors mode="Off">
<error statusCode="404" redirect="Templates/PageNotFound.html" />
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<!--Code Log Handler-->
<add name="LogHandler1" path="SendOWA.ashx" verb="*" type="InfoDomeNewUI.Handler.SendOWA"/>
<!-- SMS SENDER-->
<add name="SendSOS" path="SendSOS.ashx" verb="*" type="InfoDomeNewUI.Handler.SendSOS"/>
</handlers>
</system.webServer>
Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I am using asp.net4.0 and C#. I am not using MVC
On local host it is working fine.
But when I am hosting the published code it is giving me the above error.
Stack Trace:-
[FileNotFoundException: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
System.Web.Http.WebHost.SuppressFormsAuthRedirectModule.Register() +0
[InvalidOperationException: The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +11708830
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +465
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLeve
[HttpException (0x80004005): The pre-application start initialization method Start on type System.Web.Http.WebHost.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11697760
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4866485
It appears that Microsoft.Web.Infrastructure.dll is not being installed in the GAC, even if .net (4.0 or 4.5 or other) are installed successfully on Windows Server. On localhost (typically Windows client), it seems like it is being in the GAC when the tools/platform (Visual Studio etc.) are installed.
As one possible fix, please try the following:
Run the following command in the Package Manager Console. (If you are using Visual Studio, this can be reached via menu options "Tools --> Library Package Manager --> Package Manager Console:)
PM> Install-Package Microsoft.Web.Infrastructure
You will see the following messages if it is successfully installed.
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0.0'.
Successfully added 'Microsoft.Web.Infrastructure 1.0.0.0' to Web.
You will notice that Microsoft.Web.Infrastructure.dll has now been added as a Reference (can be seen in the references folder of your project in in Solution Explorer)
If you look at the properties of this reference you will notice that "Copy Local" has been set to "True" by default.
Now when you "Publish " your project, Microsoft.Web.Infrastructure.dll will be deployed.
I installed MVC4 via WPI and it helped me.
I had the same problem. When I tried the accepted answer (rockyb), I got the message that the package was already installed and assigned to my project. When I checked the references list, it was NOT referenced, however.
The Microsoft.Web.Infrastructure was installed in my solution's packages folder. Instead of using NuGet to add the package, I just used the Add Reference option. On the left side of the pop-up window, I chose Browse, and then pressed the Browse button on the bottom of the window. I navigated to the packages folder under the folder that my solution was in, then drilled down to the ...\mysolution\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40 and clicked on the Microsoft.Web.Infrastructure.dll. After clicking OK, the package showed up in my References list. I used the Web Deploy Package option to deploy my website and everything worked.
Why not copy Microsoft.Web.Infrastructure.dll file manually to the server BIN folder. This works for. My project is VS2010 Website.
This file can be located:
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40
Just copy and paste it in the BIN folder.
You probably need to include this in the web.config if you don't have it already
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
Reference: http://thedeveloperblog.com/
I found the problem. Instead of adding a class (.cs) file by mistake I had added a Web API Controller class which added a configuration file in my solution. And that configuration file was looking for the mentioned DLL (Microsoft.Web.Infrastructure 1.0.0.0).
It worked when I removed that file, cleaned the application and then published.
After installing Microsoft.Web.Infrastructure through Nuget-Package Manager
PM> Install-Package Microsoft.Web.Infrastructure
Copy the Microsoft.Web.Infrastructure.dll manually from the Nuget-Package folder on your web application and then paste it in your bin folder of your web application deployed on the web server.
packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll
It worked for me.
Update-Package -reinstall Microsoft.Web.Infrastructure didn't work for me, as I kept receiving errors that it was already installed.
I had to navigate to the Microsoft.Web.Infrastructure.1.0.0.0 folder in the packages folder and manually delete that folder.
After doing this, running Install-Package Microsoft.Web.Infrastructure installed it.
Note: CopyLocal was automatically set to true.
Sometimes needs to delete the package with force then reinstall it
its works for me.
try delete package
Uninstall-Package Microsoft.Web.Infrastructure -force
then install again
Install-Package Microsoft.Web.Infrastructure
I had the same problem and the "Microsoft.Web.Infrastructure.dll" appeared to be missing. I have tried few advises and installed MVC`s etc. and nothing helped. The solution was to install "Web Services Enhancements (WSE) 1.0 SP1 for Microsoft .NET" which includes Microsoft.Web.Infrastructure.dll.
Available at: http://www.microsoft.com/en-gb/download/details.aspx?id=4065
I had the same problem. I tried installing Visual Studio 2010 SP1 but it didn't worked.
Finally I get Microsoft.Web.Infrastructure.dll from the colleague. You can find the dll into your friends PC where the project is perfectly working. Try to search dll into Temp/Temporary ASP.NET Files. Go to Temp using %temp% into run window.
After getting dll into your pc, just add reference to your project and it will work.
Republishing the site fixed the issue for me.
Was facing the same issue and unfortunately nothing here was working. Finally, I came across this link: https://blogs.msdn.microsoft.com/jjameson/2009/11/18/the-copy-local-bug-in-visual-studio/
Turns out the solution is sort of dumb: set copy-local for the microsoft.web.infrastructure dll to False, then set it back to True.
By the way, I think what is happening is that there are two versions of the microsoft.web.infrastructure dll, one that is pre-installed in the GAC, and another one that is now a nuget package. I think one is masking the other, hence causing issues. In my particular case, on my build server, I need it to be copied over to a folder (this folder is then zipped and sent off to deployment). I guess the system had a copy locally and just thought "nah, it'll be fine"
I have a files only website. Added MVC 5 to webforms application (targeting net45). I had to modify the packages.config
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45"
to
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" developmentDependency="true"
in order for it to startup on local box in debug mode (previously had the top described error). Running VS 2017 on Windows 7...opened through File > Open > Web Site > File (chose root directory outside of IIS).
I had the same problem after upgrading a bunch of NuGet packages.
I have tried all kinds of deleting, cleaning, resintalling described here and beyong to no avail. The references did not have Microsoft.Web.Infrastructure despite the NuGet manager showed it was installed.
The problem was solved by replacing:
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
with
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
in packages.config. The culprit is apparently "net45".
Visual Studio 2022 .net.4.8
I just run this and is solved
you can install this dll using nuget package manager
PM> Install-Package Microsoft.Web.Infrastructure -Version 1.0.0
I just started to work on WebMatrix, I did this tutorial to learn the basic and then I started with this one to get started with Entity Framework on WebMatrix (Note: That tutorial is for WebMatrix 1, but the only thing I see changed was the way you install helpers into your project). The thing is, I installed the Entity Framework helper, but my project doesn't recognize the EntityFramework.dll.
I get this error The type or namespace name 'MaxLength' could not be found (are you missing a using directive or an assembly reference?). But the EntityFramework.dll does appear in my bin folder, what is going on? I don't understand why the reference isn't working.
This is my Web.config file according to the second tutorial and after installing the EntityFramework helper:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /><add assembly="System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></assemblies></compilation>
</system.web>
<connectionStrings>
<add name="BookContext" connectionString="Data Source=|DataDirectory|Books.sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
</configuration>
This is the compiler output link
Am I missing something? Why does the EntityFramework.dll isn't being recognized properly by my project?
UPDATE
I thought the problem was solved when I copied the EntityFramework.dll from a webpage project created in Visual Studio 2012, but even though the errors aren't shown anymore, WebMatrix still doesn't recognize annotations like Table, Column, ForeignKey, InverseProperty, etc.
I really don't understand, a simple database is created but I can't use the EntityFramework annotations to specify all I need for the database. WebMatrix should recognize the EntityFramewor.dll but it is not. I need help in this one because I'm really lost.
The error that you see is the end result of the version of EntityFramework installed on your site.
The EntityFramework 5.0 package installs version 4.4 or 5.0 of the EntityFramework.dll depending on the version of .NET (4.0 or 4.5) that the project is targeting.
In my experience, installing EntityFramework from the NuGet Gallery in WebMatrix always copies version 4.4 of EntityFramework.dll into the bin folder: you can check it looking at Properties --> Details of the EntityFramework.dll file.
The only solution I know is to download EntityFramework v.5.0 using VisualStudio Express or another standalone utility (look at this post: Install Entity Framewok v5 in Webmatrix 2 RC) and simply replace the dll installed by NuGet Gallery in WebMatrix with this one.
UPDATE
Other problems experimented with EntityFramework v.5.0 and WebMatrix are that the type 'System.Data.EntityState' is defined in an assembly that is not referenced and that is needed a using directive for DataAnnotations.Schema.
The first problem is resolved adding the following reference to web.config (look at Could not load file or assembly 'System.Data.Entity):
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
The second problem needs the addition of the directive
using System.ComponentModel.DataAnnotations.Schema;
to the code.
Anyway, in my opinion WebMatrix isn't the right tool for developing a site based on EntityFramework.