Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

help using assemblies from GAC

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dimagofman@googlemail.com - 25 Jun 2007 20:06 GMT
Hi,
I have an asp.net application and a number of assemblies in GAC. These
assemblies have to be in GAC because they are used by other services.

I figured out how to get ASP.NET to reference them in web.config using
<system.web><compilation><assemblies>

How can I reference assemblies without version number? Basically I
want ASP.Net to use the latest version unless I specify a specific
version to use. According to msdn documentation the everything except
the assembly name is optional in <add> but removing the "Version" part
of the attribute "assembly" of element "add" doesn't seem to do it.

Additionally is it possible to add assemblies with a wildcard? The set
of assemblies I have are all named:

CFA.FormatConverter.something
CFA.DB.something
CFA.xxx.something

and the names represent namespaces in those assemblies.

so is it also possible to add "CFA.*" in web.config? the obvious ".*"
doesn't work

Regards

Dima
Peter Bradley - 26 Jun 2007 08:24 GMT
My understanding is that .NET looks for assemblies first in the GAC anyway.
So you shouldn't need to specifically point your application at them at all.
Maybe I've misunderstood how things work.

Peter

> Hi,
> I have an asp.net application and a number of assemblies in GAC. These
[quoted text clipped - 24 lines]
>
> Dima
dimagofman@googlemail.com - 26 Jun 2007 14:00 GMT
Peter,
No it would seem not, here's what i've tried:

remove the <add> elements for my assemblies from web.config (meanwhile
the assemblies are in the GAC) - doesn't find it
put all my assemblies into 1 folder on the server's local hard drive,
added that location to HKLM\Software\Microsoft\.NETFramework
\AssemblyFolders\CFA Assemblies!Default
that's the trick to getting your assemblies to show up in "Add
References" box in visual studio - same result
tried <add assembly="*"> - same result

oh and between the trials I've been restarting the webserver...

D

> My understanding is that .NET looks for assemblies first in the GAC anyway.
> So you shouldn't need to specifically point your application at them at all.
[quoted text clipped - 34 lines]
>
> > Dima
Peter Bradley - 26 Jun 2007 14:40 GMT
Are you talking about the compiled code-behind for your web site, or about
assemblies accessed by your web site's code behind?  If it's the latter, all
I can say is that it works for us from the GAC.  We've never put anything in
Web.config under any version of the .NET framework.

I forgot to say that the Framework's second port of call when looking for an
assembly is in the system32 assembly (but on on Windows, of course).  But
that's not really relevant for you.

If you want the Framework to get something from the GAC, you must be sure
that the version in the GAC is exactly the same as the version referenced in
your solution.  This means not only that the version number and all the rest
are exactly the same, but also that the bytecode is exactly the same
(otherwise the hash will be different).  So even if you change one semicolon
in your code and recompile as the same version, the Framework will no longer
be able to find it via its strong name.

HTH

Peter

> Peter,
> No it would seem not, here's what i've tried:
[quoted text clipped - 52 lines]
>>
>> > Dima
dimagofman@googlemail.com - 26 Jun 2007 16:07 GMT
Peter,

it's the latter, the assemblies are VB.NET, Application type: Class
Library and are signed (non-delay) so they are strong named.
So I specify the version for Assembly Version and File Version (and
keep those the same - it's confusing enough as it is). Then compile
and drag-drop the assembly into c:\windows\assembly (compile on my
workstation and drag-drop on my dev server). That's how I install them
into the GAC (maybe this is wrong? maybe I should use the command line
util?)

To take a specific example
The structure of code in an assembly is like so:

Namespace DB
 Public Class DB
 End Class
 Public Class Objects
 End Class
End Namespace

and the Project is compiled with the following properties:

Assembly name: CFA.DB
Root namespace: CFA

You said you don't mention your assemblies in the web.config, how do
you reference the namespaces/objects in your code-behind? On my page
where I need to use one assembly I have:

<%@ Page Language="VB" %>
<%@ Import Namespace="CFA.DB" %>

then somewhere on the page:

Dim blah As New CFA.DB.DB

Is this how you do it?
That works if I have this in web.config:

<add assembly="CFA.DB, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=xxx"/>

I must admit I find this process very confusing, so much for "the end
to dll hell", COM was much easier.

D

> Are you talking about the compiled code-behind for your web site, or about
> assemblies accessed by your web site's code behind?  If it's the latter, all
[quoted text clipped - 77 lines]
>
> >> > Dima
Peter Bradley - 26 Jun 2007 19:28 GMT
Ysgrifennodd dimagofman@googlemail.com:

Comments in the text.  My examples are in C#, because that's what I use.
 VB gives me the creeps:

> Peter,
>
[quoted text clipped - 6 lines]
> into the GAC (maybe this is wrong? maybe I should use the command line
> util?)

If you're using .NET 2.0, you're *possibly* putting them in the wrong
place.  What version of .NET are you using?

I always use the tools provided in Visual Studio to put stuff in the GAC
- either gacutil or the configuration tool.

http://visualbasic.about.com/od/usingvbnet/a/asmnet01_3.htm

The following url (http://www.codeproject.com/dotnet/demystifygac.asp)
says this about configuring the gac:

<quote>
In order for the GAC to be useful, we need to be able to interact with
it. I am aware of the following five interfaces available for such
interaction.

   1. The Windows Installer 2.0
   2. The command line tool GACUtil.exe
   3. The Windows Shell namespace extension implemented in SHFusion.dll
   4. The .NET Framework Configuration Administrative tool
</quote>

Also bear in mind what I said about recompilation.  It's not enough that
the version number, culture etc etc match.  The hash of the code has to
match.  So any recompile means you have to put the new assembly in the
GAC and renew all your references in order to import the correct dll to
compile against.  Forgetting to renew references is a favourite gotcha.

> To take a specific example
> The structure of code in an assembly is like so:
[quoted text clipped - 14 lines]
> you reference the namespaces/objects in your code-behind? On my page
> where I need to use one assembly I have:

Add references in the code-behind.  Just as I would in any other .NET code.

> <%@ Page Language="VB" %>
> <%@ Import Namespace="CFA.DB" %>
[quoted text clipped - 8 lines]
> <add assembly="CFA.DB, Version=1.1.0.0, Culture=neutral,
> PublicKeyToken=xxx"/>

It would work if you were coding in-line.  For example it works for
Global.asax.  But if you're using code-behind your Page declaration
should look something like this (for a default.aspx page):

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="user" %>

If you use code behind, you can add references as you would into any
.NET project.

Global.asax, for example, is always in-line in .NET 2.0, so I have
something like this for inline coding:

<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Security.Principal" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    etc, etc

</script>

Are you using code behind or inline code?  I suspect the latter, from
what you've said.  Is there some reason you're not using code behind?

> I must admit I find this process very confusing, so much for "the end
> to dll hell", COM was much easier.

Now I know you're joking!

:D

Peter

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.