I've been trying to utilize a file that I have on my PC in Xamarin.Forms and after some error fixing and researching I learnt that you cannot reference it locally but have to embed it into Xamarin as a resource. I've done so by accessing the file with Stream and now I would like to convert that Stream into a string using StreamReader. Now I get a Value cannot be null parameter:stream
error.
namespace AimlTest { // Learn more about making custom code visible in the Xamarin.Forms previewer // by visiting https://aka.ms/xamarinforms-previewer [DesignTimeVisible(true)] public partial class MainPage : ContentPage { public SimlBot chatbot; public MainPage() { InitializeComponent(); chatbot = new SimlBot(); var assembly = IntrospectionExtensions.GetTypeInfo(typeof(MainPage)).Assembly; Stream stream = assembly.GetManifestResourceStream("AimlTest.Knowledge.simplk"); StreamReader reader = new StreamReader(stream); string file = reader.ReadToEnd(); var packageString = File.ReadAllText(file); chatbot.PackageManager.LoadFromString(packageString); } private void Button_Clicked(object sender, EventArgs e) { var result = chatbot.Chat(UserEntry.Text); BotEntry.Text = string.Format("User: {0}\nBot: {1}\n{2}", UserEntry.Text, result.BotMessage, BotEntry.Text); UserEntry.Text = string.Empty; } } }
And yes, I have set my file to an EmbeddedResouce
At this point, I believe I may have a bug.