'Having problem with specifying a valid predicate in vb.net program

I'm currently supporting an old vb.net app that I'm trying to migrate to another domain. When running on an old domain, it works perfectly but when running the .exe in a new domain this error pops up:

System.ArgumentException: You must specify a valid predicate for filtering the results. Parameter name: predicate at System.Data.Objects.ObjectQuery`1.Where(String predicate, ObjectParameter[] parameters) at COOP_Incentive.frmEmployeeMaster.LoadDefaultData() in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 78
at COOP_Incentive.frmEmployeeMaster.frmEmployeeMaster_Load(Object sender, EventArgs e) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 329 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.SetVisibleCore(Boolean value) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at WeifenLuo.WinFormsUI.Docking.DockContentHandler.SetVisible() at WeifenLuo.WinFormsUI.Docking.DockPane.set_ActiveContent(IDockContent value) at WeifenLuo.WinFormsUI.Docking.DockContentHandler.Activate() at WeifenLuo.WinFormsUI.Docking.DockContentHandler.Show(DockPanel dockPanel, DockState dockState) at COOP_Incentive.frmEmployeeMaster.Show(DockPanel dockpanel) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\Setup - Employee Master\frmEmployeeMaster.vb:line 356 at COOP_Incentive.frmMenu.cmdEmployeeMaster_Click(Object sender, EventArgs e) in C:\Users\username\Desktop\CBVS For new_domain\COOP Incentive\Forms\MainForms\frmMenu.vb:line 26 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Based on the error message this is the code it is referring to:

cboBusinessUnit.DataSource = (From r In DefaultBusinessUnitSet.Where(filter).Execute(MergeOption.PreserveChanges) _
                           Order By r.BussinessCode _
                           Select New With {.id = r.BussinessCode, .text = r.BussinessName}).ToList()

This is the filter variable that is in the "Where" part:

Dim filter As String = String.Join(" or ", (From result In SessionUtil.AllowedEmployerCodes _
                                               Let c = " it.BussinessCode='" + result + "' " _
                                               Select c).ToArray())

I am not familiar with this kind of error and how do I work around this?



Solution 1:[1]

It is likely that the filter string is landing up with some things that are making it invalid. I would suggest displaying the filter value when the error you having is thrown. It could be that one of your employercodes has an apostrophe in it as an example. In that case, you would need to wrap the result with a replace e.g. replace(result,"'","''").

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TCBW