我有一个大问题。我整天都在理解为什么我有这个例外。我得到的信息是:
“无法构造String类型。您必须配置容器以提供此值。”
我对这条消息做了自己的研究,我发现了一些文章,但没有什么不能帮助我。我不知道在这里发布哪些代码。我会发布任何可以帮助我们找到问题解决方案的代码。
堆栈跟踪
[InvalidOperationException: The type String cannot be constructed. You must configure the container to supply this value.]
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context) +311
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +229
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +162
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +245
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +250
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +101
lambda_method(Closure , IBuilderContext ) +205
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +71
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +42
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +333
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +250
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +101
lambda_method(Closure , IBuilderContext ) +205
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +71
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +42
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +333
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +250
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +101
lambda_method(Closure , IBuilderContext ) +443
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +71
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +42
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +333
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp(NamedTypeBuildKey newBuildKey) +250
Microsoft.Practices.Unity.ObjectBuilder.NamedTypeDependencyResolverPolicy.Resolve(IBuilderContext context) +101
lambda_method(Closure , IBuilderContext ) +267
Microsoft.Practices.ObjectBuilder2.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context) +71
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) +42
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +333
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +274
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +384
[ResolutionFailedException: Resolution of the dependency failed, type = "Nop.Web.Controllers.CommonController", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type String cannot be constructed. You must configure the container to supply this value.
-----------------------------------------------
At the time of the exception, the container was:
Resolving Nop.Web.Controllers.CommonController,(none)
Resolving parameter "categoryService" of constructor Nop.Web.Controllers.CommonController(Nop.Services.Catalog.ICategoryService categoryService, Nop.Services.Catalog.IProductService productService, Nop.Services.Catalog.IManufacturerService manufacturerService, Nop.Services.Topics.ITopicService topicService, Nop.Services.Localization.ILanguageService languageService, Nop.Services.Directory.ICurrencyService currencyService, Nop.Services.Localization.ILocalizationService localizationService, Nop.Core.IWorkContext workContext, Nop.Services.Messages.IQueuedEmailService queuedEmailService, Nop.Services.Messages.IEmailAccountService emailAccountService, Nop.Services.Seo.ISitemapGenerator sitemapGenerator, Nop.Web.Framework.Themes.IThemeContext themeContext, Nop.Web.Framework.Themes.IThemeProvider themeProvider, Nop.Services.Forums.IForumService forumService, Nop.Services.Common.IGenericAttributeService genericAttributeService, Nop.Core.IWebHelper webHelper, Nop.Services.Security.IPermissionService permissionService, Nop.Services.Common.IMobileDeviceHelper mobileDeviceHelper, System.Web.HttpContextBase httpContext, Nop.Core.Caching.ICacheManager cacheManager, Nop.Services.Logging.ICustomerActivityService customerActivityService, Nop.Core.Domain.Customers.CustomerSettings customerSettings, Nop.Core.Domain.Tax.TaxSettings taxSettings, Nop.Core.Domain.Catalog.CatalogSettings catalogSettings, Nop.Core.Domain.StoreInformationSettings storeInformationSettings, Nop.Core.Domain.Messages.EmailAccountSettings emailAccountSettings, Nop.Core.Domain.Common.CommonSettings commonSettings, Nop.Core.Domain.Blogs.BlogSettings blogSettings, Nop.Core.Domain.News.NewsSettings newsSettings, Nop.Core.Domain.Forums.ForumSettings forumSettings, Nop.Core.Domain.Localization.LocalizationSettings localizationSettings, Nop.Web.Framework.UI.Captcha.CaptchaSettings captchaSettings)
Resolving Nop.Services.Catalog.CategoryService,(none) (mapped from Nop.Services.Catalog.ICategoryService, (none))
Resolving parameter "categoryRepository" of constructor Nop.Services.Catalog.CategoryService(Nop.Core.Caching.ICacheManager cacheManager, Nop.Core.Data.IRepository`1[[Nop.Core.Domain.Catalog.Category, Nop.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null]] categoryRepository, Nop.Core.Data.IRepository`1[[Nop.Core.Domain.Catalog.ProductCategory, Nop.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null]] productCategoryRepository, Nop.Core.Data.IRepository`1[[Nop.Core.Domain.Catalog.Product, Nop.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null]] productRepository, Nop.Core.Data.IRepository`1[[Nop.Core.Domain.Security.AclRecord, Nop.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null]] aclRepository, Nop.Core.IWorkContext workContext, Nop.Services.Events.IEventPublisher eventPublisher)
Resolving Nop.Data.EfRepository`1[Nop.Core.Domain.Catalog.Category],(none) (mapped from Nop.Core.Data.IRepository`1[Nop.Core.Domain.Catalog.Category], (none))
Resolving parameter "context" of constructor Nop.Data.EfRepository`1[[Nop.Core.Domain.Catalog.Category, Nop.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null]](Nop.Data.IDbContext context)
Resolving Nop.Data.NopObjectContext,(none) (mapped from Nop.Data.IDbContext, (none))
Resolving parameter "nameOrConnectionString" of constructor Nop.Data.NopObjectContext(System.String nameOrConnectionString)
Resolving System.String,(none)
]
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +447
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) +50
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) +48
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve(IUnityContainer container, Type t, ResolverOverride[] overrides) +61
Nop.Web.App_Start.UnityControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) in c:\Solutions\petlync13nov2013 (1)\Presentation\Nop.Web\App_Start\UnityControllerFactory.cs:52
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +197
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.Mvc.<>c__DisplayClass7.<BeginProcessRequest>b__6() +31
System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +98
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +2019
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +76
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28
System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +19
System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter) +483
System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues) +83
System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName) +10
ASP._Page_Views_Shared__Root_cshtml.Execute() in c:\Solutions\petlync13nov2013 (1)\Presentation\Nop.Web\Views\Shared\_Root.cshtml:6
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +97
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +88
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +233
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +64
System.Web.WebPages.WebPageBase.PopContext() +246
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.WebPages.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) +233
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +10
System.Web.WebPages.WebPageBase.Write(HelperResult result) +71
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +64
System.Web.WebPages.WebPageBase.PopContext() +246
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +95
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +260
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +295
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.<>c__DisplayClass1a.<InvokeActionResultWithFilters>b__17() +23
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +242
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +21
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +89
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9514928
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
web.config文件。
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<namespace name="Nop.Web.Controllers" />
<alias alias="HomeController" type="Nop.Web.Controllers, Nop.Web" />
<container>
<register type="BaseNopController" mapTo="HomeController" />
</container>
</unity>
HomeController文件
public partial class HomeController : BaseNopController
{
private IHomeModel _model;
public HomeController(IHomeModel mdl)
{
_model = mdl;
}
public ActionResult Index(string id)
{
if (_model != null)
{
Tag tag = _model.GetTag(id);
if (tag != null)
{
MainDataModel model = new MainDataModel();
PetDataModel petModel = null;
string sCurrentUserName = WebSecurity.CurrentUserName;
Customer cst = _model.GetCustomerFromTag(tag.Id);
if (sCurrentUserName != cst.Username && sCurrentUserName != "")
{
WebSecurity.Logout();
}
string connectionString = ConfigurationManager.ConnectionStrings["StorageAccountConnectionString"].ConnectionString;
string containerReference = ConfigurationManager.AppSettings["ImageContainerReference"] as string;
string sPhotoUrl = "";
petModel = new PetDataModel(tag);
if (tag.PetId.PhotoUnqName != null && tag.PetId.PhotoUnqName != "")
{
sPhotoUrl = BlobStorageManager.GetFileLink(connectionString, containerReference, tag.PetId.PhotoUnqName);
petModel.PhotoUrl = sPhotoUrl;
}
#region PetOwner
PetOwner petOwner = _model.GetPetOwner(tag.Code);
PetOwnerDataModel petOwnerModel;
if (petOwner != null)
{
petOwnerModel = new PetOwnerDataModel(petOwner);
if (petOwner.CountryId != null)
petOwnerModel.StateProvinceList = _model.GetStateProvinceList(petOwner.CountryId.Id);
}
else
{
petOwnerModel = new PetOwnerDataModel();
Language lang = _model.GetCustomerlanguage(tag.Code);
if (lang != null)
petOwnerModel.LanguageId = lang.Id;
}
petOwnerModel.TagCode = tag.Code;
petOwnerModel.CountryList = _model.GetCountryList();
#endregion
model.PetDataModel = petModel;
model.PetOwnerDataModel = petOwnerModel;
ViewBag.Tag_Code = tag.Code;
ViewData.Add("CustomerName", cst.Username);
return View("/Views/Home/Main.cshtml", model);
}
ViewBag.Message = "This Tag Code: " + id + " is wrong!";
return View();//"/Views/Home/Index.cshtml");
}
else
{
return View();
}
}
}
提前致谢。