Alex Rivera | Logout

Unity application block 2.0 - The given assembly name or codebase was invalid

Asked 2010-10-17T05:09:47.610
14

Interfaces (In the assembly named "Interfaces". In project :- Interfaces)

namespace Interfaces
{
    public interface IDoSomeWork1
    {
        string DoSomeWork1();
    }
}

namespace Interfaces
{
    public interface IDoSomeWork2
    {
        string DoSomeWork2();
    }
}

Dependencies (In the assembly named "Entities". In project :- Entities)

namespace Entities
{
    public class ClassB : IDoSomeWork1
    {
        public string DoSomeWork1()
        {
            return this.ToString();
        }
    }
}

namespace Entities
{
    public class ClassC : IDoSomeWork2
    {
        public string DoSomeWork2()
        {
            return this.ToString();
        }
    }
}

Class (In project :- UsingUnity)

public class ClassA
    {
        [Dependency]
        public IDoSomeWork1 DoSomeWork1 { get; set; }
        [Dependency]
        public IDoSomeWork2 DoSomeWork2 { get; set; }


        public void SomeMethodInClassA()
        {
            Console.WriteLine(DoSomeWork1.DoSomeWork1());
            Console.WriteLine(DoSomeWork2.DoSomeWork2());
        }
    }

App.Config (In a console application project :- ConsoleUsingUnity)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="unity"
                 type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
                   Microsoft.Practices.Unity.Configuration" />
    </configSections>
    <unity>
        <containers>
            <container>
                <types>
                    <type type="Interfaces.IDoSomeWork1, Interfaces"
                          mapTo="Entities.ClassB, Entities" />
                    <type type="Interfaces.IDoSomeWork2, Interfaces"
                          mapTo="Entities
Edit
Report

1 Answer

0

Please make sure, that you have added assembly references of the missing assembly in the project where your web.config file exists.

I was missing this. I already have added those assembly references in the project which was using Unity to resolve the class, but missed to add it in the parent project where configuration file was located. This has resolved my problem.

answered 2013-03-07T07:29:45.330

Your Answer