Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top