Cannot convert source type to target type

This is a really interesting puzzle. I have a set of classes that I am busily refactoring (see the sample code below). The difference in the real code is that Foo is defined in a separate assembly from Bar and Baz. The code compiles without any errors, but ReShaper complains that it cannot convert source type Logging.Log to target type Logging.Log.

At first I thought this was a bug in ReShaper, but then I noticed that it did not complain about the identical code with the Messaging class. After a bit of head scratching and investigation, I discovered that the assembly in which Foo is defined references a binary copy of the Logging assembly instead of the project I am refactoring. I corrected the reference and the error highlight went away.

I thought you might find it interesting to know that you successfully detected an error condition that blew right past Visual Studio's compiler.

For what it's worth, I do not normally create such sloppy code as this (or so I hope!). I'm at an intermediate refactoring stage in which I am moving methods into temporary static classes.

namespace Test
{
class Foo
{
protected Messaging _messaging;
protected Log _log;
}

class Bar : Foo
{
public Foo()
{
Baz.messaging = _messaging;
// Cannot convert source type Logging.Log to target type Logging.Log
Baz.log = _log;
}
}

class Baz
{
public static Messaging messaging;
public static Log log;
}
}

9 comments
Comment actions Permalink

Are you using Resharper 1.5? This was a problem in 1.0 ...

"GREGORY LAW" <lothan@email.uophx.edu> wrote in message news:dck55l$j1j$1@is.intellij.net...
This is a really interesting puzzle. I have a set of classes that I am busily refactoring (see the sample code below). The difference in the real code is that Foo is defined in a separate assembly from Bar and Baz. The code compiles without any errors, but ReShaper complains that it cannot convert source type Logging.Log to target type Logging.Log.

At first I thought this was a bug in ReShaper, but then I noticed that it did not complain about the identical code with the Messaging class. After a bit of head scratching and investigation, I discovered that the assembly in which Foo is defined references a binary copy of the Logging assembly instead of the project I am refactoring. I corrected the reference and the error highlight went away.

I thought you might find it interesting to know that you successfully detected an error condition that blew right past Visual Studio's compiler.

For what it's worth, I do not normally create such sloppy code as this (or so I hope!). I'm at an intermediate refactoring stage in which I am moving methods into temporary static classes.

namespace Test
{
class Foo
{
protected Messaging _messaging;
protected Log _log;
}

class Bar : Foo
{
public Foo()
{
Baz.messaging = _messaging;
// Cannot convert source type Logging.Log to target type Logging.Log
Baz.log = _log;
}
}

class Baz
{
public static Messaging messaging;
public static Log log;
}
}

0
Comment actions Permalink

I can attest to this issue with version 1.5 as well.

0
Comment actions Permalink

Hello David,

could you please create a simple solution demonstrating the issue?
You could then send us that solution and we'll check it here.

Thanks.

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

I can attest to this issue with version 1.5 as well.



0
Comment actions Permalink

Here's a "simple app". It uses the iTunes application for it's interfaces so you'll need to install it and possibly repair the references to it. My apologies for the complexity but this is how I found this issue. You'll find the bug in the UnitTests project in the SetUp method of the SampleTest.

Thanks,
Dave



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

Hello David,

thank you, I've been able to repeat the problem. We'll be working to fix it.


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

Here's a "simple app". It uses the iTunes application for it's
interfaces so you'll need to install it and possibly repair the
references to it. My apologies for the complexity but this is how I
found this issue. You'll find the bug in the UnitTests project in the
SetUp method of the SampleTest.

Thanks,
Dave



0
Comment actions Permalink

It's been what? 6 years? and I still see the very same issue but about converting dictionary to dictionary. I have a licensed product:


JetBrains ReSharper 6.1 C# Edition
Build 6.1.37.86 on 2011-12-21T05:15:24



Attachment(s):
error.jpg
0
Comment actions Permalink

Hello Zane
     Could you please attach a small sample solution that would demonstrate this problem? Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

I have many but apparently cutting and pasting classes into a new project does NOT reproduce the problem. Somehow it's reprtoring the namespace of the class that is NOT actually the namespace the class belongs to. I'll try to re-create the problem but it takes too much time, which I don't have right now.

0
Comment actions Permalink

Hello Zane
     Have you tried clearing ReSharper caches for your solution? To do that, open ReSharper | Options | Environment | General, click 'Clear caches' and then restart Visual Studio. Let me know if this helps. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Please sign in to leave a comment.