Using <%# Assembly %> reference without CopyLocal - asp.net

I am trying to write a standalone ASPX page (no codebehind) for reasons I won't get into. So I want to have some functions declared in the page. But those functions need to reference assemblies that aren't generally referenced by ASPX pages. This means that I need an <%# Assembly %> reference, as detailed here:
http://msdn.microsoft.com/en-us/library/d864zc1k.aspx
And it all works fine if I have my reference to the assembly set to CopyLocal = true. However, it is in my GAC, so I don't want to set it to copy local. But if I don't have the DLL in my /bin folder, the page does not compile due to a bad reference.
What do I have to do to get the <%# Assembly %> declaration to work against an assembly in the GAC?

Typically assemblies that are in the GAC are referenced in the web.config. Is your assembly referenced in the system.web -> compliation -> assemblies section? If not, adding it should resolve your issue.

Related

Could not load file or assembly 'DropDownCheckBoxes' or one of its dependencies. The system cannot find the file specified

We have added third party (DropdownCheckBoxes) dll reference in our SharePoint web part application.
On the user control, registered this assembly as
<%# Register Assembly="DropDownCheckBoxes" Namespace="Saplin.Controls" TagPrefix="asp" %>
When we run it on browser, it giving us error as --
Could not load file or assembly 'DropDownCheckBoxes' or one of its dependencies. The system cannot find the file specified.
Can you please guide what needs to be done for this?
Thank You!

In ASP.NET where and all we can refer the assembly reference?

In ASP.NET where and all we can refer the assembly reference in Project? for ex: generally we can refer the file in web.config file as like below
<%# Register assembly="System.Web" namespace="System.JavaScript.Web" tagprefix="ex" %>
Except this what are the other pages in which we can refer assembly as like above.
secondly you can refer the assembly in project. Right click on references and select the required assembly, and click add. This will add assembly reference to your project.
Some assemblies like ajaxtoolkit.dll or if you are using some partial views (ascx) pages, then you can use the reference which you have mentioned.

Ajax Control Toolkit fails to load

I am having trouble getting my AJAX control tool kit working in asp.net. The website runs fine when I run it using the localhost/website.aspx address however when I attempt to access the website via the net I get the error below. Any Suggestions?
Parser Error Message: Could not load file or assembly
'AjaxControlToolkit' or one of its dependencies. The system cannot
find the file specified.
Line 1: <%# Page Language="VB" AutoEventWireup="false"
CodeFile="Submit_Employee_Info.aspx.vb" Inherits="_Default"
MaintainScrollPositionOnPostback="true" %>
Line 3: <%# Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Source File: /RequestForm/Submit_Employee_Info.aspx Line: 3
Sorry not much reputations so posting as answer instead of comments. Do you have ajax toolkit dll referenced in your project. To confirm, check your bin/debug director.
In your local solution, expand the references folder in the web application, and find the AjaxControlToolkit.dll.
Right click, Properties, and check the path to where the DLL is referenced
If it's referenced to a folder outside of your project, you will need to include this in the project.
You have a couple of choices...
Copy DLL into a 3rdPartyLibs folder in the solution, and change the reference to point here
Use Nuget to download the file into the solution, the only issue here is that the version may be incorrect, so option 1 here might be best in your scenario.

Deploying SharePoint layout ASP .NET assembly into GAC

I'm currently rewriting a legacy SharePoint application and I need to figure out how to deploy it.
The application itself is SharePoint solution with several features, including webparts and simple web pages with some code.
There is a webpage that is designed to be deployed in layouts subfolder.
In production environment, there is no codebehind in layouts subdirectory, just the .aspx file.
I understand that corresponding codebehind assembly is loaded from GAC. Indeed, it is there.
However the page code doesn't contain <%# Assembly %> directive that would ask it look in GAC, nor does it specify fully-qualified name:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BadWolf._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- -->
</html>
So how does this page locate its code assembly in the production environment? I need to deploy the same code to a different server but if I don't specify <%# Assembly %> SharePoint gives me Unknown Error, which is represented in logs as follows:
Exception Type: System.Web.HttpException
Exception Message: Could not load type 'BadWolf._Default'.
What did I miss? Is there any special config, any special setting, whatever?
You need to use Inherits= with the fully qualified assembly name...
Inherits="MyAssembly.MyNamespace.MyClass, MyAssembly, version=1.0.0.0, culture=neutral, publickeytoken=123456789"
Turned out the assembly was in SharePoint bin folder, that's why it was loaded without specifying the fully qualified name. However removing it from GAC yielded another issue:
Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed
This is funny because removing the assembly from either GAC or bin folder makes it unusable (or else requiring additional configuration which I seek not), and I'm not sure which one is actually being loaded.
I think I'll stick with keeping assembly in GAC (to have full trust) and specifying fully qualified name.

LoadControl on control with assembly reference

I'm trying to use System.Web.UI.TemplateControl.LoadControl to build a templated web part for a SharePoint application, and I'm having trouble with a control that references an external assembly.
I have a user control with the first few lines like this:
<%# Control Language="C#" ClassName="MyControl" %>
<%# Assembly Name="AjaxControlToolkit" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
The web part derives from a base webpart that implements the templating and some other utilities which is in an assembly called "MyWebParts" (for example), while the derived web part class is in "MyProject". MyProject has a reference to "MyWebParts" (obviously), and to "AjaxControlToolkit", but "MyWebParts" does not have a reference to "AjaxControlToolkit". At runtime, when the templated web part tries to load the user control (a .ascx file in the "controltemplates" SharePoint root folder), it calls the base methods it inherited across assemblies, and it throws an HttpParseException, indicating that it couldn't load a required assembly. The EventViewer confirms that the assembly in question is AjaxControlToolkit.
I tried adding the AjaxControlToolkit assembly to the web.config for sharepoint, and it's sitting in the GAC, but to no avail.
Anyone know how I can do this without having a reference to every assembly in existence in my "MyWebParts" assembly?
Add a reference to your assembly in the web.config assemblies section, this will force sharepoint to load that assembly into memory, like so:
<assemblies>
<add assembly="AjaxControlToolkit, Version=1.0.10920.16768, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
</assemblies>
P.S. this is for ajax 1.0, correct the assembly version if you are using the AJAX 3.5 version.

Resources