4

I would use the System.Linq.Dynamic.

I added the specified Dynamic.vb file, that starts like this :

Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports System.Text
Imports System.Linq
Imports System.Linq.Expressions
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Threading
Imports System.Runtime.CompilerServices

Namespace System.Linq.Dynamic
  Public Module DynamicQueryable

to my (VB.NET)solution.

Now Visual Studio does not recognize anymore in the project files the System.XXX references, proposing me to change them to Global.System.XXX enter image description here

Was is Das, and how to manage it?

Ahmad Mageed
  • 94,561
  • 19
  • 163
  • 174
serhio
  • 28,010
  • 62
  • 221
  • 374

1 Answers1

2

It looks as though some namespace hiding is taking place. In VB.NET projects a root namespace exists that is set to your project's name by default. You can check this from Project -> Properties -> Application -> Root namespace.

When a class explicitly specifies a namespace, the root namespace is prefixed to it. For example, let's say your root namespace is RootNs. Since the DynamicLinq.vb file specifies a namespace of System.Linq.Dynamic this is really RootNs.System.Linq.Dynamic. This hides the regular .NET System namespace, which is why Visual Studio prompts you to prefix all your namespaces with Global.

It's worth noting that in C# this concept is different, so I wouldn't expect this issue to come up when someone uses the C# version of DynamicLinq.

To fix this you have a few options (pick one):

  1. Remove the namespace declaration from DynamicLinq.vb and remove any full qualifications from objects within that file that use System.Linq.Dynamic. In other words, System.Linq.Dynamic.Signature becomes Signature. To use it elsewhere, add Imports System.Linq.Dynamic.

  2. Remove the root namespace from Project/Properties/Application by making it blank. By doing so your project will be more like C# and you ought to explicitly specify namespaces in all your classes. To use it elsewhere, add Imports System.Linq.Dynamic.

  3. Keep the root namespace and just change the namespace of DynamicLinq.vb. For example, change it to NewNs.Linq.Dynamic and remove full qualifications from Signature as before. To use it elsewhere, add Imports RootNs.NewNs.Linq.Dynamic (notice the RootNs prefix).

Ahmad Mageed
  • 94,561
  • 19
  • 163
  • 174