The type SByte* does not have an accessible constructor.

Aug 15, 2010 at 3:51 PM

At first,I'm sorry for my poor English,this is my first post in English.

I'm learning Asp.Net MVC,And copy the source code of The Oxite this.

public class HuHuControllerFactory : DefaultControllerFactory
        private readonly IUnityContainer container;

        public HuHuControllerFactory(IUnityContainer unityContainer)
            this.container = unityContainer;

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)

            IController icontroller = container.Resolve(controllerType) as IController;
            if (typeof(Controller).IsAssignableFrom(controllerType))
                Controller controller = icontroller as Controller;

                return icontroller;

            return icontroller;
But It doesn't work,the red line has a mistaike that the error message is the same as the post's title.

the param ----  the type of controllerType is AdminController Inherited From Controller class.
public class AdminController : Controller
        private readonly ISortService sortService;

        public AdminController(ISortService sort)
            sortService = sort;

And I register the Type At Global.asax File.

 public IUnityContainer GetHuHuContainer()
            IUnityContainer parentContainer = new UnityContainer();

            parentContainer.RegisterType<ISortService, SortService>();

            return parentContainer;

And Replaces  DefaultControllerFactory Class with HuHuControllerFactory class.
 private void registerControllFactory()

But it's have a mistake,I don't know why.
I'sorry for my poor English again,If you know what I say and have a answer,please help me!

Aug 15, 2010 at 11:00 PM

Which version of Unity are you using? The error messages in 2.0 are a lot easier to read then they were in previous versions.

The error is not in resolving your controller, it's actually further down the dependency tree. My guess is that there's a string argument to your SortService that isn't configured properly. Either that or something SortService depends on. Can you post the full exception message?


Aug 16, 2010 at 2:55 AM

Thank you for you reply.

My Unity version 1.2. And Your guess is right.

Exception here:

{"Resolution of the dependency failed, type = \"HuHu.Services.SortService\", 
name = \"\". Exception message is: The current build operation (build key Build Key[HuHu.Services.SortService, null])
 failed: The parameter rep could not be resolved when attempting to call constructor HuHu.Services.SortService(HuHu.Repositories.ISortRepository rep). 
(Strategy type BuildPlanStrategy, index 3)"}	
System.Exception {Microsoft.Practices.Unity.ResolutionFailedException} 

And I find that every "UnityContainer.Resolve" have the same mistake all over my project.

public IUnityContainer GetHuHuContainer()
            IUnityContainer parentContainer = new UnityContainer();

            parentContainer.RegisterType<ISortRepository, SortRepository>()
                            .RegisterType<ISortService, SortService>();

            ISortRepository repository = parentContainer.Resolve<ISortRepository>();

            ISortService service = parentContainer.Resolve<ISortService>();

            return parentContainer;

two red line also has a mistaike,The Unity don't work well.
I think Unity's config don't configured properly.
show my config:

    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      <typeAlias alias="ISortRepository" type="HuHu.Repositories.ISortRepository,HuHu"/>
          <type type="System.Data.Linq.DataContext,System.Data.Linq, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,Microsoft.Practices.Unity.Configuration">
                <param name="connection" parameterType="System.String">
                  <dependency name="ApplicationServices" />
          <type type="ISortRepository" mapTo="HuHu.LinqToSql.SortRepository,HuHu.LinqToSql" />

is there something wrong?


Aug 16, 2010 at 3:54 AM

My God!I Find the answer.There is something wrong in my web.config.

I think I could solve it.

Thank you very much. ^_^ .