gpt4 book ai didi

c# - System.ArgumentException : No member matching data has been found - Unity IOC

转载 作者:行者123 更新时间:2023-12-03 10:41:56 30 4
gpt4 key购买 nike

在行执行时我的应用程序出现异常

public static void Initialize(Context applicationContext, IUnityContainer diContainer)
{
diContainer.RegisterType<IAndroidGlobals, AndroidGlobals>(new ContainerControlledLifetimeManager(), new InjectionConstructor(applicationContext));
}

这是AndroidGlobls类
public class AndroidGlobals : IAndroidGlobals
{

public string ApplicationVersion(string appName)
{
return ApplicationContext.PackageManager.GetPackageInfo(appName, 0).VersionName;
}
public Android.Content.Context ApplicationContext
{
get { return _applicationContext; }
}

private readonly Context _applicationContext;

public AndroidGlobals(Context applicationContext)
{
_applicationContext = applicationContext;
}
}

以下是异常(exception)。我该如何解决这个问题

{System.InvalidOperationException: No member matching data has been found. Error in: RegisterType(Lifetime:PerContainer, Invoke.Constructor(dispatch.droid.mainactivity@77cb316)) ---> System.ArgumentException: No member matching data has been found. at Unity.Injection.InjectionConstructor.SelectMember (System.Type type, Unity.Injection.InjectionMember _) [0x0003c] in C:\projects\abstractions\src\Dependency\Injection\Members\InjectionConstructor.cs:48 at Unity.Injection.InjectionMember`2[TMemberInfo,TData].AddPolicies[TContext,TPolicySet] (System.Type registeredType, System.Type mappedToType, System.String name, TPolicySet& policies) [0x00023] in C:\projects\abstractions\src\Dependency\Injection\Abstracts\InjectionMember.cs:133 at Unity.UnityContainer.Unity.IUnityContainer.RegisterType (System.Type typeFrom, System.Type typeTo, System.String name, Unity.Lifetime.ITypeLifetimeManager lifetimeManager, Unity.Injection.InjectionMember[] injectionMembers) [0x00144] in C:\projects\container\src\UnityContainer.IUnityContainer.cs:66 --- End of inner exception stack trace --- at Unity.UnityContainer.Unity.IUnityContainer.RegisterType (System.Type typeFrom, System.Type typeTo, System.String name, Unity.Lifetime.ITypeLifetimeManager lifetimeManager, Unity.Injection.InjectionMember[] injectionMembers) [0x002de] in C:\projects\container\src\UnityContainer.IUnityContainer.cs:97 at Unity.UnityContainerExtensions.RegisterType[TFrom,TTo] (Unity.IUnityContainer container, Unity.Lifetime.ITypeLifetimeManager lifetimeManager, Unity.Injection.InjectionMember[] injectionMembers) [0x00000] in C:\projects\abstractions\src\Extensions\Container\UnityContainer.cs:132 at Ex.Express.Mobile.Core.Shared.Initializer.Initialize (Android.Content.Context applicationContext, Unity.IUnityContainer diContainer) [0x00012] in D:\ExNew\SmartPad\DEV\Ex.Express.Mobile\SmartPad\Components\Core\Core.Shared\Initializer.cs:72 at Ex.Express.Mobile.Core.Droid.Initializer.Initialize (Android.Content.Context applicationContext, Unity.IUnityContainer diContainer) [0x00001] in D:\ExNew\SmartPad\DEV\Ex.Express.Mobile\SmartPad\Components\Core\Core.Droid\Initializer.cs:22 at Ex.Express.Mobile.Apps.DispatchApp.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00034] in D:\ExNew\SmartPad\DEV\Ex.Express.Mobile\SmartPad\Apps\Messages\DispatchApp.Droid\MainActivity.cs:121 }



我在链接器中使用 Sdk and User Assembly。我该如何解决这个问题?

最佳答案

通过在所有使用的类的顶部使用属性[Android.Runtime.Preserve(AllMembers = true)]解决了此问题。

关于c# - System.ArgumentException : No member matching data has been found - Unity IOC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58408450/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com