Download, extract, and load the sample solution in Visual Studio 15.7.3:
AndroidEFCore21LinkedSoln.zip
Note: This is the same sample solution as I created for https://github.com/xamarin/xamarin-android/issues/1769 (now closed, fixed in 15.7.3) except I modified the project's Debug configuration AndroidLinkMode setting from None to SdkOnly.
Build the project.
The project should build and deploy to device.
The build fails at the linker stage, with the following error:
Xamarin.Android.Common.targets(1812,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly.
Xamarin.Android.Common.targets(1812,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.ReadOnlySpan`1<System.Char> Microsoft.Extensions.Primitives.StringSegment::AsSpan()' in assembly: 'Microsoft.Extensions.Primitives.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.ReadOnlySpan`1<System.Char> System.MemoryExtensions::AsSpan(System.String,System.Int32,System.Int32)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue()
Xamarin.Android.Common.targets(1812,5): error MSB4018: --- End of inner exception stack trace ---
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessQueue()
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process()
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Mono.Linker.Pipeline.Process(LinkContext context)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute()
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
Xamarin.Android.Common.targets(1812,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
FWIW, if you were to downgrade the Microsoft.EntityFrameworkCore.Sqlite package to 2.0.3, which no longer indirectly depends on System.Memory 4.5, then the project builds and is deployed to device.
Microsoft Visual Studio Community 2017
Version 15.7.3
VisualStudio.15.Release/15.7.3+27703.2026
Microsoft .NET Framework
Version 4.7.02556
Installed Version: Community
Visual C++ 2017 00369-60000-00001-AA398
Microsoft Visual C++ 2017
Add New File 3.5
The fastest and easiest way to add new files to any project - including files that start with a dot
Application Insights Tools for Visual Studio Package 8.12.10405.1
Application Insights Tools for Visual Studio
ASP.NET and Web Tools 2017 15.0.40522.0
ASP.NET and Web Tools 2017
ASP.NET Core Razor Language Services 15.7.31476
Provides languages services for ASP.NET Core Razor.
ASP.NET Web Frameworks and Tools 2012 4.0.21208.0
For additional information, visit https://www.asp.net/
ASP.NET Web Frameworks and Tools 2017 5.2.60419.0
For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 15.0.40424.0
Azure App Service Tools v3.0.0
C# Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
CodeMaid 10.4.53
CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, R, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
JavaScript Language Service 2.0
JavaScript Language Service
JavaScript Project System 2.0
JavaScript Project System
JavaScript UWP Project System 2.0
JavaScript UWP Project System
JetBrains ReSharper Ultimate 2017.2.2 Build 109.0.20171006.122324
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright 漏 2018 JetBrains, Inc.
Merq 1.1.19-rc (a4ffc1b)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.
Microsoft Continuous Delivery Tools for Visual Studio 0.3
Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers
Microsoft Visual C++ Wizards 1.0
Microsoft Visual C++ Wizards
Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
Microsoft Visual Studio VC Package 1.0
Microsoft Visual Studio VC Package
Mono Debugging for Visual Studio 4.10.5-pre (ab58725)
Support for debugging Mono processes with Visual Studio.
Node.js Tools 1.4.11027.3
Adds support for developing and debugging Node.js apps in Visual Studio
NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
Open Command Line 2.1.212
Opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files.
ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info
ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info
Search in Velocity by Silverlake Software LLC 0.7.1
Provides a command to search in Velocity the offline documentation and docset viewer for Windows
SQL Server Data Tools 15.1.61804.210
Microsoft SQL Server Data Tools
SQLite & SQL Server Compact Toolbox 4.7
SQLite & SQL Server Compact Toolbox adds scripting, import, export, rename, query execution and much more to SQL Server Compact & SQLite Data Connections.
Syntax Visualizer 1.0
An extension for visualizing Roslyn SyntaxTrees.
TypeScript Tools 15.7.20419.2003
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 2.8.3-beta6-62923-07. Commit Hash: 7aafab561e449da50712e16c9e81742b8e7a2969
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 2527e6829ecdc8281ee60d83be8cfd0fa720a648.
Microsoft Visual F# Tools 10.1 for F# 4.1
Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
Visual Studio Tools for Universal Windows Apps 15.0.27703.2026
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
VSColorOutput 2.5.1
Color output for build and debug windows - http://mike-ward.net/vscoloroutput
Windows Machine Learning Generator Extension 1.0
Windows Machine Learning Visual Studio Extension Detailed Info
Xamarin 4.10.10.1 (f1760154c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin Designer 4.12.1 (f3257e429)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
Xamarin.Android SDK 8.3.3.2 (HEAD/dffc59120)
Xamarin.Android Reference Assemblies and MSBuild support.
Xamarin.iOS and Xamarin.Mac SDK 11.12.0.4 (64fece5)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
adb logcat output is not applicable as the app didn't even build.
Thanks for creating this issue. I'm seeing the exact same problem here.
@cwrea @mfeingol
With VS Windows 15.7.4 I was able to get the sample project to build after installing the System.Memory and System.Buffers NuGet packages:
<PackageReference Include="System.Buffers" Version="4.5.0" />
<PackageReference Include="System.Memory" Version="4.5.1" />
Now I don't know if the resulting app _works_ at runtime. Can you give this a try?
I think part of the problem here was the bad error message. Using latest master we have improved this, it says:
error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.Extensions.Primitives`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.Extensions.Primitives`.
Next, it should tell you to add System.Buffers after System.Memory has been added.
Thanks, Jonathan. I'll test that out tonight.
Technically speaking, shouldn't System.Memory automatically bring in System.Buffers without us needing to add it manually?
After looking into this, it appears that transitive dependencies for <PackageReference /> aren't always working in Xamarin.Android projects...
Somewhat related to: https://github.com/NuGet/Home/issues/4488
Reviewing the binary build log after _only_ adding System.Memory, I don't see anything that would allow Xamarin.Android MSBuild tasks to find and locate System.Buffers... It is not in the log anywhere until I hit the failure...
But! it is in my obj\project.assets.json:
"System.Buffers/4.4.0": {
"type": "package",
"compile": {
"ref/netstandard2.0/_._": {}
},
"runtime": {
"lib/netstandard2.0/System.Buffers.dll": {}
}
},
I am wondering if this a behavior of using non-SDK-style projects. Perhaps it would work properly if Xamarin.Android supported SDK-style projects? (the new project system)
Well, my project now builds after updating EF and its many dependencies to 2.1.1. Debug configuration runs fine, release configuration crashes on startup.
Since the release configuration tends to not be debuggable, I changed my debug configuration to resemble the release configuration by setting AndroidLinkMode=SdkOnly and AndroidUseSharedRuntime=false. This reproduced the following unhandled exception on startup:
Unhandled Exception:
System.ArgumentException: type
Parameter name: Type is not derived from a java type.
This is in the following code:
[Activity(Label = "MyAppName", Icon = "@drawable/icon", Theme = "@style/splashscreen", MainLauncher = true, NoHistory = true)]
public class SplashScreenActivity : AppCompatActivity
{
protected override void OnResume()
{
base.OnResume();
StartActivity(typeof(MainActivity)); // CRASHES HERE
}
}
I'm not 100% sure this is what's happening with the release configuration, or how this relates to EF 2.1.1, or what could even cause this exception, but there you go.
@mfeingol try nuking your bin and obj directories and uninstalling the app. (We are also working on fixing these type of "DeleteBinObj" issues)
Also, I would just run the Release app and view the Android ADB log instead of modifying your Debug configuration. It _should_ give you some kind of error message.
Just a heads up that I had been seeing this error and just tried the new preview 3 release of 15.8 (windows). I don't get the related errors anymore and I can run and deploy using latest EF 2.1.1 release nugets. Hope that helps someone. I have to stay on 15.8 Pre3 now because I was "ef blocked" on both Android and iOS builds.
As for @dgerding's success, I think there are a couple PRs in 15.8 that help with this issue:
I'm going to close this for now. @cwrea feel free to reopen if you have an update!
@mfeingol can you post a new issue about your crash? It seems somewhat unrelated to the original issue.
@jonathanpeppers: good call on the Android log. I don't use that enough.
Looks like it's an exception during EF initialization. Looks to be https://github.com/aspnet/EntityFrameworkCore/issues/12460 so I'll be heading off there. Thanks for the help.
Time Device Name Type PID Tag Message
06-27 19:03:38.486 nexus_5x Info 11012 MonoDroid System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Sqlite.Query.ExpressionTranslators.Internal.SqliteCompositeMethodCallTranslator' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Sqlite.Query.ExpressionTranslators.Internal.SqliteMathTranslator' threw an exception. ---> System.ArgumentException: An item with the same key has already been added. Key: Int32 Abs(Int32)
at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException (System.Object key) [0x00006] in <a526d941c6244d2aafc7abb28a239ca6>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000ad] in <a526d941c6244d2aafc7abb28a239ca6>:0
at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <a526d941c6244d2aafc7abb28a239ca6>:0
at Microsoft.EntityFrameworkCore.Sqlite.Query.ExpressionTranslators.Internal.SqliteMathTranslator..cctor () [0x000f6] in <135a24207446461281bfc2c90f71e590>:0
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Sqlite.Query.ExpressionTranslators.Internal.SqliteCompositeMethodCallTranslator..cctor () [0x00016] in <135a24207446461281bfc2c90f71e590>:0
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.MonoCMethod.InternalInvoke(System.Reflection.MonoCMethod,object,object[],System.Exception&)
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in <a526d941c6244d2aafc7abb28a239ca6>:0
Most helpful comment
Thanks for creating this issue. I'm seeing the exact same problem here.