How to load assembly from .cs file

  • Thread starter Thread starter ss
  • Start date Start date
S

ss

I have a .cs file and i want to refer to it at run time
without compiling it into a dll. Is it possible?
 
I have a .cs file and i want to refer to it at run time
without compiling it into a dll. Is it possible?

If you by "refer" mean run the code, then no. You have to compile it
first.



Mattias
 
Thanks Mattias..
But, then how it is done in webservices [.asmx]
<@Assembly Src="" /> Directive?

Is it that the @Assembly Directive first compiles and
places in the assembly ? If so, do you know any such
equivalent tag for .aspx files ?
 
In addition to what Mattias said - you can't run source code as it is.
However, you can always compile it and run it as another assembly - by
loading it into your AppDomain, using remoting, process call or whatever
method you prefer.

You can even write your own emulator or interpreter of .Net. However I am
not sure if this makes any sense.

HTH
Alex

Thanks Mattias..
But, then how it is done in webservices [.asmx]
<@Assembly Src="" /> Directive?

Is it that the @Assembly Directive first compiles and
places in the assembly ? If so, do you know any such
equivalent tag for .aspx files ?
 
yes, in ASMX, the code is compiled before running.

In ASPX, you can do this:

<%@ Page Language="VB"
Src="HelloWorld.aspx.vb"
Inherits="MyNamespace.MyTypeName"
Debug="true"
Trace="true"
%>

And then in source file HelloWorld.aspx.vb, you define a type
MyNamespace.MyTypeName that Inherits System.Web.UI.Page. This gets JIT
compiled when the page is requested.

reference:
from
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsCodeModel.asp

-Dino


--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m


Thanks Mattias..
But, then how it is done in webservices [.asmx]
<@Assembly Src="" /> Directive?

Is it that the @Assembly Directive first compiles and
places in the assembly ? If so, do you know any such
equivalent tag for .aspx files ?
 
Ok..
so in this case, suppose in MyTypeName, i am using some
other assemblies, clases that are defined in seperate
files, will it compile and load them too ?
-----Original Message-----
yes, in ASMX, the code is compiled before running.

In ASPX, you can do this:

<%@ Page Language="VB"
Src="HelloWorld.aspx.vb"
Inherits="MyNamespace.MyTypeName"
Debug="true"
Trace="true"
%>

And then in source file HelloWorld.aspx.vb, you define a type
MyNamespace.MyTypeName that Inherits
System.Web.UI.Page. This gets JIT
compiled when the page is requested.

reference:
from
http://msdn.microsoft.com/library/en- us/vbcon/html/vbconWebFormsCodeModel.asp

-Dino


--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m


Thanks Mattias..
But, then how it is done in webservices [.asmx]
<@Assembly Src="" /> Directive?

Is it that the @Assembly Directive first compiles and
places in the assembly ? If so, do you know any such
equivalent tag for .aspx files ?

-----Original Message-----

If you by "refer" mean run the code, then no. You have to compile it
first.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.


.
 
some more details on what i want to do.

see, the aspx file will surely compile the .cs file which
i place in the Src="" tag. The issue which i face is that
in the aspx.cs file, i refer to some common functions
defined in some common.cs file and some business logic
objects defined in bussiness.cs file. I want these files
also to be compiled along with the .aspx.cs file.
In .asmx files, <@Assembly Src="" /> directive does that.
I can also specify multiple <@Assembly Src="" /> tags to
load as many assemblies as i need. however, i am not sure
if that will work in .aspx file too.

I tried it with the Src="" tag in .aspx file but it is not
able to load the dependency files.

-----Original Message-----
yes, in ASMX, the code is compiled before running.

In ASPX, you can do this:

<%@ Page Language="VB"
Src="HelloWorld.aspx.vb"
Inherits="MyNamespace.MyTypeName"
Debug="true"
Trace="true"
%>

And then in source file HelloWorld.aspx.vb, you define a type
MyNamespace.MyTypeName that Inherits
System.Web.UI.Page. This gets JIT
compiled when the page is requested.

reference:
from
http://msdn.microsoft.com/library/en- us/vbcon/html/vbconWebFormsCodeModel.asp

-Dino


--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m


Thanks Mattias..
But, then how it is done in webservices [.asmx]
<@Assembly Src="" /> Directive?

Is it that the @Assembly Directive first compiles and
places in the assembly ? If so, do you know any such
equivalent tag for .aspx files ?

-----Original Message-----

If you by "refer" mean run the code, then no. You have to compile it
first.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.


.
 
Back
Top