I have a piece of code which uses CodeDom to generate code on the fly. It’s straight forward:
CodeCompileUnitis created and filled with a type.- The unit is passed to
CSharpCodeProvider.CompileAssemblyFromDom. - The assembly is generated in memory and everything is wrapped inside a single static method, which returns an instance of the generated type.
If I call this static method from C#, everything works fine, but it fails if I call the method from IronPython. There are no compile errors and CompiledAssembly of the returned CompilerResults is NOT null. But if I call GetTypes for the assembly, I get a ReflectionTypeLoadException which tells me to look at the LoaderExceptions. That one is a FileNotfoundException giving the following message:
Could not load file or assembly ‘PosData, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The
system cannot find the file specified.”:”PosData, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
PosData is my own assembly which holds the code generation stuff and which is already loaded by IronPython. Everything is in a single folder, so I don’t see what might be missing.
Any hint would be very appreciated!
You could give the Fusion Log Viewer a shot to get more information about what’s going.
See Scott Hanselman’s blog entry and this page on MSDN for details on how to use it.