Closed adamhill closed 7 years ago
Hi @adamhill ,
Thank you for bringing the issue to attention. :sunglasses:
You're right. Bogus is not compatible with Xamarin at the moment. I think I tried Xamarin some time ago and ran into the same issue with as you've described above. I've just been too lazy to fix the problem because it's not an immediate need of mine in my current projects.
I suspect the crux of the issue is we're missing an explicit build target for profile259/xamarin
in our build process. Additionally, there might be some .NET cross-platform reflection APIs that probably need some tweaking to be fully compatible with Xamarin.
There are a few ways we can proceed to get this resolved:
Some helpful guidelines on modifying Bogus' source:
build clean
before sending in a PR.build test
to ensure all tests pass.Please let me know how you'd like to proceed.
Also, just as a heads-up (no offense) I'll be closing this issue if we don't have a path forward because I'm OCD w.r.t unresolved-open issues in GitHub that might linger on for years. IMHO, GitHub issues are like trying to get to Inbox :mailbox_with_no_mail: zero! Hehe.
Thanks, Brian
:car: :blue_car: "Let the good times roll..."
Hey @adamhill ,
FYI. Latest release v17 (compiled against .NET Standard 2.0) appears to run on Xamarin Mobile now:
Here's how I got it working:
BougsApp1
).BougsApp1
).BogusApp1
) in your *.Android
project.Here's a screenshot and XAML samples that I used to get it working:
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:BogusApp1"
x:Class="BogusApp1.MainPage">
<StackLayout>
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblName" />
<Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblAge" />
<Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblEmail" />
<Label Text="Korean Lorem:" VerticalOptions="Center" HorizontalOptions="Center" />
<Label Text="" VerticalOptions="Center" HorizontalOptions="Center" x:Name="lblLorem" />
<Button Clicked="Button_OnClicked" Text="Generate Random Stuff" x:Name="cmdButton"></Button>
</StackLayout>
</ContentPage>
Mainpage.xaml.cs
using System;
using Bogus;
using Bogus.DataSets;
using Xamarin.Forms;
namespace BogusApp1
{
public class Person
{
public string FirstName { get; set; }
public string LastName;
public int Age;
public string Email { get; set; }
}
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_OnClicked(object sender, EventArgs e)
{
var personFaker = new Faker<Person>()
.RuleFor(p => p.FirstName, f => f.Person.FirstName)
.RuleFor(p => p.LastName, f => f.Person.LastName)
.RuleFor(p => p.Age, f => f.Random.Int(18, 38))
.RuleFor(p => p.Email, f => f.Person.Email);
var fakePerson = personFaker.Generate();
this.lblName.Text = $"{fakePerson.FirstName} {fakePerson.LastName}";
this.lblAge.Text = $"Age: {fakePerson.Age}";
this.lblEmail.Text = $"{fakePerson.Email}";
var koLorem = new Lorem("ko");
this.lblLorem.Text = $"{koLorem.Sentence(3, 2)}";
}
}
}
Is there any version of Bogus that is compatible with PCL Profile 259 in Xamarin? I tried all the way up to 7.1.2, which is the one just before .NET Core support was official. I always get:
Could not install package 'Bogus 7.1.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259'
when I try to add the the Nuget package.
Even though the Dependency is .NET 4.0 and 259 is Version=4.5 shouldn't I be able to add it? I thought dependencies were always >= <X.X>
Thanks.