this seems too simple, to be accurate

J

Jim Butler

What are the drawbacks if any to this approach of not
using the gac for shared components... basically having a
central directory located outside of iis, that all web
applications have a virtual dir named bin pointing to this
dir. like below setup, all on each server in a farm

web site root one
vdir bin points to drive\sharedbin

web application a
vdir bin points to drive\sharedbin

web application b
vdir bin points to drive\sharedbin

web site root two
vdir bin points to drive\sharedbin

web application 2a
vdir bin points to drive\sharedbin

my thinking is that it would be easier/faster to deploy a
new assembly (and its config file, which entails copying
that through dos into the correct location, we read the
config file from the location of the dll) by only copying
to a directory instead of having to gac remove, gac
install, copy config file into dir

thanks, jim
 
S

Steven Cheng[MSFT]

Hi Jim Butler,

Thanks for using Microsoft Newsgroup Service. Based on your description,
you want to create a Virutal Directory named "bin" under each
WebApplication's root Virutal Directroy, the "bin" VD is specified to a
physical path which has some assemblies you want to share in many web
applicaitons. Is my understanding or you problem correct?

As this problem, I think it due to how the ASP.NET web application search
for assemblies when compiled the pages at runtime. By default, the ASP.NET
runtime will search for assemblies at the "bin" sub directoy certain
assemblies not found in GAC. However, the "bin" subdirectoy is the physical
sub directoy, not by virtual path. For example, if you create a sub Virtual
Directoy named "bin" under web app's root Virutal Directory and then put
all the assemblies need into it and delete the physical "bin" sub directory
created by default. When you run the web page, the ASP.NET runtime can't
locate those assemblies correctly. So I don't think it a proper way to
locate shared assemblies like this.

In dotnet, if you want to specifically locate some assemblies in some
different paths, there are serveral approachs:
1. using GAC, I think this is the most convenient and will provide strong
version control for you. But this'll force you to make the assembly
strong-named.

2. To use the confige file for dotnet application. In dotnet, you can
specify the locations for certain assemblies in applicatino's configure
files. For ASP.NET , you can add such configure infomation in the
web.config file.
For example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="en-us" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>


For more detailed information on how to "Specifying an Assembly's
Location", you may refer the following article in MSDN:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconspecifyingassembly
slocation.asp?frame=true

Please check out the preceding suggestions to see whether they are helpful.
If you have any questions on it, please feel free to let me know.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Jim Butler

thanks for the response, what you have surmised is exactly my
question/situation, we have all of our assemblies strong named, i will try
out #2 and let you know how it goes.... i will first try the probing path,
then the dependent assembly route.

jim
 
J

Jim Butler

Steven, i was able to get the probing path to work, but it needs the path to
be a physical path, and not a virtual directory (ie website\sharedbin worked
as long as it was an actual folder under the web site). I can't seem to get
the dependentassembly tag to work though. below is an excerpt from my
web.config file. Is there something missing/wrong?

<dependentAssembly>
<assemblyIdentity name="co.app.assembly"
publicKeyToken="thepublickeytoken"
culture="neutral" />
<codeBase version="1.0.0.1"
href=http://localwebserver/app/sharedbin/co.app.assembly.dll />
</dependentAssembly>

where sharedbin is a virtualdirectory to c:\sharedbin
when accessing the page, i get FileNotFoundException, and directly after the
pre-bind state info, there is a message that states
Log: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind)

this makes it seem like it is ignoring what i have in my web.config, thus
giving the file not found error

thanks jim
 
S

Steven Cheng[MSFT]

Hi Jim ,


Thank you for the response. As for the "dependentAssembly" method, I've
done some test on my side. It does can specify a certain location path for
the dotnet runtime to find the required assembly. For example, I made a
strong-named assembly "GenericComponent.dll" ,version "1.0.0.1", then in
the ASP.NET web application's web.config file, I set as below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="GenericComponent"
publicKeyToken="003114443600b39f" culture="" />

<codeBase version="1.0.0.1"
href="F:\workspace\GenericComponent\bin\debug\GenericComponent.dll"
/>
</dependentAssembly>

</assemblyBinding>
</runtime>

<system.web>
...................

</system.web>
</configuration>

When run the page which called the classes in the dll, it did found it. You
may try checking the Assembly's name version or keyToken attributes to see
whether they were set as the correct value.

In addition, as for the problem you mentioned at start that you want to use
a http web url such as "http://mysite/sharedbin/xxx.dll" to locate the
assembly, I think there'll some limits if you are using the ASP.NET1.1. In
DOTNET, if you specify a assembly's location via weburl in configuration
file, when running , the runtime will try to download the assembly from the
url. Also, every AppDomain have an property named "DisallowCodeDownload"
which determines whether such operation is permitted. It can be get via :
"System.AppDomain.CurrentDomain.SetupInformation.DisallowCodeDownload".
However, this property is set as "true" by default in dotnet 1.1 and didn't
provide any setting to change it in web.config or machine.config file. So
if you want to use the http web url to locate the assembly, maybe you need
to use some workaround to download the assembly manually. For example, use
the "WebClient" class to download the assembly, or specify the asp.net web
application to use the framework1.0. Here is some kb for them:
http://support.microsoft.com/?id=820106

BTW, since to use the web url location will caused so many problems, would
you consider that use a normal file path such as
"c:\foldername\assembly.dll" to specify the "codeBase" of the assembly.
Thus, you also can let serveral different web applications to share the
same folder(with those public assemblies). You just need to set the path in
the <dependentAssembly> element within the web.config file.

Please check out the preceding suggestions. If you have any questions on
them, please feel free to let me know.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Jim Butler

Steven, thanks again for the help,

i was able to get your sample to work, but only if i added a reference to
the dll (set its copy local to false, so it wouldn't already be in the bin
dir), and compiled the application. Here we are using src= instead of
codebehind and not precompiling.

so it works like this (on the aspx page)

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb"
Inherits="WebApplication1.WebForm1"%>
and fails like this

<%@ Page Language="vb" AutoEventWireup="false" src="WebForm1.aspx.vb"
Inherits="WebForm1"%>
with this error
Compiler Error Message: BC30002: Type 'GenericComponent' is not defined

any ideas as to why?

thanks again,

jim
 
S

Steven Cheng[MSFT]

Hi James,


Thank you for the prompt response. Based on the situation you described in
the reply, now the "file not found" exception is caused at the comiple
time(when the page is requested and the dotnet runtime compile the page
class), because you
specify the "Src" attribute in the page directive @page.

In dotnet, when compile the code, the dotnet runtime will search the needed
assemblies from the GAC or the application directory or the "bin" sub
directory for ASP.NET web application. The "dependentAssebmly" attrribute
set in the application config file such as web.config" file:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="GenericComponent"
publicKeyToken="003114443600b39f" culture="" />

<codeBase version="1.0.0.1"
href="F:\workspace\GenericComponent\bin\debug\GenericComponent.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

such setting is used for the runtime to find the assemblies that will be
used by some of the existing assemblies. As for your situation, you set the
page's "Src" attribute to let its page class be compiled when first
requested, the compiler have no information about the "denpendentAssebmly"
set in the web.config file, this is why the "file no exception" occured.

If you do think it very important to specify the "Src" attribute of the
page to dynamicaly compile page class, I recommend that you use the GAC to
provide the shared assemblies. Otherwise, you'd have to gather those
asseblies in the web application's sub "bin" directory.

Please check out my preceding suggestions. If you have any questions on it
or you have any further information on your problem, please feel free to
let me know.


Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
J

Jim Butler

stephen,

that is kinda what i figured, worth a thought and try, thanks for all the
help anyway. we will probably automate the push into the gac of the shared
assemblies.

thanks again,

jim
 
W

Wolfgang Kaml

Steven,

I understand that this entry is necessary so that the compiler will find the
already compiled web service assembly .dll file in the GAC, correct? If that
entry has to be made in the web.config file, then this file will be
necessary for each web page (virtual path) that I want to use that web
service, correct?
To avoid coping the web.config file into multiple directories or maintaining
those if I want to publish a new assembly for all the web sites, can I add a
certain entry to the e.g. machine.config? If that is possible, can you give
an example?

Your help on that is highly appreciated!!!
Thank you,
Wolfgang
 
W

Wolfgang Kaml

Finally!!!

I have been able to figure it all out.

After the DLL has been added to the GAC (you will need to create a strongly
typed DLL to be able to add your DLL to the Global Assembly Cache GAC), you
have to add the DLL manually to the machine.config file that is located
under:
%systemroot%\Microsoft.net\Framework\<versionnumber>\config

The lines to be added have to be added in the following structure: (This
example adds the WebCounter.dll)
<configuration>
<system.web>
<compilation debug="false" explicit="true" defaultLanguage="vb">
<assemblies>
<add assembly="WebCounter, Version=1.0.1480.30047, Culture=neutral,
PublicKeyToken=c434ff78305dda8b" />
</assemblies>
</compilation>
</system.web>
</configuration>

Verson and PublicKeyToken can be retrieved from the GAC that is located
under:
%systemroot%\assembly
Locate your DLL that you have added to that store, and right click to check
the info in the properties.

BTW, a handy dandy idea is to add the following tool to your MS VS.NET
Development IDE:
(select menu "Tools" - "External Tools" - "Add")
Enter the following fields:
Title: "Create Assembly Ke&y File"
Command: "D:\Microsoft\Microsoft Visual Studio .NET
2003\SDK\v1.1\Bin\sn.exe" (needs to be adjusted to your drive and path for
sn.exe)
Arguments: "-k $(TargetDir)$(TargetName).snk"
Initital Directory: "$(TargetDir)"
Check the option: Output window (that will allow you to copy & paste the
output file after successful generation into the AssemblyKeyFile directive
of your AssemblyInfo.vb file.

From now on you will be able to select that command and the tool will create
the key pair file for you that will have to be added to the DLL project's
"AssemblyInfo.vb" file in the following line:
<Assembly:
AssemblyKeyFile("E:\Development\WebTools\WebCounter\obj\Release\WebCounter.s
nk")>

Hope that this info will help somebody to save a lot of trouble. I wished
that info would be available as a knowledge base article on MSDN.

All the best,
Wolfgang Kaml
 

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

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top