English 中文(简体)
Unity (in PRISM) does (not) weird resolving...??!!
原标题:

I m using PRISM and in the Bootstrapper class i did override the ConfigureContainer() method. There is nothing fancy in it just these lines:

protected override void ConfigureContainer()
{       
    Container.RegisterType<IDataContext, SQLDataContext>(new InjectionConstructor(@"Server=localhostSQLExpress;User Id=sa;Password=xxxxx;Database=MyDatabase"));
        base.ConfigureContainer();
}

At "debug-time" i try to call Container.Resolve() but this gives me the following error:

{"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)"} System.Exception {Microsoft.Practices.Unity.ResolutionFailedException}

But when i do

Container.IsTypeRegistered(typeof(IDataContext))

I get true!!!

  • What am I missing???

Info which published as answer below, which should be an edit to the question:

This is the full stack:

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:UsersSavvasDocumentsVisual Studio 2008ProjectsPhotoPhoto.DALMapping.cs:line 18
   at Photo.DAL.Concrete.SQLDataContext..ctor(String connectionString) in C:UsersSavvasDocumentsVisual Studio 2008ProjectsPhotoPhoto.DALConcreteSQLDataContext.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:UsersSavvasDocumentsVisual Studio 2008ProjectsPhotoPhoto.DesktopBootstrapper.cs:line 42

I noticed that the error is not coming from actually resolving the class, but from the calling method GetMapping() which is defined as

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;
        }
    }
  • Is Unity incapable of doing this? (it worked well with Windsor!!)
最佳回答

It could be one of two things.. it s not clear from your exception exactly...

  1. Likely there is another inner exception that might be masked?

  2. Otherwise it might be that your SqlDataContext class has a constructor that accepts a stream?

Again, the exception isn t quite clear enough (at least to me). If neither of these suggestions helps, could you post the full out put of $exception.ToString() in your question?

Edit: according to your full stack trace, the line of code failing is this one:

using (Stream stream = Assembly.
                       GetExecutingAssembly().
                       GetManifestResourceStream("Photo.DAL.Entities.Entities.map"))
{
    //This line is failing with null argument
    mapping = XmlMappingSource.FromStream(stream);
}

Your resource stream is coming back null, which either indicates your resource does not exist or the assembly couldn t be loaded (sometimes this refers to a satellite assembly). I would suspect the former first... check to make sure the Build setting is correct on your .map file.

问题回答

暂无回答




相关问题
Getting a list of loaded modules from PRISM in WPF

I have a WPF application built on top of PRISM. When the user tries to close the application I need to check the dirty status of any loaded views. I was hoping to enumerate a list of the loaded ...

Silverlight 3 different behavior between browsers

I have a silverlight project that runs normally, its just a listbox that retrieivies some value. This project run correctly in Internet explorer but do not runs correctly in Safari 4 or Firefox 3.5.......

Where should the data be stored in MVVM?

I ve got this Silverlight Prism application that is using MVVM. The model calls a WCF service and a list of data is returned. The ViewModel is bound to the View, so the ViewModel should have a List ...

ADO.NET DataServices with Prism

I ve start using prism with silverlight 3, but, we are trying to implement it to work with ADO.NET DataServices. The "DataServiceQuery" query type required to use with Silverlight, requires a ...

Best logging approach for composite app?

I am creating a Composite WPF (Prism) app with several different projects (Shell, modules, and so on). I am getting ready to implement logging, using Log4Net. It seems there are two ways to set up the ...

Localization in Prism WPF App

I m looking for the best way to localize a Prism 2 WPF app that might have several modules ported to Silverlight 3. Has anyone successfully localized a Prism 2 WPF app with several modules?

Where to put the calls to WCF or other webservices in MVVM?

I m building Silverlight applicaitions using Prism and MVVM. When calling WCF services on your own server, or even external webservices like the Bing api, would this be done from the Model? or from ...

热门标签