Most of the time Visual Studio is pretty good about telling us where syntax errors and other bugs are hiding. Occasionally though (even after our tech lead has warned us to be on the lookout for "that one bug" they mentioned) even the best of us get stumped. Some of the most challenging bugs can be run time errors - especially the ones that are hiding deep within the code base, don't cause any Intellisense warnings or errors, and aren't developer-caused. In the case of the CS0030 error, it happens in a generated file in which you're warned "Changes to this file may cause incorrect behavior".
When I ran across this issue, it dawned on me after perhaps a little too long that my tech lead's infamous "double bracket bug" was exactly what was I was ramming my head against when I added our Salesforce web reference to my project. It also dawned on me that others may have the same hangup as me and that I should write about it to share. I'm not going to get overly technical in this article; my main goal is to get problem and resolution across in a written format.
Now to the problem! For whatever reason, when some web references are added, Visual Studio decides to be extra doubly helpful when generating the reference class files and builds something like this:
(Note the double pairs of brackets, one of which I highlighted. That highlighted one shouldn't be there.)
Once you've run across this a time or two, it's like second nature to fix it, but for those who are in their first CS0030 rodeo I wanted to share how I found and resolved the issue:
- First I checked StackOverflow and found a lot of good info here regarding why it happens to XmlElementAttribute, and that it's not really that uncommon: https://stackoverflow.com/questions/6678934/unable-to-generate-a-temporary-class-result-1-error-cs0030-cannot-convert-ty
- Second I went to my Salesforce web reference class file and searched for ''. Lo and behold, about 255k lines in, there was a pair of a pair of brackets! Deleting one of the two pairs resolved the issue, allowing me to continue on my merry way to running and testing through my code.
In summary, if you have recently added one or several web references to your C# project and Visual Studio gives you an error code of CS0030 take a look at their reference classes and search for double brackets ''. You may just have an extra pair or two hiding in there.