2

In my AppDomain there are few dynamic assembly, when I try codeDom.CompileAssemblyFromSource to Compile another new assembly, I can't figure out a way to add those dynamic assemble to ReferencedAssemblies.

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
         compilerParameters.ReferencedAssemblies.Add(assembly.Location);
}

Failed, as dynamic assembly doesn't have Location.

Thanks in advance.

PS: I'm actually trying to use ASP.Net MVC 3's new Razor template engine in IronPython.

Wuvist
  • 641
  • 1
  • 5
  • 7
  • Finally could use Razor in IronPython and use IronPython objects as template model. – Wuvist Oct 28 '10 at 12:15
  • However, the loading dynamic assembly issue remains. The template compilation error that I got is actually not related to this issue. – Wuvist Oct 28 '10 at 12:16

2 Answers2

0

Not test, try use assembly.FullName instead of assembly.Location.

Shelvin
  • 136
  • 8
  • 1
    Thx, but FullName is: Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null so, failed. – Wuvist Oct 28 '10 at 08:07
0

I was having similar issue and this blog post: http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx convinced me that there is no way to do this. However this is relatively old post and if there is something new in .net 4 which allow this would be great to know about it.

EDIT:

I can confirm that this is not possible and with .net 4. As CSharpCodeGenerator class is using csc.exe to compile your code it uses the following code to add the referenced assemblies as parameters to the compiler:

foreach (string current in options.ReferencedAssemblies)
{
    stringBuilder.Append("/R:");
    stringBuilder.Append("\"");
    stringBuilder.Append(current);
    stringBuilder.Append("\"");
    stringBuilder.Append(" ");
}

BTW: There are another posts in SO for the same problem:

Supply Assembly to CompilerParameters ReferencedAssemblies from memory and not disk?

In C#, how do you reference types from one in-memory assembly inside another?

Community
  • 1
  • 1
tenkod
  • 297
  • 1
  • 4
  • 9