Child pages
  • Co-variant array conversion may cause exception on write operation
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Consider the following code listing

This code shows an Open File Dialog and then attempts to asynchronously process the chosen files. However, what the developer has missed is that the BeginInvoke() method actually takes a params object[] argument, to which the developer is passing an array of strings. As a consequence, ReSharper offers a warning, saying that the covariant array conversion from string[] to object[] may cause an exception at run-time.

The issue with the above code is easily resolved: since BeginInvoke() expects to receive an array of all the parameters and there is only one parameter (string[] files), all we have to do is provide exactly that, i.e.,

  • No labels