AppModelv2-NativeClient-DotNet icon indicating copy to clipboard operation
AppModelv2-NativeClient-DotNet copied to clipboard

Runtime errors while runnning this project

Open ghost opened this issue 4 years ago • 3 comments

Hello, I'm using VS2019 and I wanted to learn how to setup Azure AD with my web API. Here's a summary of what I had to do different to make it compile and work:

  • TodoListclient MainWindow.xaml.cs L42-43 (Remove the todo: in the AppConfig parameters)
  • TodoListclient MainWindow.xaml.cs L227: Grabbing from the text fiend caused a crash due to threads on run time, so I just hardcoded "test" for now, but I'm sure you can do better. :)
  • Nuget: Newtonsoft.json, align todolistclient and todolistservice to version 12.0.3
  • Nuget: Upgrade all Microsoft.Asp* to 5.2.7

It took me a few hours to sort this out, but nonetheless the README.md was good.

Thanks!

ghost avatar Apr 21 '20 20:04 ghost

To add to @yell0wc0w2's comments. Yes to point 1, 3 and 4.

Regarding point 2, I usually use MVVM and ICommand (or similar) but to resolve the code "as is" for the InvalidOperation regarding the code executing on a different thread, a quick fix is to change the following line:

var todoItem = new TodoItem() { Title = ToDoText.Text };

to:

`var title = string.Empty;

Dispatcher.Invoke(() =>
{
    title = TodoText.Text;
 });

var todoItem = new TodoItem() { Title = title };`

Not ideal but better than hardcoding a value and still don't understand how so many small glitches were left in there!

tfierens avatar Jun 13 '20 00:06 tfierens

Ok,

The System.InvalidOperationException: 'The calling thread cannot access this object because a different thread owns it. does not occur because of this line:

var todoItem = new TodoItem() { Title = ToDoText.Text };

It is actually due to the fact that the todo: causes both TodoListScope and TodoListBaseAddress variables to be null and causes other problems! Removing the todo: actually takes care of the problem.

tfierens avatar Jun 13 '20 00:06 tfierens

Hey thanks for coming back to me! Glad you were able to sort it out quickly. :)

ghost avatar Jun 13 '20 02:06 ghost