PostSharp and VS.NET Test Project

Questions about integration in Visual Studio, MSBuild or other IDEs or build tools.

PostSharp and VS.NET Test Project

Postby sIrcHarles on Wed May 14, 2008 4:50 pm

Hello,
I have following problem. I created a O/R mapping class library and I wrote about 300 tests to test it. Library is used in a application where some problems occured. So I decided to add support for software memory transaction (NSTM project from Codeplex).
Everything worked fine when I decorated only classes in test project with NstmTranactional attribute.
I added this attribute to my library classes and I cannot execute some test because of System.InvalidProgramException: Common Language Runtime detected an invalid program...
Stack trace of the exception follows:
Code: Select all
   at PCollection`1.PCollection`1.IncrementVersion()
   at NstmTransactionalAspect.OnSetValue(FieldAccessEventArgs eventArgs)
   at PCollection`1.~set~_state(PCollectionState value)
   at PCollection`1.set_State(PCollectionState value)
   at PCollection`1..ctor(MemberInfo member, Object parent, PSession sessionContext)

I don't think that it is a problem of the NSTM library. My own aspects caused that error too.
Running the code outside VS.NET (i.e. not via Test Manager) works fine.

Thanks for answer
Karel
sIrcHarles
 
Posts: 4
Joined: Wed May 14, 2008 4:28 pm
Full Name: Karel Frajták

Re: PostSharp and VS.NET Test Project

Postby gfraiteur on Thu May 15, 2008 8:44 am

The best thing to do is to run peverify on your assembly. Then send me (as a bug report) the output of that utility and the source code (or MSIL) of incorrect methods.

Thanks,

Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 581
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org

Re: PostSharp and VS.NET Test Project

Postby sIrcHarles on Tue May 20, 2008 4:52 pm

I switched off "Enable the Visual Studio hosting process" in my project Properties.Debug tab and it works correctly.
Thanx anyway.
sIrcHarles
 
Posts: 4
Joined: Wed May 14, 2008 4:28 pm
Full Name: Karel Frajták

Re: PostSharp and VS.NET Test Project

Postby gfraiteur on Tue May 20, 2008 4:53 pm

That's not a solution... If you could send me the MSIL of the offending method (identified using PEVERIFY), I could correct the bug for others...
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 581
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org

Re: PostSharp and VS.NET Test Project

Postby sIrcHarles on Thu May 22, 2008 9:58 am

Here is report generated by peverify
Code: Select all
Microsoft (R) .NET Framework PE Verifier.  Version  2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved.

[MD]: Warning: Class does not implement interface method in this module (class:0x020000de; interface:0x020000dc; method:0x06000703). [token:0x0900002F]
[IL]: Error: [Persistence.dll : Persistence.Core.PClassProxy::~set~_getObjectFromCacheNotReload][mdToken=0x600006f][offset 0x00000066] Cannot change initonly field outside its .ctor.
[IL]: Error: [Persistence.dll : Persistence.Collections.PCollection`1[T]::~set~_comparer][mdToken=0x60006b9][offset 0x0000005C] Cannot change initonly field outside its .ctor.
[IL]: Error: [Persistence.dll : Persistence.Collections.Internal.PCollectionItem`1[T]::~set~_value][mdToken=0x600077d][offset 0x00000066] Cannot change initonly field outside its .ctor.
3 Errors Verifying Persistence.dll(1 Warnings)

Microsoft (R) .NET Framework PE Verifier.  Version  2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved.

[IL]: Error: [PersistenceVSTSTester.dll : PersistenceVSTSTester.Classes.Invoice::~set~_idInvoice][offset 0x00000066] Cannot change initonly field outside its .ctor.
[IL]: Error: [PersistenceVSTSTester.dll : PersistenceVSTSTester.ClassAndCompoundStorage.Locking.AssistanceRequest::~set~_idAssistanceRequest][offset 0x00000066] Cannot change initonly field outside its .ctor.
[IL]: Error: [PersistenceVSTSTester.dll : PersistenceVSTSTester.Classes.AssistanceReason::~set~_idAssistanceReason][offset 0x00000066] Cannot change initonly field outside its .ctor.
3 Errors Verifying PersistenceVSTSTester.dll

and here is IL of the first method in report (copied from ildasm)
Code: Select all
.method private hidebysig instance bool  '~get~_getObjectFromCacheNotReload'() cil managed
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
  .custom instance void [mscorlib]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 )
  // Code size       121 (0x79)
  .maxstack  4
  .locals init ([0] bool fieldValue,
           [1] class [PostSharp.Laos]PostSharp.Laos.FieldAccessEventArgs '~laosEventArgs~1',
           [2] bool '~emptyValue~2')
  IL_0000:  ldarg.0
  IL_0001:  ldfld      bool Persistence.Core.PClassProxy::_getObjectFromCacheNotReload
  IL_0006:  stloc      fieldValue
  IL_000a:  ldnull
  IL_000b:  ldloc      fieldValue
  IL_000f:  box        [mscorlib]System.Boolean
  IL_0014:  ldtoken    field bool Persistence.Core.PClassProxy::_getObjectFromCacheNotReload
  IL_0019:  call       class [mscorlib]System.Reflection.FieldInfo [mscorlib]System.Reflection.FieldInfo::GetFieldFromHandle(valuetype [mscorlib]System.RuntimeFieldHandle)
  IL_001e:  ldarg.0
  IL_001f:  newobj     instance void [PostSharp.Laos]PostSharp.Laos.FieldAccessEventArgs::.ctor(object,
                                                                                                object,
                                                                                                class [mscorlib]System.Reflection.FieldInfo,
                                                                                                object)
  IL_0024:  stloc      '~laosEventArgs~1'
  IL_0028:  ldloc      '~laosEventArgs~1'
  IL_002c:  ldarg.0
  IL_002d:  call       instance valuetype [PostSharp.Laos]PostSharp.Laos.InstanceCredentials Persistence.Core.PClassProxy::GetInstanceCredentials()
  IL_0032:  call       instance void [PostSharp.Laos]PostSharp.Laos.InstanceBoundLaosEventArgs::set_InstanceCredentials(valuetype [PostSharp.Laos]PostSharp.Laos.InstanceCredentials)
  IL_0037:  ldsfld     class [CommonAspects]CommonAspects.TransactionalMemory.NstmTransactionalAspect '~PostSharp~Laos~Implementation'::'NstmTransactionalAspect~12'
  IL_003c:  ldloc      '~laosEventArgs~1'
  IL_0040:  callvirt   instance void [PostSharp.Laos]PostSharp.Laos.IOnFieldAccessAspect::OnGetValue(class [PostSharp.Laos]PostSharp.Laos.FieldAccessEventArgs)
  IL_0045:  ldloc      '~laosEventArgs~1'
  IL_0049:  call       instance object [PostSharp.Laos]PostSharp.Laos.FieldAccessEventArgs::get_ExposedFieldValue()
  IL_004e:  dup
  IL_004f:  brfalse.s  IL_0061
  IL_0051:  unbox      [mscorlib]System.Boolean
  IL_0056:  ldobj      [mscorlib]System.Boolean
  IL_005b:  stloc      fieldValue
  IL_005f:  br.s       IL_0074
  IL_0061:  pop
  IL_0062:  ldloca     '~emptyValue~2'
  IL_0066:  initobj    bool
  IL_006c:  ldloc      '~emptyValue~2'
  IL_0070:  stloc      fieldValue
  IL_0074:  ldloc      fieldValue
  IL_0078:  ret
} // end of method PClassProxy::'~get~_getObjectFromCacheNotReload'


I hope this helps... Thanx

PS: As you wrote, switching "Enable the Visual Studio hosting process" off was not solution, errors are raised although...
Last edited by sIrcHarles on Thu May 22, 2008 10:43 am, edited 1 time in total.
sIrcHarles
 
Posts: 4
Joined: Wed May 14, 2008 4:28 pm
Full Name: Karel Frajták

Re: PostSharp and VS.NET Test Project

Postby sIrcHarles on Thu May 22, 2008 10:37 am

I tried to make some changes to my code. And I discovered this - when the code was compiled I noticed the message "postsharp warning PS0069: PostSharp: Cannot weave the initialization of the field XXX, because it is initialized outside the constructor. The weaving of this field initialization will be ignored, but other field assignments will be woven."
So I changed my code from
Code: Select all
public class Invoice {
  ...
  private int _idInvoice = -1;
  ...
}

to
Code: Select all
public class Invoice {
  public Invoice()
  {
    _idInvoice = -1;
  }

  private readonly int _idInvoice;
}

PEVerify gave me already mentioned error. I tried to remove "readonly" keyword and it worked. PEVerify did not find any problem in this class.
sIrcHarles
 
Posts: 4
Joined: Wed May 14, 2008 4:28 pm
Full Name: Karel Frajták

Re: PostSharp and VS.NET Test Project

Postby gfraiteur on Thu May 22, 2008 10:48 am

Oh yes, it makes sense. Init-only fields are not supported (or cannot be woven). I should add a guard. Could you please report a bug referring to this topic?

Thank you.

Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 581
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org

Re: PostSharp and VS.NET Test Project

Postby gfraiteur on Thu May 22, 2008 10:48 am

Oh it's already done! Thanks.
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 581
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org


Return to Integration with IDE and Build Scripts


cron