2

I'm generating an assembly (*.dll) at runtime. the compilation process is performed using CodeDom, as is recommended in following post:

Generating DLL assembly dynamically at run time

My code and assembly are generated successfully, not errors. The problem comes when I'm attempting load this generated assemblies at runtime via reflection using :

 // load for reflection only
 var _assemblyTempLoad = Assembly.LoadFrom(assembly.FullName);

Following exception is thrown:

"Could not load file or assembly 'nameforassembly.dll' or one of its dependencies. The module was expected to contain an assembly manifest."

How to generate the manifest file or fix this issue?

I want clarify that assembly is generated at runtime, using following code:

CompilerResults compilerResult = codeDomProvider.CompileAssemblyFromFile(compilerParameters, Path.Combine(path, sourceCodeFile));`

Thank you in advance

4

2 回答 2

0

Have you tried the following

compilerParameters.CompilerOptions = string.Format("/win32manifest: {0}", manifestFilename);

If you've already have the CompilerOptions set to some value, just concatenate the strings

compilerParameters.CompilerOptions += string.Format(" /win32manifest: {0}", manifestFilename);

The win32manifest parameter tells the compiler to also generate a manifest file.

于 2012-07-14T16:59:44.313 回答
0

when an assembly is created at runtime (on the fly), the assembly info or metadata is not placed into assembly automatically. The use of the [Assembly] attribute was necessary too. On this way, the last step in the process was place the /platform argument to the compiler (thanks sgmoore). I can saw this using Redgate reflector. The assembly was shown without versioning and metadata attributes. Like this:

streamWriter.WriteLine(string.Format("[assembly: AssemblyTitle(\"{0}\")]", yourassembly.propertyfornamespace.Replace(" ", "")));
streamWriter.WriteLine(string.Format("[assembly: AssemblyDescription(\"{0}\")]", yourassembly.propertywithdescription));
于 2012-07-17T21:13:17.463 回答