Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unity Application Block Error

Unity Application Block Error

Scheduled Pinned Locked Moved C#
helpgame-devdockerworkspace
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bill Warner

    HI All, I'm trying to set up the Unity block and I'm getting the following error: "Given assembly name or codebase was invalid" My setup is as follows: private void btnUnity_Click(object sender, EventArgs e) { IUnityContainer container = new UnityContainer(); var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Configure(container); var transform = container.Resolve "AddNewLabTest"); } The App.Config is: <unity> <containers> <container> <types> <type type="Interfaces.ILabTest, Interfaces" mapTo="DTO.LabTest.AddNewLabTest, DTO.LabTest" name="DTO.LabTest"/> </types> </container> </containers> </unity> Any help would be appreciated. Thanks!

    K Offline
    K Offline
    Keith Barrow
    wrote on last edited by
    #2

    Can you please update your question, it is hard to read, especially the config. Use the "code button" to highlight both the code and XML. I'm just checking the obvious here: Is the dll that contains the concrete class included in the project? Does

    AddNewLabTest

    implement

    ILabTest

    Both Interfaces.ILabTest.dll and DTO.LabTest.AddNewLabTest.dll exist in the target bin folder - if not everything will fail.

    Sort of a cross between Lawrence of Arabia and Dilbert.[^]
    -Or-
    A Dead ringer for Kate Winslett[^]

    B 1 Reply Last reply
    0
    • K Keith Barrow

      Can you please update your question, it is hard to read, especially the config. Use the "code button" to highlight both the code and XML. I'm just checking the obvious here: Is the dll that contains the concrete class included in the project? Does

      AddNewLabTest

      implement

      ILabTest

      Both Interfaces.ILabTest.dll and DTO.LabTest.AddNewLabTest.dll exist in the target bin folder - if not everything will fail.

      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
      -Or-
      A Dead ringer for Kate Winslett[^]

      B Offline
      B Offline
      Bill Warner
      wrote on last edited by
      #3

      Hi KEith, I tried the format buttons for code and markup and got the same result. The dll that contains the concrete class is included in the project. I'm not sure I have the namespace portions of the type tag correct. In the first part I have the type of interface and I'm not sure what the second portion is used for. Then in mapTo attribute I have the concrete implementation, the full namespace path to the concrete method and the namespace without the concrete method. Thanks, Bill

      K 1 Reply Last reply
      0
      • B Bill Warner

        Hi KEith, I tried the format buttons for code and markup and got the same result. The dll that contains the concrete class is included in the project. I'm not sure I have the namespace portions of the type tag correct. In the first part I have the type of interface and I'm not sure what the second portion is used for. Then in mapTo attribute I have the concrete implementation, the full namespace path to the concrete method and the namespace without the concrete method. Thanks, Bill

        K Offline
        K Offline
        Keith Barrow
        wrote on last edited by
        #4

        Bill Warner wrote:

        . I'm not sure I have the namespace portions of the type tag correct. In the first part I have the type of interface and I'm not sure what the second portion is used for

        This is probably the problem, it makes the most sense. In general

        <register type="XXXXX" mapTo="YYYYY, ZZZZZ"/>

        XXXX - The name of the interface you want to map from. YYYY - Type name ZZZZ - The Assembly name Lets Say you have an interface IFoo, which is implemented in a class with a name Bar, in namespace MyNamespace contained in Baz.dll:

        <register type="IFoo" mapTo="MyNamespace.Bar, Baz"/>

        Often the the namespace and the dll name are the same, but not always.

        Sort of a cross between Lawrence of Arabia and Dilbert.[^]
        -Or-
        A Dead ringer for Kate Winslett[^]

        B 1 Reply Last reply
        0
        • K Keith Barrow

          Bill Warner wrote:

          . I'm not sure I have the namespace portions of the type tag correct. In the first part I have the type of interface and I'm not sure what the second portion is used for

          This is probably the problem, it makes the most sense. In general

          <register type="XXXXX" mapTo="YYYYY, ZZZZZ"/>

          XXXX - The name of the interface you want to map from. YYYY - Type name ZZZZ - The Assembly name Lets Say you have an interface IFoo, which is implemented in a class with a name Bar, in namespace MyNamespace contained in Baz.dll:

          <register type="IFoo" mapTo="MyNamespace.Bar, Baz"/>

          Often the the namespace and the dll name are the same, but not always.

          Sort of a cross between Lawrence of Arabia and Dilbert.[^]
          -Or-
          A Dead ringer for Kate Winslett[^]

          B Offline
          B Offline
          Bill Warner
          wrote on last edited by
          #5

          Hi Keith, Still no luck. In your example I don't see the second portion of the type or a name attribute. Here is what I have right now:

          K 1 Reply Last reply
          0
          • B Bill Warner

            Hi Keith, Still no luck. In your example I don't see the second portion of the type or a name attribute. Here is what I have right now:

            K Offline
            K Offline
            Keith Barrow
            wrote on last edited by
            #6

            Not the tag name should be "register", not "type" I assume this is a copy and paste error (I did this in my last post - apologies). Type definitions have a standard format in .net: "TypeName, [Assembly], [OtherStuff]" I usually fully-qualify the typename (i.e. prefix it with the namespace), I don't think this is strictly necessary if the type is in the executing namespace. The stuff in "[]" is optional, you only need [assembly] if the type is not in the executing assembly IIRC (I always specify it any way) though the other stuff isn't relevant right now, for completeness you can specify something like:

            "System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

            Defines TextWriterTraceListener type in namespace System.Diagnostics. The Assembly containing the defined type is System.dll, st version 1.0.3300.0 having the neutral culture and can be verified with the supplied public key (to verify it is genuine). This definition format can apply to both your type attribute and mapTo attribute. Reading from your code you need to check: Interface: Frankenstein.Laboratory.Interfaces.dll (from the second part of the type) exists in the bin directory Frankenstein.Laboratory.Interfaces.dll Contains an interface ILabTest in namespace Frankenstein.Laboratory.Interfaces (from the first part of type). Mapped To Type: Frankenstein.Laboratory.DTO.LabTest.dll (from the second part of the mapTo) exists in the bin directory Frankenstein.Laboratory.DTO.LabTest.dll Contains an class AddNewLabTest in namespace Frankenstein.Laboratory.DTO.LabTest (from the first part of mapTo).AddNewLabTest must implement the above interface. General: The projects or dlls containing your mapped types need to be referenced in the project The name is really just an identifier. Strictly you don't need it as you can use a default mapping. What you have looks right, but without the actual project in front of me it is hard to tell. You might want to look at this article, which sets up a basic mapping step by step: http://netpl.blogspot.co.uk/2011/11/unity-application-block-is-lightweight.html[

            B 1 Reply Last reply
            0
            • K Keith Barrow

              Not the tag name should be "register", not "type" I assume this is a copy and paste error (I did this in my last post - apologies). Type definitions have a standard format in .net: "TypeName, [Assembly], [OtherStuff]" I usually fully-qualify the typename (i.e. prefix it with the namespace), I don't think this is strictly necessary if the type is in the executing namespace. The stuff in "[]" is optional, you only need [assembly] if the type is not in the executing assembly IIRC (I always specify it any way) though the other stuff isn't relevant right now, for completeness you can specify something like:

              "System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

              Defines TextWriterTraceListener type in namespace System.Diagnostics. The Assembly containing the defined type is System.dll, st version 1.0.3300.0 having the neutral culture and can be verified with the supplied public key (to verify it is genuine). This definition format can apply to both your type attribute and mapTo attribute. Reading from your code you need to check: Interface: Frankenstein.Laboratory.Interfaces.dll (from the second part of the type) exists in the bin directory Frankenstein.Laboratory.Interfaces.dll Contains an interface ILabTest in namespace Frankenstein.Laboratory.Interfaces (from the first part of type). Mapped To Type: Frankenstein.Laboratory.DTO.LabTest.dll (from the second part of the mapTo) exists in the bin directory Frankenstein.Laboratory.DTO.LabTest.dll Contains an class AddNewLabTest in namespace Frankenstein.Laboratory.DTO.LabTest (from the first part of mapTo).AddNewLabTest must implement the above interface. General: The projects or dlls containing your mapped types need to be referenced in the project The name is really just an identifier. Strictly you don't need it as you can use a default mapping. What you have looks right, but without the actual project in front of me it is hard to tell. You might want to look at this article, which sets up a basic mapping step by step: http://netpl.blogspot.co.uk/2011/11/unity-application-block-is-lightweight.html[

              B Offline
              B Offline
              Bill Warner
              wrote on last edited by
              #7

              Hi Keith, I got the config setup from an example I found online, that seems to work. All my interfaces are implemented. Everything is in the same dll FrankensteinFramework.dll. Inside it I have a namespace for Laboratory called Frankenstein.Laboratory.Interfaces. Inside there I have a method called IAddNewLabTest. The concrete implementation is done in Frankenstein.LAboratory.DTO namespace, in the method AddNewLabTest, which implements the interface. I'm still getting the same error. I've tried a number of things and can't seem to get this working. Thanks, Bill

              K 1 Reply Last reply
              0
              • B Bill Warner

                Hi Keith, I got the config setup from an example I found online, that seems to work. All my interfaces are implemented. Everything is in the same dll FrankensteinFramework.dll. Inside it I have a namespace for Laboratory called Frankenstein.Laboratory.Interfaces. Inside there I have a method called IAddNewLabTest. The concrete implementation is done in Frankenstein.LAboratory.DTO namespace, in the method AddNewLabTest, which implements the interface. I'm still getting the same error. I've tried a number of things and can't seem to get this working. Thanks, Bill

                K Offline
                K Offline
                Keith Barrow
                wrote on last edited by
                #8

                Bill Warner wrote:

                Everything is in the same dll FrankensteinFramework.dll.

                Try:

                <register type="Frankenstein.Laboratory.Interfaces.ILabTest, FrankensteinFramework" mapTo="Frankenstein.Laboratory.DTO.LabTest.AddNewLabTest, FrankensteinFramework" name="FrankensteinFramework"/>

                Note that name defines the name of the mapping not the assembly, it is possible to resolve more than one type to more than one interface, name is used to disambiguate. Hopefully the above should work, I think it is right given your description of the file/class structure. Setting these things up for the first time are always a PITA.

                Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                -Or-
                A Dead ringer for Kate Winslett[^]

                B 1 Reply Last reply
                0
                • K Keith Barrow

                  Bill Warner wrote:

                  Everything is in the same dll FrankensteinFramework.dll.

                  Try:

                  <register type="Frankenstein.Laboratory.Interfaces.ILabTest, FrankensteinFramework" mapTo="Frankenstein.Laboratory.DTO.LabTest.AddNewLabTest, FrankensteinFramework" name="FrankensteinFramework"/>

                  Note that name defines the name of the mapping not the assembly, it is possible to resolve more than one type to more than one interface, name is used to disambiguate. Hopefully the above should work, I think it is right given your description of the file/class structure. Setting these things up for the first time are always a PITA.

                  Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                  -Or-
                  A Dead ringer for Kate Winslett[^]

                  B Offline
                  B Offline
                  Bill Warner
                  wrote on last edited by
                  #9

                  Amen to PITA my brother. I made the changes and still getting the same error: {"The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)":null}. I'm assuming that the issue is in the config. Maybe I'm missing something else. My code errors on :

                  IUnityContainer container = new UnityContainer();
                  var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

                          **section.Configure(container);**            
                  

                  var transform = container.Resolve("AddNewLabTest");

                  I did see that the MApToName, TypeName and Name were all populated correctly in the Registrations section of my Unity configuration section object. Am I barking up the wrong tree?

                  K 1 Reply Last reply
                  0
                  • B Bill Warner

                    Amen to PITA my brother. I made the changes and still getting the same error: {"The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)":null}. I'm assuming that the issue is in the config. Maybe I'm missing something else. My code errors on :

                    IUnityContainer container = new UnityContainer();
                    var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");

                            **section.Configure(container);**            
                    

                    var transform = container.Resolve("AddNewLabTest");

                    I did see that the MApToName, TypeName and Name were all populated correctly in the Registrations section of my Unity configuration section object. Am I barking up the wrong tree?

                    K Offline
                    K Offline
                    Keith Barrow
                    wrote on last edited by
                    #10

                    Bill Warner wrote:

                    Am I barking up the wrong tree?

                    Nope. The line you quote is where the the type information is loaded which is consistent with what you've said in terms of errors. Something is probably wrong with the type definitions , without having access to the project it is hard to tell what though. One thing that is a common gotcha is that you need to reference all dependant assemblies as well, let's say FrankensteinFramework references Log4Net.dll, then you'd have to reference Log4Net.dll plus all its dependancy tree too. Not doing this won't cause a compile time error (one of the drawbacks of DI) so it'll build even though you don't have the references you need. The final thing (OT, this isn't your current problem) is that, given:

                    <register type="Frankenstein.Laboratory.Interfaces.ILabTest, FrankensteinFramework" mapTo="Frankenstein.Laboratory.DTO.LabTest.AddNewLabTest, FrankensteinFramework" name="MappingName"/>

                    you need:

                    var transform = container.Resolve<ILabTest>("AddNewLabTestMappingName");

                    You'll hit this if (hopefully when) you get any further. It also illustrates what the name is for. [Edit] Corrected some of the very poor English wot I wrote.

                    Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                    -Or-
                    A Dead ringer for Kate Winslett[^]

                    B 1 Reply Last reply
                    0
                    • K Keith Barrow

                      Bill Warner wrote:

                      Am I barking up the wrong tree?

                      Nope. The line you quote is where the the type information is loaded which is consistent with what you've said in terms of errors. Something is probably wrong with the type definitions , without having access to the project it is hard to tell what though. One thing that is a common gotcha is that you need to reference all dependant assemblies as well, let's say FrankensteinFramework references Log4Net.dll, then you'd have to reference Log4Net.dll plus all its dependancy tree too. Not doing this won't cause a compile time error (one of the drawbacks of DI) so it'll build even though you don't have the references you need. The final thing (OT, this isn't your current problem) is that, given:

                      <register type="Frankenstein.Laboratory.Interfaces.ILabTest, FrankensteinFramework" mapTo="Frankenstein.Laboratory.DTO.LabTest.AddNewLabTest, FrankensteinFramework" name="MappingName"/>

                      you need:

                      var transform = container.Resolve<ILabTest>("AddNewLabTestMappingName");

                      You'll hit this if (hopefully when) you get any further. It also illustrates what the name is for. [Edit] Corrected some of the very poor English wot I wrote.

                      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                      -Or-
                      A Dead ringer for Kate Winslett[^]

                      B Offline
                      B Offline
                      Bill Warner
                      wrote on last edited by
                      #11

                      Well I got it working. It's Miller time. This did the trick: Thanks a ton for your your help! There's a neat project that demos this at: http://www.codeplex.com/Download?ProjectName=unity&DownloadId=40036[^]

                      K 1 Reply Last reply
                      0
                      • B Bill Warner

                        Well I got it working. It's Miller time. This did the trick: Thanks a ton for your your help! There's a neat project that demos this at: http://www.codeplex.com/Download?ProjectName=unity&DownloadId=40036[^]

                        K Offline
                        K Offline
                        Keith Barrow
                        wrote on last edited by
                        #12

                        No Worries!

                        Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                        -Or-
                        A Dead ringer for Kate Winslett[^]

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups