How to use DLLs from GAC in ASP.NET apps?

A

Andrey Mazurov

Hi!

Please advise. Can I use DLLs from GAC in ASP.NET applications? How?

Thanks,
Ray
 
H

Hermit Dave

you can either choose to add a reference to the dll and then use "using
namespace" for classes within the specified namespace to be available...
alternatively you can add @Assembly="assembly.dll"

Regards,

HD
 
A

AlexR

Hermit Dave said:
you can either choose to add a reference to the dll and then use "using
namespace" for classes within the specified namespace to be available...
alternatively you can add @Assembly="assembly.dll"

Regards,

HD


I have a similar problem because I've added my own Assembly to the GAC
(it has a strong name btw) however it is not visible from the Add
Reference .Net Tab in Microsoft Visual C# .NET.

I have had to fix this by modifying the registry to point to an
assemnbly file like this:


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\<name>]
@="C:\\Projects\\<name>\\CoreServices\\CoreServicesLibrary\\"

Then any dll in this directory is visible in the assembly list.
 
A

Andrey Mazurov

I have a component in a separate DLL. This DLL has public key and is placed
in GAC. When I use this component on a web page, ASP does not take this
component from GAC. Maybe I should tune ASP.NET, in order to make it work?
Please advise.

Thanks, Andrey
 
J

John Timney \(Microsoft MVP\)

I have seen GAC registered components fail to load in ASP.NET because they
were not culture neutral in the assembly info when the DLL was compiled.

Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------
 
W

Wolfgang Kaml

John,

I have been running into the same problem. As long as the assembly .dll is
in the local /bindirectory, all works fine. As soon as I delete it there and
put it into the GAC instead, I get errors, that it can't be found in the
/bin directories.
Can you tell us what directive has to be put into the aspx header or if one
of the config files has to be adjusted? e.g. web.config, machine.config, or
aspnet.config? I'd prefer not to change web.config, but maybe the others,
since the web.config would have to be copied into every single local web
site then. That would add unnecessary maintenance, just like making multiple
copies of the assembly's dll for each /bin directory.

If you could give me some idea, as of what to change, that would be great!
Thanks for your help!
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
 
L

lucky_hemya

Thanks Wolfgang,
for giving info about adding Sn.exe
:?: But does this means when ever we sign assembly with Strong Name
.. That particular line in machine.config will be added automatically
or we have to do it manually ?
 
J

John Timney \(Microsoft MVP\)

If your adding to the GAC you must strong name any assemblies and add them
to your web.config. You will usually add this manually.

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------

lucky_hemya said:
Thanks Wolfgang,
for giving info about adding Sn.exe
:?: But does this means when ever we sign assembly with Strong Name
. That particular line in machine.config will be added automatically
or we have to do it manually ?



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
B

Brent

Yeah, I've been losing sanity lately over getting an assembly in the
GAC to be read by my application. I've been trying to convert common
functions, which were in .asp pages and referred to by #include
statements, to .NET assemblies.

I had added a strong-named assembly successfully into the GAC and put
the '<add assembly...' statement in Web.Config. It failed. Then I
added the reference to Machine.Config and it worked. I'm glad it's
working now but does anyone know why it would fail in Web.Config?

Also, I've noticed the following:

When I update an assembly in the GAC whose version number has changed,
applications using it will need to be recompiled with the latest
'copy' of the assembly in References, i.e., the assembly version used
in the application must match the assembly version in the GAC
otherwise I get an error.

So, everytime I update the shared assembly, I need to recompile
applications using it? Is that true? If I don't alter the version
number, will the latest assembly be downloaded to the application?
Finally, if the assembly reference in my application is not the latest
(when I'm compiling), will that matter?

Thanks for any help.
 
B

Brent

I answered my own question about my assembly not loading from
web.config and that's because I didn't put the '<add assembly..' line
under the 'compilation' section, so it choked. I took the assembly
reference out of machine.config because, as I understand it, if I
modify my assembly (with the assembly reference in machine.config)
then I have to kill the aspnet_wp.exe process to get the new assembly
loaded, which I can't afford to do. So, I put the assembly line back
in web.config, in the right place this time, and tested my application
while modifying the assembly in the GAC. Thankfully, it downloaded the
right version every time as long as I modified web.config with the
correct assembly version number.

Gosh, I'm glad that's over...
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top