I\'m using C# to manipulate an Excel worksheet. The following two pieces of code should work the same, but one works and the other throws an exception. I wonder why.
Use the Worksheet Range property instead. For example, instead of
oRange = (Excel.Range)oSheet.get_Range(oSheet.Cells[1, 1],oSheet.Cells[4,4]);
use
oRange = (Excel.Range)oSheet.Range[oSheet.Cells[1, 1],oSheet.Cells[4,4]];
I was using the get_Range() method extensively when I leveraged off .NET 2. When I changed to .NET 4 Client Profile, I got this exception also. Replacing the get_Range() references with the Range property addressed this issue for me.