当我在 IOS 模拟器中从 Visual Studio 运行带有调试功能的应用程序时,应用程序启动,显示启动屏幕,然后崩溃。Visual Studio 继续显示正常行为,就像它仍然附加到调试过程一样,一切都按计划进行。
当我在模拟器上手动启动相同的应用程序时,它运行得很好。
调试日志总是这样:
加载的程序集:/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB-FD8E-441A-856C-66981DB384B5/WebtutorMobileX.iOS.app/ Xamarin.iOS.dll [外部] 加载程序集:/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB-FD8E-441A-856C- 66981DB384B5/WebtutorMobileX.iOS.app/System.dll [外部] 加载的程序集:/Users/admin/Library/Developer/CoreSimulator/Devices/40C63365-3924-44EA-9145-AAF5F59D170F/data/Containers/Bundle/Application/FED2C1CB- FD8E-441A-856C-66981DB384B5/WebtutorMobileX.iOS.app/Mono.Security.dll [外部]
之后应用程序崩溃并且没有任何反应。Visual Studio 仍然处于幸运的无知状态。
没有任何错误。
这是在我升级到 4.7.0.1179 和 XCode 11.6 后开始的。Visual Studio 2019 16.6.5。
我正在尝试从 Xamarin 迁移到 MAUI。
下面的代码完美唤醒。
Xamarin 项目:
DependencyService.Get<IMyService>().Test();
Run Code Online (Sandbox Code Playgroud)
安卓:
[assembly: Dependency(typeof(MyService))]
namespace MyProject.Android
{
public class MyService: IMyService
{
public void Test(){
////
}
}
}
Run Code Online (Sandbox Code Playgroud)
IOS 和 Windows 依此类推。
但 MAUI 的DependencyService.Get 始终返回null。我找不到必须做出哪些新的改变。在我的主项目中重新编写基于 DependencyService 的所有代码将是痛苦的。
这种情况下应该做哪些改变呢?
我上课了
public class SomeClass
{
public int num { get; set; }
public string str{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要构造一个lambda表达式,如:(x => new {new_num = x.num,new_str = x.str})
属性列在一些可枚举对象中(这很重要).让我们说吧List<KeyValuePair<string, string>>
我的代码是:
// Test properties list
var listOfParams = new List<KeyValuePair<string, string>>();
listOfParams.Add(new KeyValuePair<string, string>("new_num","num"));
listOfParams.Add(new KeyValuePair<string, string>("new_str","str"));
// SomeClass as particular test case
var tModelType = typeof(SomeClass);
ParameterExpression pe = Expression.Parameter(tModelType, "m");
NewExpression ne = Expression.New(typeof(object)); //<-- trying to emulate `new object{}`
List<Expression> lInit = new List<Expression>();
PropertyInfo pi; …
Run Code Online (Sandbox Code Playgroud)