C# 4.0 错误CS0738接口实现
我有以下界面: 公共委托void NotifyOnModulesAvailabilityHandlerLazy[]模块C# 4.0 错误CS0738接口实现,c#-4.0,mef,C# 4.0,Mef,我有以下界面: 公共委托void NotifyOnModulesAvailabilityHandlerLazy[]模块 public interface IModulesLoader { event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability; Lazy<UserControl, IModuleMetadata>[] Modules { get; set; } void On
public interface IModulesLoader
{
event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;
Lazy<UserControl, IModuleMetadata>[] Modules { get; set; }
void OnImportsSatisfied();
}
我试图实现如下接口:
public class ModulesLoader : IModulesLoader, IPartImportsSatisfiedNotification
{
#region Events
public event NotifyOnModulesAvailabilityHandler NotifyOnModulesAvailability;
#endregion
#region Public Contructor
public ModulesLoader()
{
DeploymentCatalogService.Instance.Initialize();
CompositionInitializer.SatisfyImports(this);
this.LoadModules();
}
#endregion
#region Properties
[ImportMany(AllowRecomposition = true)]
public Lazy<UserControl, IModuleMetadata>[] Modules
{
get;
set;
}
#endregion
#region IPartImportsSatisfiedNotification Members
public void OnImportsSatisfied()
{
var handler = this.NotifyOnModulesAvailability;
if (handler != null)
{
handler(this.Modules);
}
}
#endregion
#region Private Methods
private void LoadModules()
{
var wc = new WebClient();
wc.OpenReadCompleted += (s, e) =>
{
var streamInfo = e.Result;
var xElement = XElement.Load(streamInfo);
var modulesList = from m in xElement.Elements("ModuleInfo")
select m;
if (modulesList.Any())
{
foreach (var module in modulesList)
{
var moduleName = module.Attribute("XapFilename").Value;
DeploymentCatalogService.Instance.AddXap(moduleName);
}
}
};
wc.OpenReadAsync(new Uri("ModulesCatalog.xml", UriKind.Relative));
}
#endregion
}
我得到以下错误:
错误1“TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader”未实现接口成员“TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules”TunisiaMeeting.Extensibility.Shell.Helpers.Deployment.ModulesLoader.Modules无法实现TunisiaMeeting.MefBase.Interfaces.IModulesLoader.Modules,因为它没有匹配的返回类型System.Lazy``2[]。C:\Imed\TunisiaMeeting\TunisiaMeeting.Extensibility.Shell\Helpers\Deployment\ModulesLoader.cs 18 18 TunisiaMeeting.Extensibility.Shell
我很确定我的类和属性的接口中都有相同的返回类型Lazy[]
需要帮忙吗
谢谢大家您还没有显示UserControl和IModuleMetadata的来源。。。我猜您的接口引用的是一对类型,而您的实现引用的是另一对类型:
确保它们在相同的名称空间中引用相同的类型
确保每种类型只有一个副本,例如,类库中没有一个副本,并在其他地方重新声明
这是我的IModuleMetadata:namespace tuniasiameting.MefBase.Interfaces{public interface IModuleMetadata{string XapFilename{get;}string NavigateUri{get;set;}string Title{get;}int Position{get;}}UserControl是System.Windows.Controls.UserControl它们都引用相同的名称空间,每个名称空间都有一个副本type@Imed:那么您在一个程序集中只得到了IModuleMetaData的声明?是的,我在MefBase项目命名空间TunisiaMeeting.MefBase.Interfaces{public interface IModuleMetaData中得到了它{string XapFilename{get;}string NavigateUri{get;set;}string Title{get;}int Position{get;}}}}我通过项目引用引用引用它MefBase项目在同一解决方案中