Open panthernet opened 2 years ago
UPDATE: Okay not sure by 100% but looks like it happens after I use HOT RELOAD button in VS 2022 to apply changes OR reload happens automatically on code change. I use server-side Blazor for the project.
UPDATE: Confirmed. HOT RELOAD is the bad guy.
THDWebServer (Web server): Hot reload session complete
THDWebServer (Web server): Hot reload session started
THDWebServer (Web server): Sending updates to running application
THDWebServer (Web server): Updates applied successfully
@panthernet Specifically, what changes are you applying with hot reload? For example, are you changing the EF model, the query, something else related to EF, or code not specific to EF at all? It would be great if you could attach a small project that results in this behavior with instructions of what you change under hot reload to make it happen.
@panthernet Specifically, what changes are you applying with hot reload? For example, are you changing the EF model, the query, something else related to EF, or code not specific to EF at all? It would be great if you could attach a small project that results in this behavior with instructions of what you change under hot reload to make it happen.
It happens on every hot reload apply. The changes not related to database. I don't have possibility to create the test project right now. On vacation 🙂
I'm also running into this in a larger web app, but looks pretty easy to reproduce, see attached zipped-up VS Solution...
HotReloadEFCoreLikeIssue (2).zip
...with the main code being in Index.cshtml.cs:
public void OnGet()
{
People = _context.People
.Where(p => EF.Functions.Like(p.EmailAddress, "%@outlook.com"))
.ToList();
// Uncomment below line and save.
//var abc = "def";
}
As prompted above, just uncomment the above line and it should throw the following exception:
System.InvalidOperationException: 'The LINQ expression 'DbSet
(.NET 6's new web app project template without a Startup class threw me for a loop! And it's been a while since I setup a new web app from scratch, so hopefully I set it up correctly)
I am using efcore 3 + postgresql with npgsql that supports translating the Regex.IsMatch
function. Every time a hot reload happens, the query that uses Regex.IsMatch
fails with the same "could not be translated" error. This appears to be any change - adding a character to a string in the same controller, different controller, different unrelated class in a second referenced project all causes the query to fail.
Note from triage: putting this in 7.0 to investigate the experience of EF Core with hot reload.
+1 I have this problem too. I'm using SQL Server and Blazor Server Side and dotnet watch
cli
@ajcvickers: Could this be related to Roslyn, or .NET tooling? In that case, at that time you investigate it, won't it be too late for the the other teams responsible for fixing it? Thanks!
https://github.com/npgsql/efcore.pg/issues/2231 sounds suspiciously close to this as well...
When running hot reload with lazy loading (and nullable reference types, if that's relevant), I sometimes get the error:
System.NotImplementedException: This is a DynamicProxy2 error: The interceptor attempted to 'Proceed' for method 'Microsoft.EntityFrameworkCore.Infrastructure.ILazyLoader get_LazyLoader()' which has no target. When calling method without target there is no implementation to 'proceed' to and it is the responsibility of the interceptor to mimic the implementation (set return value, out arguments etc)
at Castle.DynamicProxy.AbstractInvocation.ThrowOnNoTarget()
at Castle.DynamicProxy.Internal.CompositionInvocation.EnsureValidTarget()
at Castle.Proxies.Invocations.IProxyLazyLoader_get_LazyLoader.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Microsoft.EntityFrameworkCore.Proxies.Internal.LazyLoadingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.DraftJobProxy.get_LazyLoader()
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.ReadPropertyValue(IPropertyBase propertyBase)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.get_Item(IPropertyBase propertyBase)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetIsLoaded(INavigationBase navigation, Boolean loaded)
at Microsoft.EntityFrameworkCore.Query.QueryContext.SetNavigationIsLoaded(Object entity, INavigationBase navigation)
at lambda_method768(Closure , QueryContext , DbDataReader , ResultContext , SplitQueryResultCoordinator )
at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
Once it happens, it happens consistently, but it happens rarely.
I can confirm happening this with Like
on SQL Server and ILike
for Npgsql. Both happen when app is hot reloaded. Makes no difference if change was in C# or template ( cshtml ).
// fails on this query after hot reload
var query = context.Products.Where(p => EF.Functions.ILike(p.ProductCode, productCode)).ToList();
// works on this one
var query = context.Products.Where(p => p.ProductCode.ToLower().Equals(productCode)).ToList();
Also, I noticed it happen when using .OrderBy(_ => EF.Functions.Random())
. Changing to .OrderBy(_ => Guid.NewGuid())
works without hitch.
This happened to me today too. I had to restart the app and it worked.
It happened to me too. in .NET 6 and EF Core v6.0.7
I am using dotnet watch run
. The error comes out randomly upon hot reload, even though the changes are not in the query.
I have to restart the app to make it work.
Is there any news for this issue? I experienced this, always after hot relaod, if using EF.Function.Like. Restarting the app solve the problem. (.NET 6.0.8, EF 6.0.8)
Is there any news for this issue? I experienced this, always after hot relaod, if using EF.Function.Like. Restarting the app solve the problem. (.NET 6.0.8, EF 6.0.8)
I have the same problem, on Blazor Server, restarting the app obviously fixes it, but it's annoying to restart every now and then to see any minor changes. The funny thing is that this code is in a component, and the queries that are executed within it fail, however in the parent component, the queries are executed normally
I'm hitting this issue as well but using EF.Functions.DateDiffDay. Seems to trigger nearly always after a hot reload.
Same here. Any news regarding this issue?
Same here. Using the EF.Functions.Random()
function breaks the query after hot reload.
Restarting the application fixes the issue.
Same issue with hot reload and EF.Functions.ILike usage. The hacky workaround I put in place was to catch the InvalidOperationException and invoke a query without ILike that is similar enough for development purposes, but is not suitable for production.
Got same issue with hot reload and lazy query "Method 'get_LazyLoader' on type 'Castle.Proxies.EventLogProxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is overriding a method that has been overridden." net 6.0 efcore 7.0.5
I still got the issue, VS 2022 17.8.3, Npgsql.EntityFrameworkCore.PostgreSQL 6.0.6
I think I'm also hitting this error, using Blazor WASM with sqlite.
I also have this bug when using hot reload in a MAUI app with EF Core 8.0.4 (but I also tried various other EF Core version down to 5.0.17). I attached a very minicmalistic sample app demonstrating the problem. In this app the problem occurs always after a hot reload.
Of course the suggested workaround 'switch to client evaluation explicitly by inserting a call to ... ToList()' does work, but I'm also using Include(...) to eagerly load navigation properties and this does not work with ToList(). Unfortunately Hot Reload is completely unusable for me and debugging/developing with Maui is quite a pain.
Any help is really appreciated!
https://github.com/dotnet/efcore/assets/77154858/4adb9205-be37-46e0-b6f4-072813904ab5
I also have this bug when using hot reload in a MAUI app with EF Core 8.0.4 (but I also tried various other EF Core version down to 5.0.17). I attached a very minicmalistic sample app demonstrating the problem. In this app the problem occurs always after a hot reload.
Of course the suggested workaround 'switch to client evaluation explicitly by inserting a call to ... ToList()' does work, but I'm also using Include(...) to eagerly load navigation properties and this does not work with ToList(). Unfortunately Hot Reload is completely unusable for me and debugging/developing with Maui is quite a pain.
Any help is really appreciated!
devenv_NRNYiCt721.mp4 MauiApp4.zip
This is exactly what I'm experiencing! I love to use both ef core and hot reload and it's so sad that this is what stopping from getting quick feedback from changes.
@ajcvickers do you think that is something that's easy to fix or is this just a edge case? 😊
@vallgrenerik I think if we were going to work on this, then it would mostly about providing better messages in cases where it doesn't work, such as changing a query.
Have you watched my Video? I'm using Count() on a DbSet and I have not changed this really simple query. I only changed a ContentPage. I think a better message would not help here. Unfortunately EF Core + Hot Reload is completely broken on Maui. I wonder whether this is something that can be fixed by you or by the Hot Reload/.Net guys? Btw: I also tried Net9 preview + EF Core 9. Problem persists...
I've ported my project from v5 to v6 EF Core. Previously everything worked fine but now I'm getting random translation exceptions from
EF.Functions.Like
calls. I monitor the same operation and see the same data coming from input but sometimes it passes fine and sometimes throws an exception.Behavior looks random, I can't understand what's causing it. But I see it is
a cascade failure
. Once one error pops, all queries with LIKE function starts to fail on execution: different tables, not a single one.Call example:
Database
Exception details
Include provider and version information
EF Core version: 6.0.0 Database provider: Microsoft.EntityFrameworkCore.Sqlite 6.0.0 Target framework: .NET 6.0 Operating system: WIn10 x64 21H1 IDE: Visual Studio 2022 17.0.2 Project: Blazor Server-Side