Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relocate ToDataTable #168

Closed
JamesFaix opened this issue Apr 25, 2016 · 3 comments
Closed

Relocate ToDataTable #168

JamesFaix opened this issue Apr 25, 2016 · 3 comments
Labels

Comments

@JamesFaix
Copy link

I propose that the ToDataTable method group be moved to a different assembly. Currently this is the only method group in MoreLINQ that has a dependency on System.Data or System.Xml. That's 2/3 the dependencies for 1/50 of the features, roughly.

Code that has nothing to do with relational data, using MoreLINQ extension methods that have nothing to do with relational data, without referencing System.Data will yield the compiler error "The type 'System.Data.DataTable' is defined in an assembly that is not referenced..." A similar message occurs for System.Xml

@atifaziz
Copy link
Member

If you never use ToDataTable in code then you should not run into a CS0012 error. How are you seeing this happening? Alternatively, you can use MoreLINQ PCL that doesn't include ToDataTable.

Also, DataTable is not relational on its own but a DataSet is. On its own, DataTable is a very useful container data structure with lots of applications and part of .NET Framework.

I'm closing this as wont-fix because:

  • CS0012 error does not occur
  • the PCL version is a reasonable workaround for those just annoyed by presence of ToDataTable
  • the dependencies, even if there, are not incurred at runtime or during deployment if unused

@JamesFaix
Copy link
Author

I understand not agreeing that it's a necessary change, but I do get the error.

I've even tried with a very simplified environment. I created a new C# console app project in a new solution, deleted all standard references except System, added MoreLinq, and added this code to Program:

using MoreLinq;

class Program {
    static void Main() {
        var x = new[] { 1, 2 }.Concat(3);
    }
}

I get a CS0012 when I try to compile.

(using VS2013)

@atifaziz
Copy link
Member

atifaziz commented Apr 30, 2016

I've even tried with a very simplified environment.

@JamesFaix I tried the same but I guess the difference is coming from the compiler version in 2013 and 2015.

Here's what I did. I created a simple Program.cs in a folder (no VS):

using System;
using System.Linq;
using MoreLinq;

static class Program {
    static void Main() {
        Console.WriteLine(Enumerable.Range(1, 10).ToDelimitedString());
    }
}

Then I created a batch in the same folder with following the content and named it makenrun.cmd:

@echo off
setlocal
set NETFX=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319
set CSC_PATH=%ProgramFiles%
if defined ProgramFiles(x86) set CSC_PATH=%ProgramFiles(x86)%

rem set CSC_PATH=%CSC_PATH%\MSBuild\12.0\bin
set CSC_PATH=%CSC_PATH%\MSBuild\14.0\bin

nuget install morelinq -version 1.4.0 ^
  && copy /y morelinq.1.4.0\lib\net35\MoreLinq.dll ^
  && "%CSC_PATH%\csc.exe" /noconfig /nostdlib "/r:%NETFX%\mscorlib.dll" "/r:%NETFX%\System.Core.dll" /r:MoreLinq.dll Program.cs ^
  && Program

You'll notice that to be very strict on references, I disabled the default response file (/noconfig) and even referenced mscorlib manually (i.e. /nostdlib).

Depending on which C# compiler version you want to invoke, you can uncomment the corresponding set CSC_PATH=... statement and comment out the other. I tested against the following two C# compiler versions:

  1. C# 5 compiler shipping with MS Build Tools 2013
  2. C# 6 (Roslyn) compiler shipping with MS Build Tools 2015

The first one reports CS0012 but second one doesn't.

Output from running the batch in case (1):

Feeds used:
  https://api.nuget.org/v3/index.json

Attempting to gather dependencies information for package 'morelinq.1.4.0' with respect to project 'A:\', targeting 'Any,Version=v0.0'
Attempting to resolve dependencies for package 'morelinq.1.4.0' with DependencyBehavior 'Lowest'
Resolving actions to install package 'morelinq.1.4.0'
Resolved actions to install package 'morelinq.1.4.0'
Adding package 'morelinq.1.4.0' to folder 'A:\'
Added package 'morelinq.1.4.0' to folder 'A:\'
Successfully installed 'morelinq 1.4.0' to A:\
        1 file(s) copied.
Microsoft (R) Visual C# Compiler version 12.0.40629.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(7,9): error CS0012: The type 'System.Data.DataTable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
MoreLinq.dll: (Location of symbol related to previous error)

Output from running the batch in case (2):

Feeds used:
  https://api.nuget.org/v3/index.json

Attempting to gather dependencies information for package 'morelinq.1.4.0' with respect to project 'A:\', targeting 'Any,Version=v0.0'
Attempting to resolve dependencies for package 'morelinq.1.4.0' with DependencyBehavior 'Lowest'
Resolving actions to install package 'morelinq.1.4.0'
Resolved actions to install package 'morelinq.1.4.0'
Adding package 'morelinq.1.4.0' to folder 'A:\'
Added package 'morelinq.1.4.0' to folder 'A:\'
Successfully installed 'morelinq 1.4.0' to A:\
        1 file(s) copied.
Microsoft (R) Visual C# Compiler version 1.1.0.51109
Copyright (C) Microsoft Corporation. All rights reserved.

1,2,3,4,5,6,7,8,9,10

So while you're right that CS0012 is being emitted, I'm not sure if going forward it is an improvement (I hope) or a regression with the C# 6 compiler (I see 4 mentions of CS0012 in dotnet/roslyn#7278 at the time of this writing). In any event, I'm still not inclined to spend time and energy on moving out ToDataTable as I think the issue is somewhat superficial and can be sidelined today by using PCL package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants