Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘

Assuming InvoiceMaster derives from or implements InvoiceHD, and that you’re using C# 4 and .NET 4 or higher, you can just use generic variance: This uses the fact that an IEnumerable<InvoiceMaster> is an IEnumerable<InvoiceHD> because IEnumerable<T> is covariant in T. Another way to solve it would be to change the declaration of MstDtl to use explicit typing: (I’d also suggest following regular C# naming, where local variables start with … Read more

Root element is missing

Hi this is odd way but try it once Read the file content into a string print the string and check whether you are getting proper XML or not you can use XMLDocument.LoadXML(xmlstring) I try with your code and same XML without adding any XML declaration it works for me As stated by Phil in below … Read more

How to catch all exceptions in c# using try and catch?

Both approaches will catch all exceptions. There is no significant difference between your two code examples except that the first will generate a compiler warning because ex is declared but not used. But note that some exceptions are special and will be rethrown automatically. ThreadAbortException is a special exception that can be caught, but it will automatically be … Read more

Case insensitive ‘Contains(string)’

To test if the string paragraph contains the string word (thanks @QuarterMeister) Where culture is the instance of CultureInfo describing the language that the text is written in. This solution is transparent about the definition of case-insensitivity, which is language dependent. For example, the English language uses the characters I and i for the upper and lower case versions of the ninth letter, whereas the Turkish language uses … Read more

Make first letter of a string upper case (with maximum performance)

Solution in different C# versions C# 8 with at least .NET Core 3.0 or .NET Standard 2.1 Since .NET Core 3.0 / .NET Standard 2.1 String.Concat() supports ReadonlySpan<char> which saves one allocation if we use .AsSpan(1) instead of .Substring(1). C# 8 C# 7 Really old answers This version is shorter. For a faster solution, take a look at Diego’s answer. Probably the fastest … Read more

How to use WPF Background Worker

Add using Declare Background Worker: Subscribe to events: Implement two methods: Run worker async whenever your need. Track progress (optional, but often useful)a) subscribe to ProgressChanged event and use ReportProgress(Int32) in DoWorkb) set worker.WorkerReportsProgress = true; (credits to @zagy)

How to block until an event is fired in c#

If the current method is async then you can use TaskCompletionSource. Create a field that the event handler and the current method can access. This example uses a form that has a textblock named WelcomeTitle and two buttons. When the first button is clicked it starts the click event but stops at the await line. … Read more