1

Yesterday I've downloaded the new version of Xamarin.Android which was 4.6.2. When I tried to build my project which correctly worked in previous versions (<4.6) now I get the following error:

(sorry it's in Russian)

Ошибка  1   непредвиденная ошибка при выполнении задачи "LinkAssemblies".
System.ArgumentOutOfRangeException: Заданный аргумент находится вне диапазона допустимых значений.
в Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
в Mono.Cecil.Mdb.MdbReader.ReadLocalVariables(MethodEntry entry, MethodBody body, Scope[] scopes)
в Mono.Cecil.Mdb.MdbReader.Read(MethodBody body, InstructionMapper mapper)
в Mono.Cecil.Cil.CodeReader.ReadMethodBody()
в Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
в Mono.Cecil.MethodDefinition.<get_Body>b__2(MethodDefinition method, MetadataReader reader)
в Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
в Mono.Cecil.MethodDefinition.get_Body()
в Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
в Mono.Linker.Steps.MarkStep.ProcessQueue()
в Mono.Linker.Steps.MarkStep.Process()
в Mono.Linker.Steps.MarkStep.Process(LinkContext context)
в Mono.Linker.Pipeline.Process(LinkContext context)
в MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
в Xamarin.Android.Tasks.LinkAssemblies.Execute()
в Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
в Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() AndroidApplication7

Text in russian means:

Error 1 Unexpected error while trying to execute task "LinkAssemblies".
System.ArgumentOutOfRangeException: Provided argument is out off range

I've spent a lot of time trying to understand this bug and found that the bug appears when (both):

  1. using Android.Support.V4 lib
  2. building with linking mode set to Full

So, I think this is the Linker bug connected with the Support Library. No matter what class or namespace of Android.Support.V4 is used the bug appears instantly.

Trying to make things clear I've made a sample project with one FragmentActivity and one DialogFragment nothing else. And I've reproduced this issue on it!

I want to know is there whether the temporary or instant solution to this breaking issue? This is very important, cause this freezes our development process. Yes, I know that this issue was posted to bug-tacker https://bugzilla.xamarin.com/show_bug.cgi?id=7946

Here is how I made my Sample Project.

  1. Pressed "New project" in Visual Studio 2012 and selected "Android Application"
  2. Changed "Minimum Android to target" to 1.6
  3. Set "Configuration properties" "Linking" to "Sdk and User Assemblies"
  4. Added reference to Android.Mono.Support.V4
  5. Added\Changed two source files

Activity1:

public class Activity1 : FragmentActivity
{
    int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);

        button.Click += delegate { button.Text = string.Format("{0} clicks!", count++);
                                     DialogFragment messageFragment = MyDialogFragment.GetInstance();
                                     messageFragment.Show(SupportFragmentManager, "MessageDialog");
        };
    }
}

MyDialogFragment:

 public class MyDialogFragment : DialogFragment
 {
    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }

    public static MyDialogFragment GetInstance()
    {
        return new MyDialogFragment();
    }

    public override Dialog OnCreateDialog(Bundle savedInstanceState)
    {
        var builder = new AlertDialog.Builder(Activity);
        builder.SetMessage("Message");
        builder.SetPositiveButton("Ok", (sender, args) => { });

        return builder.Create();
    }

}

I think anyone can reproduce it. If not please comment on what you've done.

Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76

1 Answers1

0

There is a linker issue with Xamarin.Android 4.6.2, the workaround is to do the following:

backup and edit /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets

remove all references to CopyMdbFiles

That info is via Jon P, a Xamarin Engineer

If you don't want to do that hackiness you can just downgrade to 4.6 for now until a fix is released (should be in the next couple of days). I have verified that 4.6 does not have this issue (well, my app builds with Release config when building with 4.6 at least).

Hope that helps.

Brett Duncavage
  • 2,163
  • 14
  • 16