Ack! Help! Linq Error on Non-Dev System...

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Well,

I'll try to give enough information here, because well, I really don't know what the cause could be. The error is definitely involving the System.Linq.Enumerable Extensions, but how or why I don't think i'll be able to figure out.

Basically, i have .Net 3.5 on both systems installed, as it is a .Net 3.5 application, and I often use some frequent "casts" as part of the System.Linq.Enumerable Cast(Of T) extension.

here is the offending line (the line separators have been added for formatting benefit and readability on this forum it is all on one line in the source):
VB.NET:
Dim dr() As RexamTables.XLColumnsRow = _ 
          DirectCast( _
              XCols.Select( _
                  DBCOL.FmtStr(itm.Text.SingleQuote) & _ 
                  " AND SheetID in (" & _ 
                  [U][B]_sheets.Cast(Of String).ToArray.Join(",") [/B][/U]& ")"), _ 
              RexamTables.XLColumnsRow())

Join() is a Wrapper extension of my own defined as:
VB.NET:
 function Join(of T)(items() as T, Sep as String) as String
and uses the Array.Join() method, and in this situation _sheets is defined

VB.NET:
private _sheets() as Integer = {}

Later I redefine _sheets() with the index of each Sheet() in an Excel file to correlate to a DataSet map of Excel Column Headers per Worksheet in a Workbook. As the user selects a worksheet in my interface, it knows which ChildTables to refer to for the column headers in the dataset.

On my system, the Development System, it works fine, without any issues, but after transferring the application to another system, it has decided to come up with an exception specifically oriented on that line, which is telling me that the Cast(Of String) from an integer Array is not working on a system other than mine. I currently don't know enough about the Linq or 3.5 environment to discern what could cause this to work in one place and not in another, but I assure you that 2.0/3.5 are installed on both systems. (I will admit, that there is a possiblity that my system is 3.5 and the other system is 3.5 SP1 but that should be backwards compatible.)
Here is the Exception for clarification.

Source: System.Core
Message: Unable to cast object of type 'System.Int32' to type 'System.String'.
Stack: at System.Linq.Enumerable.<CastIterator>d__aa`1.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at RexamClean.ImportForm.OpenXL_Click(Object sender, EventArgs e) in C:\Source\Visual Studio 2008\Projects\RexamClean\RexamClean\ImportForm.vb:line 358
at RexamClean.ImportForm.ImportForm_Shown(Object sender, EventArgs e) in C:\Source\Visual Studio 2008\Projects\RexamClean\RexamClean\ImportForm.vb:line 318
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

Thanks so much, i really need help on this one.
 
Well,
The nature of my question has altered to some degree, as I have found through some whitepaper research, that the 3.5 SP1 update altered the behavior of the Cast(Of T) extension, where in previous versions, the backend would attempt a conversion of the base type to the new type, where in 3.51 the backend performs a Cast, similar to the TryCast() function, which as anyone knows will raise an exception when one type cannot be implicitly cast into another. This is most disparaging, but we deal as we must.

I'm open to suggestions on how I might write my own "Cast" algorithm that is similar to the old "Cast" extension, because manually converting an array of integers into an array of strings is rather painstaking. (not to mention my other collections of object that would inherently execute the Object.ToString in the previous Cast methodology but now may rightly fail because the Objects are Integral in nature.)

Thanks
 
Back
Top