-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash within designer when using Refit #14282
Comments
There is a difference in implementation between your Yours calls a specific handler, but swallows the exception:
You can get the same Previewer behavior ( |
Good catch! Sounds like the Community Toolkit is not the issue then. I've updated my post accordingly and posted a new example where I rethrow the exception in the catch to replicate the issue with only Avalonia and Refit. |
I think the cause is that |
ReFit seems to call Http stuff, so IO operation. This is not supported in the previewer. Use Design.IsDesignTime to skip the IO stuff in previewer |
private async Task LoadUsersAsync()
{
//var userApi = RestService.For<DesignerCrash.Toolkit.IUserApi>("https://jsonplaceholder.typicode.com");
//var users = await userApi.GetUsers();
using var client = new HttpClient();
UsersString = await client.GetStringAsync(@"https://www.avaloniaui.net");
} |
@stevemonaco I made the change you suggested as a draft PR and tested locally with the |
@mayka-mack I don't know the Previewer / Assembly APIs that well. I was initially concerned about remote code loading, but it appears that LoadFile and LoadFrom have the same behavior in that area (disabled by default) from a quick read. |
Okay, in that case, I have marked the pull request as ready for review. If anyone else has any suggestions to test, I am happy to do them. Thank you very much for helping me track this down! |
Describe the bug
I'm encountering a strange issue when using Avalonia and Refit in tandem. I figured I would start here to get assistance pinpointing which library might be causing the issue.
When using Refit within an Avalonia project, invoking a Refit command crashes the designer in both Visual Studio and Rider.
The specific error I'm getting is
System.InvalidCastException: Unable to cast object of type 'DesignerCrashIUserApi' to type 'DesignerCrash.IUserApi'.
It almost appears like the periods are being stripped from the namespace when Refit is generating its code. Strangely, when running the application normally, everything behaves as expected. So the issue appears limited to the AXAML designer.Interestingly, when I call the Refit method directly and do not wrap it in a command, the crashing did not occur.
Full crash stack trace:
To Reproduce
Steps to reproduce the behavior:
Open the attached solution in Visual Studio or Rider : ExampleSolution.zip
Build the project, then go to
MainWindow.axaml
and open the designer.Within the designer, click on the "Load Users Method" button. The designer will not crash.
Within the designer, click on the "Load Users Command" button. The designer will crash with the
System.InvalidCastException
exception.Environment
Additional context
I did find one reported issue on the Refit GitHub which may be related to what I am seeing, but there was not enough detail provided for the maintainers to determine what would be causing the issue. It doesn't indicate if they were using any external libraries such as Avalonia or MVVM Community Toolkit.
reactiveui/refit#1125
The text was updated successfully, but these errors were encountered: