Skip to content

PlatformNotSupportedException using BenchmarkDotNet nuget package in Xamarin.iOS #1430

Closed
@leelatoo

Description

@leelatoo

Hi,

I have created a Xamarin.Forms app, Included BenchmarkDotNet(0.12.1) nuget package in shared project. Included a Helper.cs which has the following method to trim url string

using System;
using BenchmarkDotNet.Attributes;
public class Helper
 {
      [Benchmark]
      public string TrimImageUrl()
       {
            string ImageUri = "https://images.pexels.com/photos/548084/pexels-photo-548084.jpeg?vfhsdv8bhbhsfdhbsfbnbhegryw";
            var sub = ImageUri.Split('?');
            return sub[0];
      }
}

I want to benchmark the above function. So I have included a button 'Run' in MainPage.xaml, and the clicked event is handled in code behind file MainPage.xaml.cs is as follows.

    async void Run_Clicked(Object sender, EventArgs e)
    {
            SetIsRunning(true);
            try
            {
                var logger = new AccumulationLogger();
                await Task.Run(() =>
                {
                    var summary = BenchmarkRunner.Run<Helper>();
                    MarkdownExporter.Console.ExportToLog(summary, logger);
                    ConclusionHelper.Print(logger,
                            summary.BenchmarksCases
                                   .SelectMany(benchmark => benchmark.Config.GetCompositeAnalyser().Analyse(summary))
                                   .Distinct()
                                   .ToList());
                });
                SetSummary(logger.GetLog());
            }
            catch (Exception exc)
            {
                await DisplayAlert("Error", exc.Message, "Ok");
            }
     }

Expected Output:

Clicking on the Run button should give Performance summary of the function 'TrimImageUrl()' as text.

Actual output:

Clicking on the Run button lead to an exception.

{System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Console.add_CancelKeyPress (System.ConsoleCancelEventHandler value) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System/Console.cs:944

Can you please help me in getting it solved?

Thanks
Leela

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions