I have a Xamarin Android app that compiles and runs fine in DEBUG mode but won't compile in RELEASE mode.
The error that I'm getting is:
Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.CodeAnalysis.SQLite.Interop.NativeMethods::sqlite3_errmsg(Microsoft.CodeAnalysis.SQLite.Interop.SafeSqliteHandle)' in assembly: 'Microsoft.CodeAnalysis.Workspaces.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue()
--- End of inner exception stack trace ---
at Mono.Linker.Steps.MarkStep.ProcessQueue()
at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
at Mono.Linker.Steps.MarkStep.Process()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
at Xamarin.Android.Tasks.AndroidTask.Execute() MedLemnMobile.Android C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets 366
I've tried "Skip Linking" for Microsoft.CodeAnalysis.Workspaces.dll
I've tried "Skip Linking" for SQLitePCLRaw.core
Neither of the above tries at "Skip Linking" fixed the problem. The app compiles fine if I set Linking to "None", but that is not recommended for RELEASE mode.
Any help would be greatly appreciated.
2/22/2021 - I turned up the verbosity on the Build Output and did a search for System.String. Here's what I found:
Activator call 'System.Object System.Reflection.Assembly::CreateInstance(System.String)' inside 'System.ValueTuple`2<System.Int32,System.Reflection.MethodInfo> CompilerClassLibNETStandard.Compiler::CompileInMemory(System.String)' is not yet supported (TaskId:466)
5> Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'Xamarin.Forms.BindableProperty Xamarin.Forms.VisualElement::Xamarin.Forms.StyleSheets.IStylable.GetProperty(System.String,System.Boolean)' was detected with argument which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Void MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)' was detected with type name `MedLemnMobile.Classes.` which can't be resolved. (TaskId:466)
5> Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Void MedLemnMobile.ViewModels.GraphViewModel::MethodBeginModeReduce(System.String)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5> Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::set_IsValid(System.Boolean)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5> Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::a(System.Collections.Generic.List`1<System.String>)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5> Expression call 'System.Linq.Expressions.MemberExpression System.Linq.Expressions.Expression::Property(System.Linq.Expressions.Expression,System.Reflection.MethodInfo)' inside 'System.Void MedLemnMobile.ValidRules.ValidatableObject`1::set_Value(T)' was detected with 2nd argument which cannot be analyzed (TaskId:466)
5> Activator call 'System.Object System.Activator::CreateInstance(System.Type,System.Object[])' inside 'System.Void MedLemnMobile.Classes.Utils/a::MoveNext()' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Object Xamarin.Forms.BindablePropertyConverter::ConvertFromInvariantString(System.String)' was detected with type name `Xamarin.Forms.` which can't be resolved. (TaskId:466)
5> Expression call 'System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression::Call(System.Linq.Expressions.Expression,System.Reflection.MethodInfo,System.Linq.Expressions.Expression,System.Linq.Expressions.Expression)' inside 'System.Void MedLemnMobile.Behaviors.EventToCommandBehavior::a(System.Reflection.EventInfo,System.Object,System.Action`2<System.Object,System.EventArgs>)' was detected with 1st argument which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Java.Interop.__TypeRegistrations::Lookup(System.String[],System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Reflection.MethodInfo System.Reflection.RuntimeReflectionExtensions::GetRuntimeMethod(System.Type,System.String,System.Type[])' inside 'System.String Humanizer.EnumHumanizeExtensions::GetCustomDescription(System.Reflection.MemberInfo)' does not use detectable instance type extraction (TaskId:466)
5> Reflection call 'System.Reflection.MethodInfo System.Reflection.RuntimeReflectionExtensions::GetRuntimeMethod(System.Type,System.String,System.Type[])' inside 'System.String Humanizer.EnumHumanizeExtensions::GetCustomDescription(System.Reflection.MemberInfo)' does not use detectable instance type extraction (TaskId:466)
5> Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'System.Void Microsoft.CodeAnalysis.CSharp.Shared.Lightup.NullableSyntaxAnnotationEx::.cctor()' does not use detectable instance type extraction (TaskId:466)
5> Reflection call 'System.Reflection.FieldInfo System.Type::GetField(System.String,System.Reflection.BindingFlags)' inside 'System.Void Microsoft.CodeAnalysis.CSharp.Shared.Lightup.NullableSyntaxAnnotationEx::.cctor()' does not use detectable instance type extraction (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String,System.Boolean)' inside 'System.Type Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Boolean Roslyn.Utilities.UICultureUtilities::TryGetCurrentUICultureSetter(System.Action`1<System.Globalization.CultureInfo>&)' was detected with type name `System.Globalization.CultureInfo, System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a` which can't be resolved. (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Roslyn.Utilities.ObjectReader::ReadType()' was detected with argument which cannot be analyzed (TaskId:466)
5> Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Object Microsoft.DiaSymReader.SymUnmanagedFactory::CreateObject(System.Boolean,System.Boolean,System.Boolean,System.String&,System.Exception&)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5> Activator call 'T System.Activator::CreateInstance()' inside 'T Microsoft.CodeAnalysis.DecodeWellKnownAttributeArguments`3::GetOrCreateData()' is not supported (TaskId:466)
5> Activator call 'T System.Activator::CreateInstance()' inside 'T Microsoft.CodeAnalysis.EarlyDecodeWellKnownAttributeArguments`4::GetOrCreateData()' is not supported (TaskId:466)
5> Activator call 'T System.Activator::CreateInstance()' inside 'System.Void Microsoft.CodeAnalysis.Diagnostics.AnalysisState/BlockAnalyzerStateData`2::.ctor()' is not supported (TaskId:466)
5> Activator call 'System.Object System.Activator::CreateInstance(System.Type)' inside 'System.Collections.Immutable.ImmutableArray`1<TExtension> Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference/Extensions`1::GetAnalyzersForTypeNames(System.Reflection.Assembly,System.Collections.Generic.IEnumerable`1<System.String>,System.Boolean&)' was detected with 1st argument expression which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String)' inside 'System.Type Roslyn.Utilities.ObjectReader::ReadType()' was detected with argument which cannot be analyzed (TaskId:466)
5> Reflection call 'System.Type System.Type::GetType(System.String,System.Boolean)' inside 'System.Type Roslyn.Utilities.ReflectionUtilities::TryGetType(System.String)' was detected with argument which cannot be analyzed (TaskId:466)
5> Activator call 'T System.Activator::CreateInstance()' inside 'System.Void Roslyn.Utilities.IDictionaryExtensions::MultiAdd(System.Collections.Generic.IDictionary`2<TKey,TCollection>,TKey,TValue)' is not supported (TaskId:466)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: Mono.Linker.MarkException: Error processing method: 'System.String Microsoft.CodeAnalysis.SQLite.Interop.NativeMethods::sqlite3_errmsg(Microsoft.CodeAnalysis.SQLite.Interop.SafeSqliteHandle)' in assembly: 'Microsoft.CodeAnalysis.Workspaces.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.String SQLitePCL.raw::sqlite3_errmsg(SQLitePCL.sqlite3)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: --- End of inner exception stack trace ---
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.Process()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Mono.Linker.Pipeline.Process(LinkContext context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Xamarin.Android.Tasks.LinkAssemblies.RunTask()
5>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\Android\Xamarin.Android.Legacy.targets(366,5): error XALNK7000: at Xamarin.Android.Tasks.AndroidTask.Execute()
5>Done executing task "LinkAssemblies" -- FAILED. (TaskId:466)
5>Done building target "_LinkAssembliesShrink" in project "MedLemnMobile.Android.csproj" -- FAILED.: (TargetId:492)
SUCCESS! I got it to work as follows:
1.) I discovered that setting Linking to "Sdk and User Assemblies" got the app to build OK, but then, when it ran, the user interface didn't behave well.
2.) So then, I added to my "Skip Linking" list, the name of my main Xamarin.Forms shared-code project.
And, thank goodness, that got it to build and run cleanly!