Search:
Namespaces
Discussions
.NET v1.1
Feedback
Code DOM help
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.framework.sdk
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
Calvin
I use CodeDOM to create an
Assembly
,
CodeDomProvider
codeProvider = GetCodeProvider();
ICodeCompiler compiler =
codeProvider.CreateCompiler();
CodeCompileUnit compliationUnit =
CreateCompliationUnit();
CompilerResults results =
compiler.CompileAssemblyFromDom(CreateCompilerParameters
(), compliationUnit);
Assembly assembly =
results.CompiledAssembly;
return assembly.GetTypes()
The
Assembly
referd to my current assembly, so I actually
did this with the CompilerParameters:
private
CompilerParameters
CreateCompilerParameters()
{
CompilerParameters parameters =
new
CompilerParameters
();
parameters.GenerateInMemory = true;
parameters.CompilerOptions
= "/t:library";
//Add default assembly
//Add referrence to the current
assembly
string assName =
Assembly
.GetExecutingAssembly().Location;
parameters.ReferencedAssemblies.Add
(assName);
parameters.ReferencedAssemblies.Add
("mscorlib.dll");
parameters.ReferencedAssemblies.Add
("System.dll");
parameters.ReferencedAssemblies.Add
("System.Data.dll");
parameters.ReferencedAssemblies.Add
("System.Xml.dll");
return parameters;
}
My Executing
Assembly
for this piece of code again is
loaded dynamically at run time.
Then I got error at:
return assembly.GetTypes()
The
Assembly
is compiled without error, but when try
assembly.CreateInstance(typename)
it returns null. (The typename is correct!) I use debug to
check:
assembly.GetTypes()
I got the exception:
One or more type in the assembly can't be loaded.
I call GetTypes() only to get a list of the types, how
come I got the exception?
I then checked the detail of the exception, I found out
it's trying to load the referred assembly from current
working directory folder instead of actual PATH I
specified when compile the assembly.
Does this mean if a dynamic assembly call another
dynamically assembly, they can't remember where they are
from?
Thanx,
Calvin
Reply to this message...
Rick Strahl [MVP] (VIP)
Are you creating the type with a full namespace reference? Otherwise you
can't load it.
For more info on dynamic compilation along with a wrapper class that
simplifies this process considerably check out:
http://www.west-wind.com/
articles.asp
and look at the Dynamic .Net Execution article there.
+++ Rick ---
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/
wwHelp
----------------------------------
Making waves on the Web
"Calvin" <
Click here to reveal e-mail address
> wrote in message
news:02bd01c327e2$0dd215f0$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Calvin
Yes, I am using a full class name.
The problem is: The dynamically generated assembly depend
on another assembly which sits in a different directory
other than the APPBase directory.
I added the full path of the assembly as a referrenced
assembly when compile the dynamic assembly. The compiling
is fine, but when I try to create the type, the
referrenced assembly can not be found! The reason is
simple, that assembly is in another directory, the runtime
can't find it!
My problem is: I specified the path when I compile the
dynamic assembly, why it can not found it? It's not in the
APP probing path though. If I copy that assembly to the
app folder, it will work fine.
Apparently, there's a problem of where to find the
assemblies!
[Original message clipped]
Reply to this message...
Rick Strahl [MVP] (VIP)
My understanding is that apps can only load external files from one of two
places:
Your apps directory (root, bin dirs)
The global assembly cache
And actually a third the temporary assembly store.
If a dependant assembly lives ina different location then it will not be
found.
However, if you're doing this at compile time, just make sure that all
dependent DLLs are
in your app path (root,bin dirs). At compile time VS should pull that stuff
for you if you have Copy Local set to true.
If you can't do this then you need to potentially manually move the files
from within your application before executing them...
+++ Rick ---
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/
wwHelp
----------------------------------
Making waves on the Web
"Calvin" <
Click here to reveal e-mail address
> wrote in message
news:04c601c3281e$d7801050$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
System.CodeDom.CodeCompileUnit
System.CodeDom.Compiler.CodeDomProvider
System.CodeDom.Compiler.CompilerParameters
System.CodeDom.Compiler.CompilerResults
System.CodeDom.Compiler.ICodeCompiler
System.Reflection.Assembly
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com