Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I created a unity Dependency Injection project. Created a constructor in app config. The error thrown as "Unrecognized element 'constructor'. Please help me on this. Thank you.

XML
<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/>
    <section name="unity1" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/>
  </configSections>
  <unity>
    <containers>
      <container>
        <types>
          <type type="Sample1.IDB,Sample1" mapTo="Sample1.oracle,Sample1"  name="Oracle"> </type>
          <type type="Sample1.IDB,Sample1" mapTo="Sample1.sql,Sample1"  name="Sql"></type>
          <type type="Sample1.IDB,Sample1" mapTo="Sample1.oracle,Sample1"  name="parOracle">
            <constructor>
              <param name="status" value="oracle" parameterType="System.String"/>
            </constructor>
          </type>
          <type type="Sample1.IDB,Sample1" mapTo="Sample1.sql,Sample1"  name="parSql">
            <constructor>
              <param name="status" value="sql" parameterType="System.String"/>
            </constructor>
          </type>
        </types>
      </container>
    </containers>
  </unity>
  <appSettings>
    <add key="Types" value="Oracle" />
  </appSettings>

</configuration>



IUnityContainer container = new UnityContainer();

UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

here its throwing error as "Unrecognized element 'constructor'.
In app config I changed the Types to register. Then its throwing error as "Unrecognized element 'register'. Its working normaly in Types and Type. But after adding the constructor throwing an error.

Actual error is Unrecognized element 'constructor'. (D:\Sample1\Sample1\Sample1\bin\Debug\Sample1.vshost.exe.Config line 14)
Posted
Updated 14-Jun-16 3:09am
v2
Comments
AnalogNerd 31-Mar-14 9:29am    
What version of unity are you using?

1 solution

C#
use <register/> instead of type, there is no tag named type in unity

<register type="Sample1.IDB,Sample1" mapTo="Sample1.oracle,Sample1"  name="parOracle">
            <constructor>
              <param name="status" value="oracle" parameterType="System.String"/>
            </constructor>
</register>

enjoy :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900