views:

540

answers:

1

I created a VB.NET Class, and created a strong key, and added it to the GAC using the GacUtil. That part has gone smoothly. The Assembly is installed in the GAC and seems to be installed/configured correctly.

FYI, the assembly is a Class called Tester, that exposes one public static method called HelloWorld, which returns a string, "Hello World".

The next step was to create a test web application (VB.NET and ASP.NET 2.0), using Visual Studio 2005, Windows XP SP3. I created the test web application and added the following to the web.config file's configuration section.

<assemblies>
<add assembly="BenGACTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e5b6cecb56999ca" />
</assemblies>

I then added some inline code to my aspx page as follows:

<div><%=BenGACTest.Tester.HelloWorld()%></div>

When I run the page in the web browser, indeed everything works as expected. The page outputs "Hello World" and all seems good.

However, I don't know how to use this code in the code-behind page. I try to import the assembly, just like "imports system" and it doesn't appear in the IntelliSense.

Also, when I try to add the assembly as a reference to the project, the assembly is not found in the list of installed assemblies. I believe this is because the list is pulled from the registry, not from a dynamic list of installed assemblies.

My goal is to add the assembly via the web.config file, not by adding it as a project reference, and to use the assembly in the code-behind page.

Any ideas?

+4  A: 

You can just reference a local version to use the DLL in Visual Studio, .NET will favour the GAC version when running the application. Furthermore, I don't believe you have to ship the DLL when it's available in GAC, yet you have to reference it through menu Project->Add Reference.

Edit: This forumpost might be helpful: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/63bf8d34-42ad-4f3c-b0c9-cf7c33d77918.

Jan Jongboom
I would like to avoid adding a reference manually. Especially since adding the assembly via the web.config file and using the code in an aspx page via inline vb works fine. How can I use the code inline, but not in the codebehind?
NJITBEN
The application has to be aware that the assembly needs to be referenced, so just reference the project. You don't need to redistribute the DLL's or something, so what's the big deal?
Jan Jongboom