Posts Tagged ‘linq’
Linq Exception(NullReferenceException): Object reference not set to an instance of an object
Posted by: admin in Linq, Linq Exceptions, Linq To Object on September 24th, 2010
With NullReferenceException:
-
Dim obj As DemographicProperties = Me
-
-
Dim m As IEnumerable(Of DemographicProperty) = From c In obj _
-
Where (c.MapClass.MapClassID = MapClassID) _
-
Order By c.Name Ascending _
-
Select c
If you are getting NullReferenceException, it means the MapClassID is null(nothing in vb.net)
Solve:
-
Dim obj As DemographicProperties = Me
-
-
Dim m As IEnumerable(Of DemographicProperty) = From c In obj _
-
Where ((Not c.MapClass Is Nothing) AndAlso (c.MapClass.MapClassID = MapClassID)) _
-
Order By c.Name Ascending _
-
Select c
Namespace or type specified in the project-level Imports ‘System.Xml.Linq’ doesn’t contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn’t use any aliases
There are 2 ways to remove this warning
First, you may need to convert the current .Net Framework used by the application to higher version, let’s say from .net framework 2 to 3.5
- Goto Property Pages of the web site project
- View Menu->Property Pages or press shift+F4
- Click the Build option from the left side
- Make sure the Target Framework is .Net Framework 3.5
Second, remove the namespace that shown in the warning in this case the “System.Xml.Linq” from the web.config
