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
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.
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]{
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
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
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
This issue is finally fixed in Resharper beta 5.1 - download at
http://confluence.jetbrains.net/display/ReSharper/ReSharper+5.1+Nightly+Builds
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.
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!
Excellent - I've just downloaded 5.1 and tried it out and it is indeed fixed. This pleases me very much!
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
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