Redundant type specification bug?

So I've just installed resharper 4.0, and I made a method that looked like this:

public string[] GetDocumentList()
{
return new string[] { "filename1.doc", "filename2.doc" };
}

Now it comes up and tells me that there is a redundant explicit array type specification, so it suggests me to change it to the following:

public string[] GetDocumentList()
{
return new[] { "filename1.doc", "filename2.doc" };
}

However, clearly this wont compile...

Is this a bug in resharper?

8 comments
Comment actions Permalink

Hello Morten,

Did you try to compile what ReSharper suggested? C# 3.0 compiler is capable
of deducing type of array from initializer list.
Ah, and which version of Visual Studio do you use?

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


MP> So I've just installed resharper 4.0, and I made a method that
MP> looked like this:
MP>
MP> public string[] GetDocumentList()
MP> {
MP> return new string[] { "filename1.doc", "filename2.doc"
MP> };
MP> }
MP> Now it comes up and tells me that there is a redundant explicit
MP> array type specification, so it suggests me to change it to the
MP> following:
MP>
MP> public string[] GetDocumentList()
MP> {
MP> return new[] { "filename1.doc", "filename2.doc" };
MP> }
MP> However, clearly this wont compile...
MP>
MP> Is this a bug in resharper?
MP>


0
Comment actions Permalink

Ah of course. It's vs2008 but it's a 2.0 project which is why it wont work. Thanks! :)

0
Comment actions Permalink

Hello Morten,

That shouldn't be the case, because VS2008 uses C# 3.0 compiler regardless
of target framework. Do you have customized project? If not, could you create
small repro solution where the problem manifests itself? Thanks!

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


MP> Ah of course. It's vs2008 but it's a 2.0 project which is why it
MP> wont work. Thanks! :)
MP>


0
Comment actions Permalink

Ilya,

Actually, it's possible to get VS to use the CSC 2.0 compiler. You need to
set the ToolsVersion attribute on the project files to 2.0 and then set the
UseHostCompiler property to false. VS 2008 will then use the 2.0 compiler.

It's an edge case, but I know that we've been doing it on a large project
until we're ready to cut-over to 3.5 in its entirety.

Cheers,
--Oren

"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b1506c28ca3fb79d9938de@news.intellij.net...

Hello Morten,

>

That shouldn't be the case, because VS2008 uses C# 3.0 compiler regardless
of target framework. Do you have customized project? If not, could you
create small repro solution where the problem manifests itself? Thanks!

>

Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

MP> Ah of course. It's vs2008 but it's a 2.0 project which is why it
MP> wont work. Thanks! :)
MP>


0
Comment actions Permalink

Hello Oren,

Thanks, we will check if we can extract this info and pass it to our systems,
so that they behave in C# 2.0 compatiblity mode.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


ON> Ilya,
ON>
ON> Actually, it's possible to get VS to use the CSC 2.0 compiler. You
ON> need to set the ToolsVersion attribute on the project files to 2.0
ON> and then set the UseHostCompiler property to false. VS 2008 will
ON> then use the 2.0 compiler.
ON>
ON> It's an edge case, but I know that we've been doing it on a large
ON> project until we're ready to cut-over to 3.5 in its entirety.
ON>
ON> Cheers,
ON> --Oren
ON> "Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
ON> news:76a2bd0b1506c28ca3fb79d9938de@news.intellij.net...
ON>
>> Hello Morten,
>>
>> That shouldn't be the case, because VS2008 uses C# 3.0 compiler
>> regardless of target framework. Do you have customized project? If
>> not, could you create small repro solution where the problem
>> manifests itself? Thanks!
>>
>> Sincerely,
>> Ilya Ryzhenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> MP> Ah of course. It's vs2008 but it's a 2.0 project which is why it
>> MP> wont work. Thanks! :)
>> MP>


0
Comment actions Permalink

Cool, thanks!

The only thing you really need to check is the ToolsVersion attribute on the
project. The UseHostCompiler attribute is a red-herring. If the
ToolsVersion attribute is set to 2.0 and the host compiler option isn't set,
VS will let you use the 3.0 syntax and won't complain. However, if you use
the command-line MSBuild, the sln will fail to build. It comes down to the
fact that VS tries to cache a CSC instance in memory so it effectively
ignores the toolsversion for the compiler if host compiler isn't set. That
doesn't mean that the behavior is correct.

The general rule should be that if the ToolsVersion attribute is 3.5, then
MSBuild will use the 3.5 toolset (including CSC 3.0). If the ToolsVersion
attribute is 2.0, then it'll use CSC 2.0. The TargetFramework element is
irrelevant to the compiler selection, it's just about the ToolsVersion
attribute.

Cheers, :)
--Oren


"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b15071c8ca3fd516a3d235@news.intellij.net...

Hello Oren,

>

Thanks, we will check if we can extract this info and pass it to our
systems, so that they behave in C# 2.0 compatiblity mode.

>

Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

ON> Ilya,
ON> ON> Actually, it's possible to get VS to use the CSC 2.0 compiler.
You
ON> need to set the ToolsVersion attribute on the project files to 2.0
ON> and then set the UseHostCompiler property to false. VS 2008 will
ON> then use the 2.0 compiler.
ON> ON> It's an edge case, but I know that we've been doing it on a large
ON> project until we're ready to cut-over to 3.5 in its entirety.
ON> ON> Cheers,
ON> --Oren
ON> "Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
ON> news:76a2bd0b1506c28ca3fb79d9938de@news.intellij.net...
ON>

>>> Hello Morten,
>>>
>>> That shouldn't be the case, because VS2008 uses C# 3.0 compiler
>>> regardless of target framework. Do you have customized project? If
>>> not, could you create small repro solution where the problem
>>> manifests itself? Thanks!
>>>
>>> Sincerely,
>>> Ilya Ryzhenkov
>>> JetBrains, Inc
>>> http://www.jetbrains.com
>>> "Develop with pleasure!"
>>> MP> Ah of course. It's vs2008 but it's a 2.0 project which is why it
>>> MP> wont work. Thanks! :)
>>> MP>
>


0
Comment actions Permalink

Hi,

If you need a test project here is one. Once again, thanks for the quick replies.

Morten



Attachment(s):
ResharperTest.zip
0
Comment actions Permalink

Hello,

We appreciate your feedback. The corresponding JIRA request has been created,
and you are welcome to monitor its status at http://www.jetbrains.net/jira/browse/RSRP-58349.

You may want to check our request tracking policy here: http://www.jetbrains.net/confluence/display/ReSharper/ReSharperIssueTracker

Best regards,
- Development Team.


0

Please sign in to leave a comment.