Ticket #23 (closed enhancement: fixed)

Opened 4 months ago

Last modified 4 months ago

using statements for unloaded assemblies

Reported by: Justin Chase Assigned to:
Priority: major Component:
Keywords: Cc:

Description

Support a <use namespace="" import=""/> or <use namespace="" assembly=""/> syntax in spark templates.

Probably prefer <use assembly=""/> since it could be used without the namespace="" attribute.


I have a situation where I would like to call methods defined in an external assembly in my spark template. I added a reference to that assembly but I never call anything in that assembly in my actual code so the C# compiler decides to make an optimization and it drops the reference. :-(

If I look at AppDomain?.CurrentDomain?.GetAssemblies?() I can clearly see that this assembly is not loaded and if I call Assembly.GetExecutingAssembly?().GetReferencedAssemblies?() I can see that the assembly I have referenced is completely dropped from the list. If, however, I manually load the assembly by calling Assembly.Load("NBusiness.Utilities"), just before creating the view instance everything works fine.

Sooo, that makes me think that you could probably get away with having an optional "import" attribute on the use elements? I propose something like this:

<use namespace="NBusiness.Utilities" import="NBusiness.Utilities, Version= 1.0.0.0, PublicKey?=ASDF123..." />

Then you could spin through the currently loaded assemblies and if it is not already loaded into the current appdomain just call "Assembly.Load(use.Import)". I can get this to work for now by just loading this assembly but with this system these templates are customizable and there is no telling what sorts of assemblies people will want to load so I need some sort of lower level solution.

-- Justin Chase http://www.justnbusiness.com

Change History

07/30/08 01:57:36 changed by louis.dejardin

  • status changed from new to closed.
  • resolution set to fixed.

Implemented. At the moment, since all assemblies in the current appdomain are used as references to the compiler, the only thing that needed to be done was to load the named assembly.

Local assemblies and strong names in the gac should both work.