3

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:

  1. Find the assembly path.
  2. Open a Visual Studio Command Prompt and run sn.exe -T "full\path.dll"
  3. 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?

Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467

1 Answers1

4

Short Answer

The problem was our using statement. So, there were two requirements.

  1. Reference System.Data.DataSetExtensions in the web.config file. (See below for finding the full assembly name.)
  2. Add a using statement for System.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
  • 133,272
  • 81
  • 405
  • 467
  • *We needed to copy the assembly to the bin not to reference it in the web.config.* This seems the wrong solution. – xanatos May 02 '15 at 20:20
  • @xanatos Why does this seem the wrong solution? What is the alternative? I lack experience with web site projects. – Shaun Luttin May 02 '15 at 20:21
  • There 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. – xanatos May 02 '15 at 20:22
  • @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. – Shaun Luttin May 02 '15 at 20:46