Anybody using CslaLight and also use ReSharper?

Anybody using CslaLight and also use ReSharper?

Old forum URL: forums.lhotka.net/forums/t/6372.aspx


cds posted on Sunday, February 08, 2009

Hey All

Just getting back into some CSLA development using CslaLight. I use the Visual Studio ReSharper Plug-in (4.1) and it gets very confused with the linked business object classes in the .NET server class library and the Silverlight class library.

Basically, I have my business object class (and I've used the #if SILVERLIGHT to separate the appropriate sections of the Silverlight and CSLA.NET code). If I start up Visual Studio and open the Business Object file from the Silverlight Class Library it all looks fine. ReSharper "grays out" the code that's not inside the Silverlight sections.

But, when I then open the same file Business Object class from the .NET Class Library, ReSharper shows me a lots of "red squiggleys" indicating that there are errors in the code, which there aren't as it all compiles nicely.

I'm wondering why this is the case. It seems that ReSharper is doing some caching of assemblies and is getting confused between the CSLA.NET and CslaLight versions. I know there's not anything actually wrong with the code, but it does make the experience a lot less productive if I can't distinguish "real" errors from bogus ones. This is on 3.6.1 of CSLA.

Maybe I should be bringing the issue up with the JetBrains people (who make ReSharper) but I thought I'd see if anybody else has had similar experience, or whether something can be done to prevent the conflict.

Cheers...

Craig

RockfordLhotka replied on Sunday, February 08, 2009

Are you using VB or C#?

C# both grays out and collapses the sections of code that don't match the compiler directive. Resharper may override this so the sections are visible?

VB doesn't collapse the sections of code. I think it grays them out. It isn't nearly as nice though :(

But standard Visual Studio doesn't attempt to parse or process the non-matching sections, so it is clearly something Resharper must be doing.

You'll have to talk to them about it. It is something they'll probably want to address, since this technique of putting a file into two projects for Silverlight is not just a CSLA thing - the Prism people use it, as do pretty many any other people supporting shared code between Silverlight and .NET.

cds replied on Sunday, February 08, 2009

Hi Rocky

Thanks for the reply. I'll clarify some points since I didn't make myself clear enough first time.

I'm using C#, not VB.

The sections that ReSharper is "complaining" about aren't the greyed out sections not applying to that project, but the active sections.

Just some examples:

[Serializable]

protected override void AddBusinessRules()

{

ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, SurnameProperty);

ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, FirstNameProperty);

}

 

public static PatientEdit GetPatient(Guid id)

{

return DataPortal.Fetch<PatientEdit>(new SingleCriteria<PatientEdit, Guid>(id));

}

 

protected override void DataPortal_Create()

{

using (BypassPropertyChecks)

Status = "Created " + ApplicationContext.ExecutionLocation.ToString();

base.DataPortal_Create();

}

Has the errors:

Yet, as I said, the whole thing compiles fine. So, ReSharper is seriously confused. Interestingly, if I delete its cache folders, open up the solution and open the server class it is all fine. Then I open the Silverlight class and it is also fine. Then I switch back to the server version of the class and the "errors" are back.

Anyway, I will put together a demonstration project for the ReSharper guys to look at and they can hopefully figure it out.

Craig

nermin replied on Sunday, February 08, 2009

I am using Resharper with Csla for Silverlight and have had seen some of the issue that you mention.

 

The biggest problem is that in Clsa for Silverlight BO class file can generally be used/compiled in both Silverlight and .Net assemblies (client and server assemblies).

 

Seriazable issue is an interesting problem.  Silverlight does not define SerializableAttribute, and CslaLight actually defines the attribute instead inside Csla namespace.

 

Therefore for .Net project you will have SerializableAttribute declared in one namespace (System I believe), and for Silverlight it will be inside Csla.Serialization. 

 

If you open your BO class file from .Net project – ReSharper will complain that the Csla.Serialization is unused namespace (and it is in that project).  On the other hand if you open the same file in Silverlight project (we use concept of linked files), you will notice that ReSharper states that System namespace is not used.

 

Both of the assumptions are correct I one assumes that class is only declared and used in one of the runtimes.  However that is not the case here.  So to avoid this, I declare namespaces like following:

#if !SILVERLIGHT

using System;

#else

using Csla.Serialization;

#endif

 

This way ReShrper does not get confused as it does not use Silverlight namespaces in .Net and vice versa.  Same is the case for some of the declarations you mention below – some of the signatures are only part of Csla Silverlight runtime and others are a part of Csla .Net runtime.  Hence you might see these separated by #if SILVELIGHT compile directives.

 

 

 

 

From: cds [mailto:cslanet@lhotka.net]
Sent: Sunday, February 08, 2009 3:11 PM
To: Nermin Dibek
Subject: Re: [CSLA .NET] Anybody using CslaLight and also use ReSharper?

 

Hi Rocky

Thanks for the reply. I'll clarify some points since I didn't make myself clear enough first time.

I'm using C#, not VB.

The sections that ReSharper is "complaining" about aren't the greyed out sections not applying to that project, but the active sections.

Just some examples:

[Serializable]

protected override void AddBusinessRules()

{

ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, SurnameProperty);

ValidationRules.AddRule(Csla.Validation.CommonRules.StringRequired, FirstNameProperty);

}

 

public static PatientEdit GetPatient(Guid id)

{

return DataPortal.Fetch<PatientEdit>(new SingleCriteria<PatientEdit, Guid>(id));

}

 

protected override void DataPortal_Create()

{

using (BypassPropertyChecks)

Status = "Created " + ApplicationContext.ExecutionLocation.ToString();

base.DataPortal_Create();

}

Has the errors:

Yet, as I said, the whole thing compiles fine. So, ReSharper is seriously confused. Interestingly, if I delete its cache folders, open up the solution and open the server class it is all fine. Then I open the Silverlight class and it is also fine. Then I switch back to the server version of the class and the "errors" are back.

Anyway, I will put together a demonstration project for the ReSharper guys to look at and they can hopefully figure it out.

Craig



cds replied on Sunday, February 08, 2009

Hi Nermin

Thanks for the tip - that does indeed fix the Serializable issue, but the others remain in the server version of the class. But I shall take it up with the JetBrains people.

Craig

PeteH replied on Monday, February 09, 2009

I have this issue with ReSharper too, I went with partial classes in the end instead of the #if SILVERLIGHT defines which helped. I have to add the Csla and CslaLight projects to my business object DLLs too, or it gets in a muddle very quickly. This isn't a major problem, as you can change both projects to release and then untick them in the configuration manager - so that they don't build when you need to recompile the business objects - but this isn't a very neat solution.

Please let me know how you get on with JetBrains as I'd love to see a fix for this too.

Jaans replied on Saturday, July 11, 2009

Does anyone have some news on this?

I'm also getting a very confused resharper with Silverlight and Csla.

Regards,
Jaans

RockfordLhotka replied on Monday, July 13, 2009

After the NDC I did receive an email from a guy at ReSharper asking why
anyone would have an assembly on the Silverlight side that had the same
strong name as an assembly on the .NET side.

I explained, but I never heard back after that.

But apparently this is the problem - ReSharper isn't smart enough to handle
the scenario where the solution uses different assemblies that have the same
name.

Rocky

Jack replied on Tuesday, July 14, 2009

I sent an email in a long time ago but never heard anything.  If someone wants to properly notify them and get a ticket# or whatever they use I'm happy to attach my comments to it.

If enough people complain they might work on fixing it.

Jack replied on Tuesday, July 14, 2009

I sent an email in a long time ago but never heard anything.  If someone wants to properly notify them and get a ticket# or whatever they use I'm happy to attach my comments to it.

If enough people complain they might work on fixing it.

Jaans replied on Wednesday, August 05, 2009

Hi All

I took the time to create a mock Visual Studio solution with all the different projects (.NET and Silverlight) in order to simulate the issue with the simplest of CSLA implementation that I could come up with (given a short time frame).

I also created small document describing the issue. I proceeded to email it all to JetBrains and opened a Resharper issue/bug with them (RSRP-116566).

You can view the bug using the link below. I would suggest that multiple people register with them,log in and vote on the issue.

http://www.jetbrains.net/jira/browse/RSRP-116566

Ps: For us the issue is important enough that it compells to create some noise about it in order to get them to act on it more seriously - hence this post request some "backup" from the community ;-)

Regards,
Jaans

Jack replied on Thursday, August 06, 2009

Thank you for taking the time to do that. I've voted and will add some
comments this week.

-----Original Message-----
From: Jaans [mailto:cslanet@lhotka.net]
Sent: August-05-09 8:31 PM
To: jaddington@alexandergracie.com
Subject: Re: [CSLA .NET] RE: RE: Anybody using CslaLight and also use
ReSharper?

Hi All

I took the time to create a mock Visual Studio solution with all the
different projects (.NET and Silverlight) in order to simulate the issue
with the simplest of CSLA implementation that I could come up with (given a
short time frame).

I also created small document describing the issue. I proceeded to email it
all to JetBrains and opened a Resharper issue/bug with them (RSRP-116566).

You can view the bug using the link below. I would suggest that multiple
people register with them,log in and vote on the issue.

http://www.jetbrains.net/jira/browse/RSRP-116566

Ps: For us the issue is important enough that it compells to create some
noise about it in order to get them to act on it more seriously - hence this
post request some "backup" from the community ;-)

Regards,
Jaans

espenrl replied on Monday, June 28, 2010

This issue is finally fixed in Resharper beta 5.1 - download at

http://confluence.jetbrains.net/display/ReSharper/ReSharper+5.1+Nightly+Builds

RockfordLhotka replied on Monday, June 28, 2010

I am glad to hear they fixed it. I talked to them months ago while at PDC (so it was face to face) and explained the reasoning why CSLA works as it does. Of course the fact that SL4 assemblies can be used in .NET projects probably also helped convince them that they needed to make this possible.

Jaans replied on Monday, June 28, 2010

To me that is excellent news indeed! Especially since I've been doing so much CSLA + Silverlight work of late.

Thanks for the face-to-face-good-word on this issue - I'm sure it made a big difference. I feared that JetBrains did not consider it that important and kept bumping the fix for later, also not many users voted to complain (thanks to those who did though).

Woo hoo!

cds replied on Tuesday, July 20, 2010

Excellent - I've just downloaded 5.1 and tried it out and it is indeed fixed. This pleases me very much!

Jack replied on Monday, October 18, 2010

I've noticed that with a later build this has crept back in .  I'm seeing the same issues again with the reference error.  I'm still in CSLA 3.8.x.  Is anybody else seeing this or is it something I've managed to do?

I just had did an upgrade to 5.1.1754.4

jack

Jaans replied on Monday, October 18, 2010

Haven't noticed the regression, but I'm on 5.1.1753.3 still (and since your post might remain there). I do have a super annoying and possibly related issue with ReSharper messing up with Silverlight and the CSLA ViewModel (infact I derive from it first to add custom bits).

http://youtrack.jetbrains.net/issue/RSRP-192638

To me it's as if ReSharper has added so much "extra" features over the years that it's now just not doing it's core functions well any more. I find it not as quick as it used to be and wish I could turn it off for Silverlight projects because it's just too interruptive!

Copyright (c) Marimer LLC