Tuesday, 15 January 2013

c# - CodeDomProvider failed to resolve my assemblies in website Bin folder when dynamically compiling code -


All,

I have the asp.net website and all the necessary assemblies I have in my bin folder My dynamic compiled code reference I compile my code in the run-time using CodeDomProvider.

When I compile my expression from the following line

  compiler.CompileAssemblyFromSource (expr);   

I get an error: Metadata file 'NHibernate.dll' can not be found , although it is in the assembly bin folder .

Note: I have a code that works in a window app, if not equal.

Here's my code:

  CodeDomProvider compiler = _GetCompiler (); Compiler parameter compiler perm = _GetCompilerParams (); Compiler results result = compiler.CompileAssemblyFromSource (compiler, EXP); If throw a new invalid operation exception ("Results :Air.Count.Count.01)" ("Failed to compile criteria expression for the following reasons:" + _GetAllCompilerErrors (Results .adders)); Private CodeDrop Provider _GetCompiler () {dictionary & lt; String, string & gt; ProviderOptions = New Dictionary & lt; String, string & gt; (); Provider options Add ("Compiler Version", "v2.0"); CodeDomProvider compiler = New CSharpCodeProvider (provider options); Return compiler; } Private Compiler Parameters _GetCompilerParams () {Compiler Parameter Compiler Perm = New Compiler Parameter (); CompilerParams.GenerateInMemory = True; Compiler mercury Generate Fraa = false; CompilerParams.ReferencedAssemblies.AddRange (new string [] {"System.dll", "NHibernate.dll",}); Return compiler param; }   

I had the same problem, just solve it by adding bin Use the

folder in the path instead of Em> "NHibernate.dll" :

  path.gate directoryname (System.Reflection.Assembly.GetExecutingAssembly (  

Location "+ \\ NHibernate.dll")

This will now give the bin directory for "NHibernate.dll" in the same way.

I hope this will work for you too

No comments:

Post a Comment