0

So, I inherited a project that seems to be using Spring.net extensively to do dependency injection. Every executable module implements a method where it goes to the Application config file for the given module and pulls a value along the lines of assembly://Config/Company.Protocol.Config/DIConfig.xml with the middle bit of "Company.Protocol.Config" being slightly different for different executables, bearing a name similar, but not identical to, the project. That XML file seems to be contained within a Config directory at the base of the solution holding the project. While I feel that things are a bit overcomplicated, I see what they're aiming for, storing references to various processing routines in that DIConfig.xml file so that they can be injected.

The problem I'm running into is that I can't actually seem to navigate to those XML files with the specified path above, and my attempts to understand Spring.net don't seem to go far enough to understand where they plan to go with the "Assembly://" bit. I get a Could not resolve resource location error. I've tried contacting the person who last worked with the code, but apparently they inherited it too, and have avoided messing with it for fear of breaking it.

I think that the intent of the line above is to go to the base of the assembly, then the Config directory or project, then get the DIConfig.xml there, but when I try to use that, it can't find the file. I've tried removing the bit between Config and DIConfig.xml just in case this was a matter of there used to have been directories in between, but no dice. I can get it to "work" by dropping the DIConfig.xml file into the same location as the executable and changing the file to be read to simply "DIConfig.xml", thus in the same directory, but of course, that's not very extensible, particularly when I try to run the service that uses this.

Sean Duggan
  • 1,105
  • 2
  • 18
  • 48

1 Answers1

2

The assembly:// tells Spring.net to use the "assembly" protocol to locate the resource. It has the general format assembly://<AssemblyName>/<NameSpace>/<ResourceName>. So in the case of assembly://Config/Company.Protocol.Config/DIConfig.xml there should be an assembly named Config (not necessarily the same as the project name; check the properties). The xml file is contained in the source project that holds the source for the assembly.

Folders in the project can add to the namespace; so if the root namespace of the project is Company.Protocol, then you'll find your xml file in a folder named Config.

The xml file should be marked as an embedded resource. See section 5.2.2.1 of the docs for more.

Marijn
  • 10,367
  • 5
  • 59
  • 80
  • As it turns out, the issues seems to be that the project containing the embedded XML file needed to be Cleaned and Recompiled before I could see the XML file, but you're the only one who responded, and it helped me discount a few possibilities, so I'm crediting you with the answer. – Sean Duggan Feb 14 '14 at 20:01
  • Ah. And I am even more enlightened after reading Chapter 7. It still works somewhat intermittently, but that's better than before. – Sean Duggan Feb 20 '14 at 15:52
  • Hopefully, this reaches you. Currently, the code only works in Release mode. The Config project where the embedded resource exists is called Config. `Company.Protocol.Config` is its default namespace. The embedded file is there. I've tried checking out the Spring.Net forums, but their image verification is broken (I get broken images at work and at home) which means I can't register and I can't contact them to tell them that it is broken. I can work around the problem for now by providing an explicitly pathed file and routing to that in Debug mode, but it's ugly. – Sean Duggan Feb 26 '14 at 18:46
  • 1
    Hmm, that's strange. Can you confirm that the assembly name is Config and that the assembly is present in the Debug directory? If your project does not have a dependency on the Config project, then your IDE might not copy it to the output directory. BTW the spring.net team shows [activity on Github](https://github.com/spring-projects/spring-net) of late. – Marijn Feb 27 '14 at 07:10
  • {nods} And Erich Eichinger has been active on Stack Exchange, but doesn't have any contact information listed. And your suggestion about the assembly being missing was dead on. I wish I could vote your answer up again. :) Thank you. – Sean Duggan Feb 27 '14 at 12:32
  • You're welcome. Erich contributed a lot to spring.net, but nowadays it's mostly [Steve Bohlen](http://stackoverflow.com/users/23208/sbohlen) and [Marko Lahma](http://stackoverflow.com/users/111604/marko-lahma). – Marijn Feb 27 '14 at 13:35
  • And is there a good way of determining whether said assembly exists other than trying to load it and catching the exception if it doesn't? FileInfo doesn't support this "assembly://" thing and I'm not certain if searching for a DLL in the working directory is the right approach. – Sean Duggan Feb 27 '14 at 14:23
  • Well, IMO, anything you'd do here is working around the bigger problem of having all your config in a separate project (/asm), that, I imagine, also holds the configuration for other projects. You could check for the dll (not bad given the circumstances) but if this only bugs you in Debug mode, why not add a post build step that copies the config dll to `bin\Debug`? When in Rome ... – Marijn Feb 27 '14 at 14:35
  • {nods} I've added a check on the exception so that I can notify calling functions that the configuration failed. I think that should work. Thank you. – Sean Duggan Feb 27 '14 at 14:44