@Assembly Directive Question


Jim Heavey

I am trying to figure out the @Assembly directive.

I have an application which uses "codebehind" and only uses source code,
so I
am using the "src=" option of the @Page directive. So I have something
looks like the following:

ASPX Files ASPX.VB Files
Page1.aspx Page1.aspx.vb
Page2.aspx Page2.aspx.vb
Page3.aspx Page3.aspx.vb

Now all of these three pages have a common program, let's call it
which is called from Page1.aspx.vb, Page2.aspx.vb, Page2.aspx.vb.

When I run using the @Page src="Pag1.aspx.vb" inherits="Page1", when
Page1.aspx.vb instatiates the "Common.vb" I get a compile error
that the class can not be found.

If I copy "Common.vb" and append it to "Page1.aspx.vb"... then no
problem, it
works just fine.

I am trying to find a way to enable these pages to find "Common.vb"
without me
having to copy the source into each of these pages.

I have taken to "Common.vb" and created a seperate project, and compiled
and placed the code in the "bin" folder, but still not luck.

Looking at the @Assembly option, it would appear to me that this may
allow the
assembly to be found, but no matter what I put into this directive, even
garbage, it has not effect. It has a "src=" option which indicates that
specified program will be compiled on the fly.

So any ideas as to what I need to do to enable the program to be found
compiled on the fly? Or for that matter, found in the "bin" folder?
I believe it will look in the "Bin" folder for the "folder" which is
identified as an "application folder" and unfortuneatly the folder that
I am
executing from is not an application folder and nor do I have access to
folder which is the application folder to place my compiled program

Your assistance would be greatly appreciated!!!!!!!!!!!



Chris Jackson

If you are using the src option, you are indicating that your class should
be dynamically compiled. As such, you should be aware of where this is
taking place - it is placing compiled versions of the pages you want into a
web cache, where it can not locate other source files that you may intend to
rely on.

A better approach would be to pre-compile the codebehind pages and use the
CodeBehind attribute. Now, during dynamic compilation, it will search for
this code in compiled form in the bin directory, and all of your references
to another class will be compiled into the same assembly and accessible from
your code behind pages. If you need to get at this from your declarative
page (inside of a code declaration/code render block) then you may want to
consider creating wrappers from your code behind, or else using inheritance.
(For example, creating a new SpecialPage that derives from
System.Web.UI.Page, and then having each of your pages derive from this

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question