我正在使用PRISM,在Bootstrapper类中,我确实重写了ConfigureContainer()方法。
protected override void ConfigureContainer()
{
Container.RegisterType<IDataContext, SQLDataContext>(new InjectionConstructor(@"Server=localhost\SQLExpress;User Id=sa;Password=xxxxx;Database=MyDatabase"));
base.ConfigureContainer();
}在“调试时”,我尝试调用Container.Resolve(),但这给了我以下错误:
异常消息是:当前生成操作(生成键生成{Microsoft.Practices.Unity.ResolutionFailedException},空)失败:值不能为空。\r\n参数名称:
(策略类型BuildPlanStrategy,索引3)"} System.Exception System.Exception
但当我做的时候
Container.IsTypeRegistered(typeof(IDataContext))我是真的!
作为答案发布的信息,它应该是对问题:的编辑。
这是完整的堆栈:
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Photo.DAL.Abstract.IDataContext", name = "". Exception message is: The current build operation (build key Build Key[Photo.DAL.Concrete.SQLDataContext, null]) failed: Value cannot be null.
Parameter name: stream (Strategy type BuildPlanStrategy, index 3) ---> Microsoft.Practices.ObjectBuilder2.BuildFailedException: The current build operation (build key Build Key[Photo.DAL.Concrete.SQLDataContext, null]) failed: Value cannot be null.
Parameter name: stream (Strategy type BuildPlanStrategy, index 3) ---> System.ArgumentNullException: Value cannot be null.
Parameter name: stream
at System.Data.Linq.Mapping.XmlMappingSource.FromStream(Stream stream)
at Photo.DAL.Mapping.GetMapping() in C:\Users\Savvas\Documents\Visual Studio 2008\Projects\Photo\Photo.DAL\Mapping.cs:line 18
at Photo.DAL.Concrete.SQLDataContext..ctor(String connectionString) in C:\Users\Savvas\Documents\Visual Studio 2008\Projects\Photo\Photo.DAL\Concrete\SQLDataContext.cs:line 52
at BuildUp_Photo.DAL.Concrete.SQLDataContext(IBuilderContext )
at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
--- End of inner exception stack trace ---
at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
--- End of inner exception stack trace ---
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)
at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)
at Microsoft.Practices.Unity.UnityContainerBase.Resolve(Type t)
at Microsoft.Practices.Unity.UnityContainerBase.Resolve[T]()
at Photo.Desktop.Bootstrapper.ConfigureContainer() in C:\Users\Savvas\Documents\Visual Studio 2008\Projects\Photo\Photo.Desktop\Bootstrapper.cs:line 42我注意到错误不是来自实际解析类,而是来自调用方法GetMapping(),该方法被定义为
public static class Mapping
{
public static XmlMappingSource GetMapping()
{
XmlMappingSource mapping;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Photo.DAL.Entities.Entities.map"))
{
mapping = XmlMappingSource.FromStream(stream);
}
return mapping;
}
}发布于 2009-12-04 06:12:58
这可能是两件事之一..。你的例外还不清楚..。
masked?
的构造函数。
同样,例外情况还不够清楚(至少对我来说是这样)。如果这些建议都没有帮助,你能在你的问题中贴出$exception.ToString()的全部内容吗?
编辑:根据您的完整堆栈跟踪,失败的代码行是这样的:
using (Stream stream = Assembly.
GetExecutingAssembly().
GetManifestResourceStream("Photo.DAL.Entities.Entities.map"))
{
//This line is failing with null argument
mapping = XmlMappingSource.FromStream(stream);
}您的资源流将返回null,这表明您的资源不存在,或者程序集无法加载(有时这是指附属程序集)。我怀疑前第一个..。检查以确保.map文件上的构建设置是正确的。
https://stackoverflow.com/questions/1844245
复制相似问题