Avalonia项目在OpenKylin运行踩坑
本篇博客记录OpenKylin开源操作系统中运行Avalonia项目遇到的各种问题,会一直更新,最新的内容请点击文末的链接跳转到我的博客原文地址查看。
1.Default font family name can't be null or empty
报错内容:
Unhandled exception. System.InvalidOperationException: Default font family name can't be null or empty.
at Avalonia.Media.FontManager..ctor(IFontManagerImpl platformImpl) in /_/src/Avalonia.Base/Media/FontManager.cs:line 37
at Avalonia.Media.FontManager.get_Current() in /_/src/Avalonia.Base/Media/FontManager.cs:line 59
at Avalonia.AppBuilder.<>c__DisplayClass61_0.<ConfigureFonts>b__0(AppBuilder appBuilder) in /_/src/Avalonia.Controls/AppBuilder.cs:line 256
at Avalonia.AppBuilder.SetupUnsafe() in /_/src/Avalonia.Controls/AppBuilder.cs:line 310
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 219
at TerraMours.Chat.Ava.Program.Main(String[] args)
报错分析:
根据报错信息,应用程序在使用 Avalonia UI 框架时遇到了问题。报错信息表明默认字体系列名称为空或为空字符串。
可以通过以下命令查看系统已安装的字体列表:
fc-list
重点issue
这是一个很久的问题,参考这个issue
https://github.com/AvaloniaUI/Avalonia/issues/4427
尝试第一个解决方案(0.10版本及以前有效)
网上的解决方案,针对0.10版本及以前有效 解决方案一
由于 11.0.0 更改了 Avalonia.Skia.GlyphTypefaceImpl 的访问级别,从公共访问级别更改为内部访问级别,因此上述实现 Avalonia.Platform.IFontManagerImpl 的示例代码现在均不可用。
V11版本解决方案
1.修改环境变量 export Lang=en_ US.UTF-8
https://github.com/AvaloniaUI/Avalonia/issues/12140
将环境变量设置 export Lang=en_ US.UTF-8
1.打开终端。
2.运行以下命令来查看当前的 LANG
环境变量的值:
echo $LANG
3.如果当前的 LANG
值不是 en_US.UTF-8
,就需要设置它为 en_US.UTF-8
。可以使用以下命令来设置:
export LANG=en_US.UTF-8
4.使用 echo
命令验证环境变量是否已更改:
echo $LANG
5.如果您希望永久设置 LANG
变量,可以将上述命令添加到您的 shell 配置文件中(如 ~/.bashrc
、~/.bash_profile
等),这样每次启动终端时都会自动设置。
代码中修改掉linux不支持的字体
将字体修改后
<Setter Property="FontFamily" Value="宋体,国标黑体,Simsun,微软雅黑,Microsoft YaHei,苹方-简,宋体-简" />
linux中没有宋体,会自动选择后面的国标黑体
成果展示
2.Cannot access a disposed context instance
报错记录
Unhandled exception. System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'ChatDbcontext'.
at Microsoft.EntityFrameworkCore.DbContext.CheckDisposed()
at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
at Microsoft.EntityFrameworkCore.DbContext.get_Model()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Collections.Generic.IEnumerable<TEntity>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Collections.ObjectModel.ObservableCollection`1..ctor(IEnumerable`1 collection)
at TerraMours.Chat.Ava.Views.MainWindow.MainWindow_Loaded(Object sender, RoutedEventArgs e)
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore() in /_/src/Avalonia.Base/Threading/DispatcherOperation.cs:line 412
at Avalonia.Threading.DispatcherOperation.Execute() in /_/src/Avalonia.Base/Threading/DispatcherOperation.cs:line 268
at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job) in /_/src/Avalonia.Base/Threading/Dispatcher.Queue.cs:line 126
at Avalonia.Threading.Dispatcher.ExecuteJobsCore() in /_/src/Avalonia.Base/Threading/Dispatcher.Queue.cs:line 181
at Avalonia.Threading.Dispatcher.Signaled() in /_/src/Avalonia.Base/Threading/Dispatcher.Queue.cs:line 134
at Avalonia.X11.X11PlatformThreading.CheckSignaled() in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 119
at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.X11/X11PlatformThreading.cs:line 192
at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl) in /_/src/Avalonia.Base/Threading/DispatcherFrame.cs:line 117
at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in /_/src/Avalonia.Base/Threading/Dispatcher.MainLoop.cs:line 53
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.MainLoop.cs:line 80
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 127
at TerraMours.Chat.Ava.Program.Main(String[] args)
原因
在 Linux 环境下发生此错误可能是因为 Linux 环境的异步处理方式与 Windows 环境有所不同。
解决方案
去掉using
public void CreateDatabase()
{
var context = new ChatDbcontext();
context.Database.Migrate();
VMLocator.ChatDbcontext = context;
}
然后,在其他需要使用 ChatDbcontext
的地方,使用 VMLocator.ChatDbcontext
来获取上下文实例。确保不要在其他地方使用 using
语句或调用上下文实例的 Dispose
方法。
3.openkylin会自动切换到平板模式
而且切换不回来,程序点不了
解决方案
可以通过桌面侧边栏进行PC/平板模式切换,唤出侧边栏的方法有:
点击任务栏上的侧边栏图标;
快捷键 super + A;----super对应Windows键
通过触摸手势,在屏幕右边缘向左短滑。
阅读如遇样式问题,请前往个人博客浏览: https://www.raokun.top
拥抱ChatGPT:https://ai.terramours.site文章来源:https://www.toymoban.com/news/detail-606803.html
开源项目地址:https://github.com/raokun/TerraMours.Chat.Ava文章来源地址https://www.toymoban.com/news/detail-606803.html
到了这里,关于Avalonia项目在OpenKylin运行踩坑的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!