Use System.Linq Extension Method In Project With Option Strict ON?
Feb 2, 2011
I'm using .NET 3.5 In my DataLayer class I have references of System.Core,System.Data.Linq, System.Data.DataSetExtensions. But I cantnot use this feature in Linq query if I have Option Strict ON:
I really like the coding speed that vb.net provides, but I don't like the possibility to forget to declare variable types, return types of functions, etc. and that is why in each class I use[code]..
Is there a way to define those two options on the project/solution level?
I'm facing a trick issue with LINQ. I generate the above code:[code..]
Everything is running well if I turn off Option Explicit. When I turn it on, compiler is showing me a meessage: Expression is of type 'Object', which is not a collection type. Referencing to lResult variable.
i'm encountering the following problem. I recently activated 'Option Strict On' and now I get an error in my LINQ query. From e As TEnum returns the following error: Option Strict On disallows implicit conversions from 'Object' to 'TEnum'. [code]
http://127.0.0.1:47873/help/1-6644/ms.help?method=page&id=C318B79A-FA4D-4DE3-B62D-C1162BEB267E&product=VS&productVersion=100&topicVersion=100&locale=EN-US&topicLocale=EN-US and i get the following error
I am in the process of fixing my code to be in line with Option Strict On, but the code below is still throwing an error and I don't know why. What do you think?
I've got the below, where I'm grouping a collection by a propery, then wanting to access the properties of my group. Problem I have is with the anonymous typing. Because of option strict I have to give an explicit type but I can't work out what the type should be. The below doesn't compile because t.HeadAccountKey isn't a value (as t has a type of object). So either I need do some casting or my linq selector is wrong,
I have to take over a project written in vb.net, which contains more than 400k lines of code written in option strict off mode. I want to build it under option strict on first before I do anything else -- which maybe converting it into C#. I found there's thousands of lines of code raises compilation error, mostly are about implicit type casts. Is there any tool would help to make it compile under option strict on mode if I don't want to correct every single line manually? Because it's really painful to add CStr/CInt invocation into every line of Code myself.
The datagridview has columns for all 4 values as well as a 5th (a checkbox column called "colIsSelected"). There is no problem binding the list to the grid and displaying the items. The problem is that the query that gets the selected items in the grid is giving me an implicit cast error when option strict is enabled.
This is the query...
Dim _changes As List(Of BaseChange) _changes = (From _row As DataGridViewRow In dgvChanges.Rows() _ Where Convert.ToBoolean(_row.Cells(NAME_COLUMN_IS_SELECTED).Value) = True _ Select DirectCast(_row.DataBoundItem, BaseChange)).ToList()
...and it produces the correct results with option strict off. The implicit cast squiggle is on the "row As DataGridViewRow" code, and the full message is "Implicit conversion from 'Object' to 'System.Windows.Forms.DataGridViewRow'*".
If I exclude the "As DataGridViewRow" from the query, I get a late binding error on the _row.Cells and _row.DataBoundItem and this also fails option strict.I need this to work with Option Strict enabled, and in VB.
I have had several occasions recently to access a specific class several times over a relatively small time frame.So I've been storing the value of the class in Session and trying to access it on page load, if it's not available creating a new instance and storing that in session.
So instead of constantly replicating the same code for different classes on different pages I'm trying to create an extension method to do this for me.
[Code]...
I'm stuck on what to do when I make my new instance of my class (it would have to have a New() sub)
I'm not sure where to go from here... or even if this is the best way to do it.
I have inherited a VB.NET application that I need to compile so I can run dorkumentation on it. I first received "Option Strict On disallows implicit conversion from x to y" errors, so I turned off the Option Strict option in the Project file.
So why do I still fail with the same error message?
The following LINQ query resp. call of the extension method Select in Visual Basic 2010 is working fine:
Dim qAvSalary = qJobData.Select(Function(e) e.AvSalary) But doing so I am not able to specify the name of property I want the query (e.g. AvSalary) using a string variable. This should be possible if I use a LINQ expression tree. Searching and trying a long time on how to translate the query to a corresponding expression tree was not successful. My final approach is:
Can I make an Extension method for all the subclasses of System.Object (everything)?
Example: <Extension> Public Function MyExtension(value As Object) As Object Return value End Function
The above functions won't work for object instance:UPDATE The problem seems to occur only in VB, where members of object are looked-up by reflection (late-bound).UPDATE AFTER ANSWERED.FYI, as vb has an advantage that C# lacks that is, members of imported Modules are imported to the global scope so you can still use this functions without their wrapper:Dim myObj2 = MyExtension(myObj1)
When I have Option Strict ON in my project, the IDE tells me that "Option Strict On disallows implicit conversions from 'System.Data.ParameterDirection' to 'String'." How can this be, since I'm using their built-in enumeration for the SqlParameter direction.
I'm working on a larger VB application (framework v3.5) where the compile time continues to get slower and slower the larger it grows. It currently takes about 7 minutes to compile just the extensions project. We have other similar projects in C# that don't experience the slow compile time.
what does these two code means in vb.net: Option Explicit on Option strict on i think option explicit means the compiler is not going to do any kind of conversion and i need to do all of them by the code;also it becomes case sensitive i.e;
I would use the System.Linq.Dynamic. I added the specified Dynamic.vb file, that starts like this:
[Code]...
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
1. I have read that keeping Option strict on and Option infer off is good practice and will insure your code is tight and properly written. I would like input regarding this, pro's and con's from those who are in the know.
2. Having said that, I have set Option strict on and Option infer off in an existing program I wrote (that was working perfectly mind you) with them off and on respectively. I went through and cleaned up all the errors on the 'need AS' and casting of variables, but one is leaving me a bit put out.[code]
I have also read where using My.Computer.System.Directory.GetFiles() instead of System.IO.Directory.GetFiles() is probably not a good thing, but when I change to this I get no error, but also no dataI am thinking I should stay with the strict on and infer off but am really slogging through getting this code correct.Running Win7 on Dual Quad Core XEON Intel Extreme with 8Gb RAM.
I am getting following error whenever I want to use IIf function inside entity framework query.
LINQ to Entities does not recognize the method 'System.Object IIf(Boolean, System.Object, System.Object)' method, and this method cannot be translated into a store expression.
I have the following extension method that I've built and have working for one MVC3 project, but when trying to use it in another, the compiler (not the view) gives me the error;Error 1 'TextBoxFor' is not a member of 'System.Web.Mvc.HtmlHelper(Of TModel)'...Intellisense shows none of these html element shorcut methods.I'm sure it's just because I'm missing a reference or something, but beats me what it is.
FImports System.Runtime.CompilerServices Public Module HtmlHelperExtension <Extension()> _
I had a code segment on an asp.net page in the code-behind file. I decided to move it into a public subroutine in a module (general_functions.vb). Once I did this, however, the code no longer works - it throws an error. On the original code-behind I replaced the original code with a call like so:
what do you thinkg about comment below? original article url is also suggested to read.I didnt get why my code will be faster if i use it on. anyone has good knowledge about it?
Although Visual Basic .NET allows you to perform implicit type conversions and late binding, you should avoid these practices. Implicit type conversions and late binding may lead to severe performance problems, runtime errors, code that is difficult to read and maintain,and sub-standard programming practices.Many VB.NET professional programmers believe that leaving OPTION STRICT OFF by default was perhaps Microsoft's worst decision in the VB.NET implementation. Use OPTION STRICT ON.