help using assemblies from GAC

D

dimagofman

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
 
P

Peter Bradley

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
 
D

dimagofman

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
 
P

Peter Bradley

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
 
D

dimagofman

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
 
P

Peter Bradley

Ysgrifennodd (e-mail address removed):

Comments in the text. My examples are in C#, because that's what I use.
VB gives me the creeps:
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?)

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:

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:

Add references in the code-behind. Just as I would in any other .NET code.
<%@ 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"/>

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
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top