How to add a reference to System.Data.DataSetExtensions to a Web Site ascx.cs file?
Short Answer
The problem was our using
statement. So, there were two requirements.
- Reference
System.Data.DataSetExtensions
in the web.config file. (See below for finding the full assembly name.) - Add a
using
statement forSystem.Data
in the C# file.
The problem was that our using statement was for System.Data.DataSetExtensions
.
Explanation
Rick Strahl explains that by default ASP.NET includes:
- all assemblies in the
bin
path - any GAC-based assembly references in the web.config
<compilation>
section
Further, we were able to query to GAC from a Visual Studio Command Prompt as follows:
> gacutil /l System.Data.DataSetExtensions
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.17929
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
Number of items = 2
This confirmed that the assembly we wanted was in the GAC. It also listed the full name of the assembly that we needed to reference in the web.config file.
Shaun Luttin
My professional work focuses on designing, testing, implementing/securing, and deploying distributed services. I kind be "that guy" too. Ship it!
Updated on July 14, 2022Comments
-
Shaun Luttin almost 2 years
We're working with a Web Site project and trying to reference
System.Data.DataSetExtensions
. (Using a Web Application would be better; the technical lead, though, has her reasons.)Here is what we have tried:
- Find the assembly path.
- Open a Visual Studio Command Prompt and run
sn.exe -T "full\path.dll"
- Add the following to the web.config based on the Public key token.
web.config > system.web >
<compilation debug="true" targetFramework="4.0"> <assemblies> <!-- Other assemblied omitted --> <add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /> </assemblies> </compilation>
The full path is
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll
Despite this, msbuild still complains when we add
using System.Data.DataSetExtensions
to a code behind file. What gives? How do we solve this? -
xanatos about 9 yearsWe needed to copy the assembly to the bin not to reference it in the web.config. This seems the wrong solution.
-
Shaun Luttin about 9 years@xanatos Why does this seem the wrong solution? What is the alternative? I lack experience with web site projects.
-
xanatos about 9 yearsThere must be some problem in the configuration file... But I do know that copying Microsoft assemblies in the bin folder isn't a right solution.
-
Shaun Luttin about 9 years@xanatos Thank you for your feedback. It turned out that the problem wasn't with the web.config file but in the way that we were doing the
using
statement.