ASP.NET "Reference required to assembly" error - asp.net

I have an ASP.NET page A that uses a data layer assembly DAL. I reference the DAL assembly with a
<%# Assembly Name="NGC.DAL" %> tag since there is no project to add the reference to. The assembly itself I copied to the pages' bin folder.
The assembly DAL is a project that references System and System.Data.
Now when A calls a method in DAL, the compiler gives the error
BC30652: Reference required to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes' containing the type 'System.Data.IDbConnection'. Add one to your project.
I tried referencing the assembly System.Data with a <%#Import Namespace="System.Data" %> tag and I tried copying it to the bin folder and referencing it with a
<%# Assembly Name="System.Data" %> tag, both in A directly. Nothing worked.
Why would a project A that uses project B which uses project C require a reference to B and C rather than just B and why does the way above not work?
This MSDN thread covers the problem but shows no solution that works.
EDIT: As Robert Wagner suggested I added the reference to the web.config.
Now I get another error message. BC30560: 'CommandBehavior' is ambiguous in the namespace 'System.Data'. which is odd because the one in the web.config is the only one I reference inside the page.
Maybe it's worth mentioning that the System.Data referenced and used in the DAL assembly is from the compact framework. But since it's the only one I use, where does the ambiguity come from?

Most likely you have inherited from a System.Data class in your DAL dll and are using that class in your website. It requires a reference to be able to resolve the references those classes otherwise the compiler would not know what the class contract is.
You should not need to copy in System.Data as it is in the GAC.
A better way would be to add the reference in your web.config file:
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
</system.web>
When you say "there is no project to add references to" are you using Visual Studio? If so, why not use the Web Application or Web Site projects?

Related

Error while implementing MembershipProvider

Today i got an error while trying to implement MembershipProvider.
Error 1 The type 'System.Configuration.Provider.ProviderBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The thing that i have done is i added a reference of system.web because i had to implement membershipProvider which is under System.Web.Security. and now i get this error. thanks in advance !
When implementing a custom MembershipProvider, you must also put a reference to System.Configuration (as indicated by the exception), because the MembershipProvider gets configured via settings in web.config.

Add Assembly (in Web.Config) required for assembly in GAC

Please see the code below (Image Hander):
<%# WebHandler Language="VB" Class="com.Genie.PresentationLayer.Web.ImageHandler1" %>
Imports com.Genie.BusinessLogicLayer
Namespace com.Genie.PresentationLayer.Web
Public Class ImageHandler1
Inherits ImageHandler
Private p1 as Person
Public Sub New()
End Sub
end class
end namespace
com.Genie.BusinessLogicLayer was added to the GAC today. The application produces a runtime error when it gets to the Image Handler: 'Type Person is not defined'. Adding an assembly to the web.config as follows resolves the problem:
<assemblies>
<add assembly="BusinessLogicLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken="669e0ddf0bb1aa2a"/>
</assemblies>
Why do I have to amend the web.config? I thought 'Add Assembly' was for website projects that do not use MSBuild (and therefore do not have 'References'). This is a web application project.
The references you add to a project are used when the project is compiled, but an ASPX page or ASHX handler is compiled when it is first requested. At this time the references are lost, so you'll need to provide them yourself.
The alternative would be precompiling your ASPX pages, causing the error to be caught at compiletime as opposed to runtime, or moving the code to codebehind so your project's references will be used.

Problem using Ajax with Visual Studio 2010

I am hoping someone can help me. I am trying to add Ajax controls to my VS 2010 project for the first time. I have previously gotten it to work when I used VS2008. I keep getting this exception:
Error 56 The type 'System.Web.UI.ExtenderControl' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Here’s what I did. I downloaded the ajax 4 toolkit and added a reference to the project. I also added a reference to system.web extension to my project. When I do this these lines get added to my web.config
<assemblies>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies></compilation>
I added these lines to my aspx file.
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
And
<cc1:CalendarExtender runat="server" Id="txtDateOfBirth_CalendarExtender" TargetControlID="txtDateOfBirth"></cc1:CalendarExtender>
Etc.
I also backed off and tried ajax 3.5, this didn’t help. I did notice that the ajax dll is 4.1 while the 'System.Web.Extensions is 4.0. I don’t know if this matters but I cannot find ajax 4.0 or 'System.Web.Extensions 4.1.
Thank once again in advance.
This is not a solution but a recommendation: stay away from the Ajax toolkit or you are asking for trouble; use jquery instead (seriously, I have been down this road).

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.

ASP.NET Website's BIN directory and references

Imagine the following solution:
Website ABC.com (not Web Application)
BLL (business logic layer in a seperate assembly)
DTO (dto objects in their own assembly)
DAL (data access layer in it's own assembly as well).
The BLL has a reference to the DAL.
The BLL has a reference to the DTO layer.
The Website project references the BLL.
When one compiles the website project, the following DLLs will appear in the BIN directory:
BLL.dll
DTO.dll
DAL.dll
When one goes to preview the site, an error occurs about not having the necessary assembly references... Now if one right clicks on the website project, Add Reference, and explicitly add the reference to the missing assemblies, it will work fine.
It seems to me like ASP.NET pulls the referenced assemblies of the referenced assembly being added/referenced in the website.
Why does one need to add explicit references to the references of the references... ? Sorry if I'm not wording this correctly or if it confusing.
I think the problem may have to do with using a web site project, as oppossed to a Web Application. I can't remember off the top of my head, but there's something funky about the way web site projects are compiled, as oppossed to web application projects.
Here is a good article on your question Compilation and Deployment.
It has something to do with "WebSites" being compile at runtime. Hopefully the above article will answer your question.
Just tested this scenario today for the project I'm on. You should be just fine just adding your assembly in Web.config as:
<compilation debug="true">
<assemblies>
<clear/>
<add assembly="mscorlib"/>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<add assembly="YourBLLLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</assemblies>
</compilation>
Also your assemblies should stay in the famous ./bin folder of your web site's root.
GL!

Resources