Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:35:55+00:00 2026-05-23T23:35:55+00:00

i am trying to compile some code to memory at runtime using a CodeDomProvider.

  • 0

i am trying to compile some code to memory at runtime using a CodeDomProvider.

The code I am compiling have a reference to an external assembly which I include in the parameters used when compiling the code.

When I compile to memory and try to use reflection on the assembly generated in a Visual Studio Add-In it throws an exception saying that it can’t find the referenced assembly.

(Exception)
“Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.”

(LoaderException)
“{“Could not 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 file specified.”:”Dynamo.Jiss.Task, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”}”

I have tried referencing the Assembly from different places using the absolute path.

The exact same code works fine if it is run from a Console application, and it also works fine in the Add-In if I do not compile to memory.
Removing the reference to the external assembly and the code that reference it also works when compiling to memory, so it probably as the exception describes is a problem with loading the referenced assembly.

Do anyone have an idea why compiling to memory and referencing an assembly isnt working in an Add-In ?

Is there some restrictions within the AppDomain it is running or something that I should be aware of? (my best guess currently)

Should it be in a specific folder? referenced using a relative path? security settings? needs to be signed? any ideas?


What i am trying to achieve is a way to put files with a specific extension in a project and let the addin automatically compile it and if it implements an ITask interface (from the external assembly) it will call a Setup() method that makes it possible for the code to hook into the Visual Studio events and execute tasks/scripts while listening to the different events. This way I can easily execute Text templates if another file is changed, or Combine and Minify files on different events (document saved, build etc.).

Does something like this already exist (to relieve me from the pain) ? 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:35:55+00:00Added an answer on May 23, 2026 at 11:35 pm

    This is most likely happening because you’re telling CodeDom to generate an in-memory assembly (which is really a lie since it’s generating temporarily to disk, loading it, then deleting the file). The point is, the compile directory for the CodeDom assembly is not the same as the one you’re using to compile it. That is, if you’re running in bin\Debug, the CodeDom assembly is being generated to %temp%.

    You could solve this in one of two ways I can think of:

    1. Compile the CodeDom assembly to the same path as your executing assembly.

      myCodeProvider.GenerateInMemory = false; // may not be necessary...haven't tried this in a while
      myCodeProvider.OutputAssembly = string.Format(@"{0}\{1}", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location, "mydll.dll");
      
    2. Handle the AssemblyResolve event and provide the CodeDom assembly the referenced assembly it’s requested.

      AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve
      
      private static Assembly OnCurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
      {
                      // this is absurdly expensive...don't do this more than once, or load the assembly file in a more efficient way
                      // also, if the code you're using to compile the CodeDom assembly doesn't/hasn't used the referenced assembly yet, this won't work
                      // and you should use Assembly.Load(...)
                      foreach (Assembly @assembly in AppDomain.CurrentDomain.GetAssemblies())
                      {
                          if (@assembly.FullName.Equals(args.Name, StringComparison.OrdinalIgnoreCase))
                          {
                              return @assembly;
                          }
                      }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile such code: #include <iostream> using namespace std; class CPosition {
I was trying to compile a program using an external compiled object coreset.o. I
I'm trying to compile some code in MonoTouch but I'm getting an error: 'type
I was trying to compile some C++ code in Xcode and I got this
I'm trying to compile some given assembler files (.S) for Android using the NDK.
I'm trying to compile some downloaded source which contains lots of: 142 #ifdef __cplusplus
When trying to compile a file that include winnt.h via windows.h, I get the
i am trying to compile this very simple piece of code class myList {
I'm trying to compile a POCO with this code public class MenuItem { public
I had some code that I developed on Ubuntu and now I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.