Value cant be null system.text.regularexpressions

Hello All
Im using regex but i always get this null error
i imported the namespace system.text.regularexpressions

image

I dont get the error if i run from the main page but when i open the flow i get this


Value cannot be null.

Error: System.Exception: Value cannot be null.
   at System.Xml.Linq.XAttribute..ctor(XName name, Object value)
   at System.Activities.Presentation.View.NamespaceDisplayAutomationPeer.GetItemStatusCore()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
   at System.Windows.ContextLayoutManager.fireAutomationEvents()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.Controls.ItemsControl.OnBringItemIntoView(ItemInfo info)
   at System.Windows.Controls.DataGrid.ScrollIntoView(ItemInfo info)
   at System.Windows.Controls.DataGrid.ScrollIntoView(Object item)
   at System.Activities.Presentation.View.ImportDesigner.CommitImportNamespace(String addedNamespace)
   at System.Activities.Presentation.View.ImportDesigner.OnPreviewKeyUp(Object sender, KeyEventArgs args)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler), HResult -2147467261

type or paste code here

any idea why this happens?

Hazem

@Hazem_Saleh

can you share the expression at which you have used regex expression

cheers

Hope the input field in the property panel of that activity is set with some value or variable holding value
@Hazem_Saleh

Hi sure

extractedData = new DataTable();
extractedData.Columns.Add(“ORIGINAL_REF”);
extractedData.Columns.Add(“MT910_REF”);
extractedData.Columns.Add(“MT910_CCY”);
extractedData.Columns.Add(“MT910_AMOUNT”);
extractedData.Columns.Add(“MT910_VALUE_DATE”);
extractedData.Columns.Add(“FIELD72_Re”);
extractedData.Columns.Add(“FIELD72_Na”);

        foreach (DataRow row in dataTable.Rows)
        {
            string originalRefNo = row["ORIGINAL_REF_NO"].ToString();
            if (originalRefNo.StartsWith("010F") && originalRefNo.Length == 16)
            {
                string mt910Ref = row["MT910_REF"].ToString();
                if (mt910Ref.StartsWith("33") && mt910Ref.Length == 10)
                {
                    string mt910Currency = row["MT910_CCY"].ToString();
                    string mt910Amount = row["MT910_AMOUNT"].ToString();
                    if (double.TryParse(mt910Amount, out double amount))
                    {
                        mt910Amount = amount.ToString("0.##");
                    }

                    DateTime mt910ValueDate;
                    if (DateTime.TryParse(row["MT910_VALUE_DATE"].ToString(), out mt910ValueDate))
                    {
                        string field72 = row["FIELD72"].ToString();

                        // Extract FIELD72_Re using regular expression
                        Match match = Regex.Match(field72, @"/RETN/(?:59|57)/([A-Z]{2})/");
                        string rejectionReason = match.Success ? match.Groups[1].Value : "MS01";

                        // Extract FIELD72_Na using regular expression
                        string narrative = Regex.Match(field72, @"/TEXT/(.*?)(?:$|/)").Groups[1].Value;

                        // Extract date components
                        int day = mt910ValueDate.Day;
                        int month = mt910ValueDate.Month;
                        int year = mt910ValueDate.Year % 100;

                        string mt910_date_D = day.ToString("D2");
                        string mt910_date_M = month.ToString("D2");
                        string mt910_date_Y = year.ToString("D2");

                        // Reformat MT910_VALUE_DATE
                        string mt910ValueDateFormatted = $"{mt910_date_Y}{mt910_date_M}{mt910_date_D}";

                        extractedData.Rows.Add(
                            originalRefNo,
                            mt910Ref,
                            mt910Currency,
                            mt910Amount,
                            mt910ValueDateFormatted,
                            rejectionReason,
                            narrative
                        );
                    }
                }
				 }
            }

i generate, dt from a query
should i set it to default value .

Regards

@Hazem_Saleh

is there are any arguments in the regularexpression for which values are coming from other

xamls,if so then you need to run from the main

or if you want to test the specific workflow replace the arguments with default string text

yeah make sure it is set with some value or as nothing
@Hazem_Saleh

hi,
how i can do this just assign to null?

while defining that variable itself, keep it with null @Hazem_Saleh

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.