-
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
Xamarin Android: Exceptions thrown if SDK Assemblies are linked, after updating all NuGet-Packages #12460
Comments
I have the same issue, works fine in 2.0.3 but not 2.1.0 or 2.1.1. |
I'm seeing the same thing. I don't have a simple repro on hand, but willing to provide access to a private VSTS repo to the right person. |
I have this problem as well, resulting in a too big apk... |
Here is a sample project as requested. Just build it in Release-Mode to install on an Android-Phone and it crashes instantly. Please fix this asap, thank you very much |
im running into the same issue. release apk for google play ends up at ~90mb. eek! proposed solutions didnt work for me, i.e. linkdescription.txt, --skip-link, etc |
@ajcvickers Come on, any reaction.... It's been 2 days since you got a sample project by me and more than two weeks since the Bug has been reported by multiple users. |
??? |
Everyone, sorry for the delay in answering. I have assigned this to @smitpatel and myself. I would like to ask from the people that repro if just running this code throws if you copy it inside your app: var supportedMethods = new Dictionary<MethodInfo, string>
{
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(double) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(float) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(int) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(long) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(sbyte) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Abs), new[] { typeof(short) }), "abs" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(byte), typeof(byte) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(double), typeof(double) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(float), typeof(float) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(int), typeof(int) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(long), typeof(long) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(sbyte), typeof(sbyte) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(short), typeof(short) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(uint), typeof(uint) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Max), new[] { typeof(ushort), typeof(ushort) }), "max" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(byte), typeof(byte) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(double), typeof(double) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(float), typeof(float) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(int), typeof(int) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(long), typeof(long) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(sbyte), typeof(sbyte) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(short), typeof(short) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(uint), typeof(uint) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Min), new[] { typeof(ushort), typeof(ushort) }), "min" },
{ typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double) }), "round" },
{ typeof(Math).GetMethod(nameof(Math.Round), new[] { typeof(double), typeof(int) }), "round" }
}; This is a copy of the code from which the exception is coming. It is creating a dictionary where the key is a MethodInfo. Since it is saying that Abs(int32) is a duplicate key, that means that either Even if the linker is removing some members, that doesn't seem to be an excuse for reflection to start doing fuzzy matching. That said, I am not super familiar with the technology and there could be a reason for this. In any case, I would say that part is an issue in Xamarin/Mono and I would be grateful if you can report it at https://github.com/xamarin/xamarin-android/issues. Re how to workaround this, I would guess that using the options in the linker to skip linking certain assemblies. E.g. as documented in https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/linker?tabs=vsmac, you could either use:
Or a custom link configuration as described at https://docs.microsoft.com/en-us/xamarin/cross-platform/deploy-test/linker. I am not sure what assembly/assemblies you should be excluding to make sure all overoads of Math.Abs are preserved. It could be mscorlib, in which case your LinkDescription.xml file woudl look something like this (I am basing this on @cwrea's sample app LinkDescription.xml file): <assembly fullname="mscorlib">
<type fullname="System.String">
<method name="Compare"></method>
<method name="CompareTo"></method>
<method name="ToUpper"></method>
<method name="ToLower"></method>
</type>
<type fullname="System.Math">
<method name="Abs"></method>
<method name="Max"></method>
<method name="Min"></method>
<method name="Round"></method>
</type>
</assembly>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Expression`1"></type>
<type fullname="System.Linq.Queryable"></type>
</assembly>
</linker> Also, I haven't tried this workaround myself on Xamarin Android, so I am not sure with just specifying the names of the methods in the file is enough to preserve all overloads. Worst case, you may need to specify all the signatures (which is also documented in the previous link). |
@smitpatel could you try to repro this and try the workaround when you have a chance? |
these solutions don't work. trying to skip assemblies is the worst, you keep compiling, marking an assembly/namespace in ef core until you run up against an assembly that just work link correctly and you're stuck after hours of work for nothing. as i recall xamarin pushed this back on ef core team since they have to mark reflection that needs to be kept in source so this doesnt happen. ef core and xamarin are a ms flagship now, and you can't link with the ef assm and end up with a bloated apk on top of the mono framework because of it? this kind of stinks! |
@ainsophical just to double-check, when you say that these solution's don't work, do you mean that you don't think this is the right long term solution or that you tried the workaround and it really didn't work? FWIW, we also don't think that this is the ideal long term solution and that is why #10963 is still open. However all the proposals from Xamarin and experts in that issue are about moving the workarounds to EF Core and potentially all its dependencies. For example, we would ship our own LinkDescription.xml and/or annotate members in EF Core, Microsoft.Extensions.* and .NET Core BCL with PreserveAttribute. If the workaround I suggested doesn't work at all, that is very important to know because it means that this particular issue is caused by a different problem and moving the workarounds into EF Core and its dependencies wouldn't help. |
i've tried everything suggested on the topic from multiple sources including the above. I included my own linkdescription.xml file and started the compile process to see which assem. where getting stripped out during the linking process; the conclusion was that at a certain point i couldnt get ef core to work on my xam. app with linking (sdk / sdk & user assem.) since I was getting an exception for a reference to an assembly despite it being on my xml file. i dont recall the referenced assembly at the moment but it was in the ef namespace. |
I rolled back to 2.03 and work fine with Waiting for the fix now ! |
I found that the issue hasn't been reported to Xamarin so I created dotnet/android#1990. I would suggest everyone that reported the issue here to track that one. |
From dotnet/android#1990 (comment)
@daniels7 @dwaskel @mfeingol @BarretHTW @stddd @ainsophical and anyone that has hit the issue, could you please answer @JonDouglas's question on whether this repros for you using 15.8 Previews 4 or 5? |
Per the previous comment, upgrading to Xamarin.Android 9 fixes this issue. In the meanwhile, downgrading to a previous build of EF Core can serve as a workaround. Closing the issue, since there doesn't seem to be anything actionable on the EF Core side. |
@divega I am targeting Android 9, but this error still appears for me. |
what IDE and version are you using? this problem went away for me a long time ago. |
@ainsophical I am using visual studio 2019 for mac. I was using 2.2.4 version of packages. |
@mister-giga just in case it helps, there was a very similar exception reported becasue the linker removes System.Date. The workaround is described at dotnet/android#2620 (comment). |
If I build a Xamarin Android App with linked SDK Assemblies it will crash after EF Core is Updated to newest version.
Steps to reproduce
I'll try to append a sample project tomorrow, though I somehow have the thought this might be somehow related to Issue #10207 ?
Does anyone have an idea on how to modify the linking behaviour so that the Application will work again? Without linking the resulting apk sadly is 3 times as big as usual.
Further technical details
EF Core version: (found in project.csproj or packages.config) 2.1.1
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10 Pro x64
IDE: (e.g. Visual Studio 2017 15.4) VS 2017 15.7.4
The text was updated successfully, but these errors were encountered: