Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:12:35+00:00 2026-06-11T16:12:35+00:00

error :: Cannot instantiate a class that does not have a no-argument constructor [ClassLibrary2.Class1].

  • 0

error :: Cannot instantiate a class that does not have a no-argument constructor [ClassLibrary2.Class1].

I created a test project.

i got the error source in Spring src.
//////////////

ConstructorInfo constructor = GetZeroArgConstructorInfo(objectType); // in this , only zero arg allow. But I use dependency inject constructor. It doest work.
////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
   public interface IHi
    {
        string SayHi();
    }
}




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class Class1:IHi
    {
        public string SayHi()
        {
            return "Hello Yeah";
        }
    }
}





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ClassLibrary1;
namespace ClassLibrary2
{
    public class Class1:IWannaSay
    {


        private readonly IHi Hi;
///Here doest work. prompts Cannot instantiate a class that does not have a no-argument constructor [ClassLibrary2.Class1].

        public Class1(IHi Hi)
        {
            this.Hi = Hi;
        }


        public string SayHi()
        {

           return  Hi.SayHi();
        }

    }
}




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary2
{
   public interface IWannaSay
    {
       string SayHi();
    }
}






using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClassLibrary2;
namespace Mvc4.Controllers
{
    public class HomeController : Controller
    {
        private readonly IWannaSay WannaSay;
///H ere works .Its so werid.
        public HomeController(IWannaSay WannaSay)
        {
            this.WannaSay = WannaSay;

        }
        public ActionResult Index()
        {

            var c = WannaSay.SayHi();
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

}

My test.xml

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">

  <object id="w" type="ClassLibrary2.Class1,ClassLibrary2">
  </object>
  <object id="Hi" type="ClassLibrary1.Class1,ClassLibrary1">
  </object>

  <object id="Hio" type="ClassLibrary2.Class1,ClassLibrary2"  singleton="false">
    <!--构造器注入-->
    <!--<constructor-arg  name="Hi"   ref="Hi"/>-->
    <property name="Hi" ref="w"/>

  </object>

  <object id="HomeCountroller" type="Mvc4.Controllers.HomeController,Mvc4"  singleton="false">
    <!--构造器注入-->
    <constructor-arg  name="WannaSay"   ref="w"/>
    <!--<property name="UserRespositoryImpl" ref="UserRespositoryImpl"/>-->

  </object>


</objects>

web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.MvcContextHandler, Spring.Web.Mvc4" />
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
      <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
  <spring>
    <parsers>
      <parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
      <parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
    </parsers>
    <context>
      <resource uri="assembly://Mvc4/Mvc4.Configs/test.xml" />

    </context>
  </spring>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Mvc4-20120919193749;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Mvc4-20120919193749.mdf" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:12:37+00:00Added an answer on June 11, 2026 at 4:12 pm

    You can adjust your controller argument (Problem is mismatch of type)

    Because

      <object id="w" type="ClassLibrary2.Class1,ClassLibrary2">
      </object>
     <object id="HomeCountroller" type="Mvc4.Controllers.HomeController,Mvc4"  singleton="false">
        <constructor-arg  name="WannaSay"   ref="w"/>
     </object>
    

    You need argument of type Class1

    But in your constructor you have

    public HomeController(IWannaSay WannaSay)//<--- 
    {
         this.WannaSay = WannaSay;
    
    }
    

    Solution : Modify your argument and set to Class1 Type

    public class HomeController
    {
    
        private Class1 yourProperty;
        public HomeController(Class1 value) 
        {
            yourProperty = value;   
        }
    
        .........
    
    
    }
    

    With this spring

     <object id="w" type="ClassLibrary2.Class1,ClassLibrary2">
      </object>
     <object id="HomeCountroller" type="Mvc4.Controllers.HomeController,Mvc4"  singleton="false">
        <constructor-arg  name="WannaSay"   ref="w"/>
     </object>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an abstract test case class that is to be extended by
I am getting the error Cannot add task ':webserver:build' as a task with that
I have faced a problem in Qt with error: cannot convert parameter 1 from
My PHP class constructor appears to not be getting called when the class is
I have never done any Singleton class before and now I figured that for
I have a public class FriendMaps extends MapActivity that gets called from a menu
Create a function that can have different argument list. something like this void s(int
I am trying to use Generic DataContract class so that I don't have to
In PHP, if you define a class, and then instantiate an object of that
In my Rails 3.1 app (with Ruby 1.9), I have a Deployer1 class that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.