I am trying to compile some code into memory at runtime using CodeDomProvider.
The code I'm compiling has a link to an external assembly, which I include in the options used to compile the code.
When I compile into memory and try to use reflection in the assembly generated in the Visual Studio add-in, it throws an exception saying that it cannot find the link to the assembly.
(Exception)
"Cannot load one or more of the requested types. Get more information about the LoaderExceptions object."
(LoaderException)
"{" Failed to load file or assembly "Dynamo.Jiss.Task, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" or one of its dependencies. The system cannot find the specified file. ":" Dynamo.Jiss.Task, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null "}"
I tried to reference the assembly from different places using the absolute path.
The exact same code works fine if it is run from the Console application, and it also works fine in the add-in if I don't compile to memory.
Removing a link to an external assembly and the code that references it also works when compiling to memory, so it is likely that as the exception is described, there is a problem loading the referenced assembly.
Does anyone have an idea why compilation into memory and assembly reference do not work in add-in?
Are there any limitations in running AppDomain or something I should know about? (now my best guess)
Should it be in a specific folder? using relative path? Security Settings? need to sign? any ideas?
What I'm trying to achieve is a way to put files with a specific extension into a project and let it automatically compile it, and if it implements the ITask interface (from an external assembly), it will call the Setup () method, which allows the code to connect to Visual Studio events and execute tasks / scripts while listening to different events. Thus, I can easily execute text templates if another file has been modified, or Combine and Minify files for different events (document saving, assembly, etc.).
Something like this already exists (to save me from the pain)? :)