Unity and classes from an outer assembly

Apr 16, 2008 at 2:56 PM
Hi all.
I am pretty stuck here with some things, and i could really use some help.

I'm having a problem mapping a type from an outer assembly.
I tried to map between an ILogger interface (as most examples do) and a MessageBoxLogger concrete class.
If the MessageBoxLogger is defined in my assembly, then the mapping was successfull (also from configuration file).
But how do i do this mapping if i only know the ILogger and not the concrete class?
BTW, even if i reference the MessageBoxLogger assembly, the mapping from the configuration file fail (Could not load
type 'UnityAttempt.Logger.ILogger' from assembly 'UnityAttempt' )

i really look forword to get an answer.
maorino
Apr 16, 2008 at 8:42 PM
what is the mapping config you are using? What exception are you getting?

If you are getting Type load exception, when your MessageBoxLogger is in different assembly, then either Fully qualified type namespace is wrong(its case sensitive) OR DLL name is incorrect

Apr 17, 2008 at 5:19 AM
Could you please post the configuration file you're using, or sample code using the API?

Also, if you don't know the concrete type at configuration time, you're stuck - Unity can't guess, you need to give it the type to map to.
Apr 19, 2008 at 10:57 AM
Hi, thank you very much for your reply.
I suppose that i use incorrectly in the configuration file.
could you please send me an example of how i should use the full type load? i admit i didn't even supplied
a full dll path cause i didn't know that it is possible..

i am writing you frim home now, so i don't have the example of the config file, but i know now that it was incorrect.
thanks,
maorino


singhhome wrote:
what is the mapping config you are using? What exception are you getting?

If you are getting Type load exception, when your MessageBoxLogger is in different assembly, then either Fully qualified type namespace is wrong(its case sensitive) OR DLL name is incorrect



Apr 20, 2008 at 5:24 PM
You have to ensure the assembly you are referencing is available to your program. It should be in the bin directory, or it should have a strong name and put into the GAC. If strong named and in the GAC, you should also include the Version, Culture, PublicKeyToken values in the config This config should do the trick.
<?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>
                    <!-- Standard Mapping: ConsoleLogger from the CodePlex.Unity.Samples.dll assembly -->
                    <type type="CodePlex.Unity.Samples.ILogger, CodePlex.Unity.Samples"
                          mapTo="CodePlex.Unity.Samples.ConsoleLogger, CodePlex.Unity.Samples" />
 
                    <!-- External Mapping: MessageBoxLogger from the CodePlex.Unity.Discussion.dll assembly -->
                    <type type="CodePlex.Unity.Samples.ILogger, CodePlex.Unity.Samples"
                          mapTo="CodePlex.Unity.Discussion.MessageBoxLogger, CodePlex.Unity.Discussion" />
                </types>
            </container>
        </containers>
    </unity>
</configuration>


Maorino wrote:
Hi, thank you very much for your reply.
I suppose that i use incorrectly in the configuration file.
could you please send me an example of how i should use the full type load? i admit i didn't even supplied
a full dll path cause i didn't know that it is possible..

i am writing you frim home now, so i don't have the example of the config file, but i know now that it was incorrect.
thanks,
maorino


singhhome wrote:
what is the mapping config you are using? What exception are you getting?

If you are getting Type load exception, when your MessageBoxLogger is in different assembly, then either Fully qualified type namespace is wrong(its case sensitive) OR DLL name is incorrect




Apr 20, 2008 at 11:21 PM
Hi.
Thanks again for your reply.
I have tried using a very sumular conig file, and the assembly was in the bin directory but that did not seem to work.
In your config example, i didn't see the Version, Culture and PublicKeyToken values... why is that?
Apr 23, 2008 at 3:33 PM
In my example, my assemblies were not signed and I did not want to bind it to a specific version number. If you are having problems loading the configured assembly, you could try the using the Assembly Binding Log Viewerhttp://blogs.msdn.com/junfeng/archive/2004/02/14/72912.aspx or http://msdn2.microsoft.com/en-us/library/e74a18c4(vs.71).aspx to determine the load failure reason.


Maorino wrote:
Hi.
Thanks again for your reply.
I have tried using a very sumular conig file, and the assembly was in the bin directory but that did not seem to work.
In your config example, i didn't see the Version, Culture and PublicKeyToken values... why is that?