-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception. #25182
Comments
Just realized, this would be better suited under the "Question" type, my apologies for that. Can anyone move it or should I file another issue under the right category? |
What are the previous versions of the packages you upgraded? Something in this code isn't working on iOS: efcore/src/EFCore/Query/QueryableMethods.cs Lines 473 to 476 in cfe1df8
Possibly caused by too much of the assembly getting trimmed at runtime (see also #10963) |
Having same issue.
It happens when I call I followed source code and I can not get it because it should work on both platform, Android and iOS but only Android works. I can find a method named All in Queryable. But why reflection can not find that only in iOS? efcore/src/EFCore/Query/QueryableMethods.cs Lines 478 to 483 in 59ec671
code efcore/src/EFCore/Query/QueryableMethods.cs Lines 839 to 844 in 59ec671
dotnet/runtime System.Linq.Queryable[DynamicDependency("All`1", typeof(Enumerable))]
public static bool All<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
{
if (source == null)
throw Error.ArgumentNull(nameof(source));
if (predicate == null)
throw Error.ArgumentNull(nameof(predicate));
return source.Provider.Execute<bool>(
Expression.Call(
null,
CachedReflectionInfo.All_TSource_2(typeof(TSource)),
source.Expression, Expression.Quote(predicate)
));
} Is there any workaround? |
We ran into this issue with Xamarin but only in iOS Release configuration. Our workaround is to specify some linking skip settings in the iOS Build properties under "Additional mtouch arguments" --optimize=experimental-xforms-product-type --linkskip=System.Core --linkskip=mscorlib |
@JeremyLikness Could you try to repro this? |
@AndriySvyryd I can see if I can replicate it on Windows, but I don't have a Mac. |
I have a mac, I can help out if you have some repro steps to try and play around. |
Sounds good. I will reach out with some details. |
I get the same error message in combination with Xamarin. Is there an update for this in the meantime? Is this error similar with this one: |
@smitpatel @JeremyLikness Any update here? |
/cc @bricelam |
Is there any update on this bug?Are there any updates on this bug yet as I am currently stuck? Since I get exactly the same error I assume the author is also using Xamarin in combination with EF Core / SQLite. If more info is needed, I have simplified a method from my project and pasted it here. private static IEnumerable<T> GetFooKey<T>(int keyKind, Expression<Func<KeyUsage, bool>> filter = null) where T : class, new()
{
using (MobileDbContext ctx = GetMobileDbContext())
{
IQueryable<KeyUsage> query = ctx.KeyUsage.Where(use => use.KeyKind == keyKind);
if (filter != null)
{
query = query.Where(filter);
}
List<T> fooList = new List<T>();
foreach (KeyUsage itemKey in query.OrderByDescending(use => use.UsageCount).Take(20)?.ToList())
{
T item = ctx.Find<T>(itemKey.Id);
if (item is null)
{
ctx.KeyUsage.Remove(itemKey);
}
else
{
fooList.Add(item);
}
}
ctx.SaveChanges();
return fooList;
}
}
|
I continued testing and also installed the latest EF Core version (5.0.11). So far I have changed the linking behavior to |
Until we address issue #21894, we recommend disabling the linker entirely: <PropertyGroup>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup> |
Do I need to set Linking Behavior to |
I have found a solution that does not require disabling the linker. You can look at that workaround here. |
Did it work with |
@MichaelL79 Yes, It does work. But then your application size will be gigant and you may get errors when uploading to the AppStore... |
Hi, I've been able to resolve this issue by telling the linker to skip the I've set the Linking behavior to
|
Thank you michaldivis, that worked well for me. |
File a bug
During the upgrade of a NuGet package, I find myself unable to run my app anymore because of this exception. I am unable to provide a working reproducable sample but I am mostly looking for guidance on what troubleshooting steps I can take to resolve this issue, since it is most probably related to the configuration.
The app in question is a Uno Platform app, and contains a subproject for processing an iOS intent.
Both the iOS and intents project are using
Stack traces
Include provider and version information
EF Core version: 5.0.7
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: Not sure
Operating system: MacOS Big Sur 11.4
IDE: Visual Studio for Mac 8.10.4 (build 11)
The text was updated successfully, but these errors were encountered: