Build/Test Issues

Failing Tests - PostSharp

Started by pglaspey on 17,151 views

We use Devforce 2010 in our app and it uses Postsharp to modify our entities and create metadata.

This metadata is empty when running tests in NCrunch.

But not in Xunit, Nunit, or MStest using either built in runner or TestRunner from testdriven.net.

How do I get NCrunch to fire off postsharp on these project before it runs the test?
Hi,

I'm not too familiar with the mechanics of Devforce or Postsharp, but is it possible that the Postsharp manipulation happens on a post build event? NCrunch will turn off post build events by default (as they often give interference on NCrunch builds for many projects). Try turning them on for your test project underneath your NCrunch project configuration.

Cheers,

Remco
Remco wrote:Hi,

I'm not too familiar with the mechanics of Devforce or Postsharp, but is it possible that the Postsharp manipulation happens on a post build event? NCrunch will turn off post build events by default (as they often give interference on NCrunch builds for many projects). Try turning them on for your test project underneath your NCrunch project configuration.

Cheers,

Remco


ok I have tried turning on Post build in the ncrunch configuration for the project under test and the test project as well.

I am not very sure of how or when postsharp knows to fire off but I am pretty sure this is what is causing the tests to fail.
Thanks - please do let me know if this solves the problem for you. Otherwise we can try something else.
Remco wrote:Thanks - please do let me know if this solves the problem for you. Otherwise we can try something else.


It did not solve the problem.

perhaps this might shed some light on it.

http://doc.sharpcrafters.com/postsharp-2.1/##PostSharp-2.1.chm/html/ddb988ad-fde6-4e52-83d0-073326f4e44b.htm

thanks for your help.

NCrunch has changed the way I develop, it is a fantastic tool, a real game changer. Thanks.

Edited

The next thing to check is whether postsharp needs any build resources that haven't been included with your project. Do you have a directory relative to your project(s) that contains postsharp resources of any kind? Try specifying it with the 'Additional files to include' setting under your project configuration - https://www.ncrunch.net/documentation/reference_project-configuration_overview

If that doesn't do the trick, can you send me through a bug report after the build has finished? I'll see if I can establish the failure from the log file.
Remco wrote:The next thing to check is whether postsharp needs any build resources that haven't been included with your project. Do you have a directory relative to your project(s) that contains postsharp resources of any kind? Try specifying it with the 'Additional files to include' setting under your project configuration - https://www.ncrunch.net/documentation/reference_project-configuration_overview

If that doesn't do the trick, can you send me through a bug report after the build has finished? I'll see if I can establish the failure from the log file.


I have submitted a bug report. (I do not know what to include in the Additional files at this point).
Thanks! Would you also be able to copy/paste for me the reference from your .proj file into postsharp? I expect there will be an <Import> or something similar.
Remco wrote:Thanks! Would you also be able to copy/paste for me the reference from your .proj file into postsharp? I expect there will be an <Import> or something similar.



Here is a project that is processed by postsharp. I could see nothing referenced.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="(- BROKEN LINK -)">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F6607DDD-8D28-4FE8-8A9E-CADD34814C73}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Decade.CIW.Model</RootNamespace>
<AssemblyName>Decade.CIW.Model</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>$(SolutionDir)\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>$(SolutionDir)\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="IdeaBlade.Core, Version=6.1.7.0, Culture=neutral, PublicKeyToken=287b5094865421c0, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Decade.Ideablade.6.1.7\lib\net\IdeaBlade.Core.dll</HintPath>
</Reference>
<Reference Include="IdeaBlade.EntityModel, Version=6.1.7.0, Culture=neutral, PublicKeyToken=287b5094865421c0, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Decade.Ideablade.6.1.7\lib\net\IdeaBlade.EntityModel.dll</HintPath>
</Reference>
<Reference Include="IdeaBlade.Linq, Version=6.1.7.0, Culture=neutral, PublicKeyToken=287b5094865421c0, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Decade.Ideablade.6.1.7\lib\net\IdeaBlade.Linq.dll</HintPath>
</Reference>
<Reference Include="IdeaBlade.Validation, Version=6.1.7.0, Culture=neutral, PublicKeyToken=287b5094865421c0, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Decade.Ideablade.6.1.7\lib\net\IdeaBlade.Validation.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Entity" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Entities\BusinessActivity.cs" />
<Compile Include="Entities\Chemical.cs" />
<Compile Include="CIWModel.IB.Designer.cs">
<DependentUpon>CIWModel.edmx.tt</DependentUpon>
</Compile>
<Compile Include="Entities\Document.cs" />
<Compile Include="Entities\DocumentType.cs" />
<Compile Include="Entities\Enforcement.cs" />
<Compile Include="Entities\EnforcementViolation.cs" />
<Compile Include="Entities\FacilitySubmittal.cs" />
<Compile Include="Entities\FacilitySubmittalActionNotification.cs" />
<Compile Include="Entities\GeographicInfoCersPoint.cs" />
<Compile Include="Entities\HwFacility.cs" />
<Compile Include="Entities\HwTankClosure.cs" />
<Compile Include="Entities\HwUnit.cs" />
<Compile Include="Entities\HwUnitCa.cs" />
<Compile Include="Entities\HwUnitCel.cs" />
<Compile Include="Entities\HwUnitCesqt.cs" />
<Compile Include="Entities\HwUnitCesw.cs" />
<Compile Include="Entities\HwUnitPbr.cs" />
<Compile Include="Entities\Inspection.cs" />
<Compile Include="Entities\OwnerOperatorInformation.cs" />
<Compile Include="MetaData\BusinessActivityMetaData.cs" />
<Compile Include="MetaData\ChemicalMetaData.cs" />
<Compile Include="MetaData\DocumentMetaData.cs" />
<Compile Include="MetaData\DocumentTypeMetaData.cs" />
<Compile Include="MetaData\EnforcementMetaData.cs" />
<Compile Include="MetaData\EnforcementViolationMetaData.cs" />
<Compile Include="MetaData\FacilitySubmittalActionNotificationMetaData.cs" />
<Compile Include="MetaData\FacilitySubmittalMetaData.cs" />
<Compile Include="MetaData\GeographicInfoCersPointMetaData.cs" />
<Compile Include="MetaData\HwFacilityMetaData.cs" />
<Compile Include="MetaData\HwTankClosureMetaData.cs" />
<Compile Include="MetaData\HwUnitCaMetaData.cs" />
<Compile Include="MetaData\HwUnitCelMetaData.cs" />
<Compile Include="MetaData\HwUnitCesqtMetaData.cs" />
<Compile Include="MetaData\HwUnitCeswMetaData.cs" />
<Compile Include="MetaData\HwUnitMetaData.cs" />
<Compile Include="MetaData\HwUnitPbrMetaData.cs" />
<Compile Include="MetaData\InspectionMetaData.cs" />
<Compile Include="MetaData\OwnerOperatorInformationMetaData.cs" />
<Compile Include="MetaData\RegulatorMetaData.cs" />
<Compile Include="MetaData\RmrActivitiesReportMetaData.cs" />
<Compile Include="MetaData\RmrRecyclableMaterialMetaData.cs" />
<Compile Include="MetaData\RwConsolidationSiteMetaData.cs" />
<Compile Include="MetaData\SubmittalElementMetaData.cs" />
<Compile Include="MetaData\SubmittalStatusTypeMetaData.cs" />
<Compile Include="MetaData\SubmittalTransactionMetaData.cs" />
<Compile Include="MetaData\SubmitterMetaData.cs" />
<Compile Include="MetaData\SubmitterRegulatorElementTypeMetaData.cs" />
<Compile Include="MetaData\SubmitterRegulatorInfoMetaData.cs" />
<Compile Include="MetaData\UstCertInstallModMetaData.cs" />
<Compile Include="MetaData\UstFacilityInformationMetaData.cs" />
<Compile Include="MetaData\UstMonitoringPlanMetaData.cs" />
<Compile Include="MetaData\UstTankMetaData.cs" />
<Compile Include="MetaData\ViolationMetaData.cs" />
<Compile Include="ModelVerifierProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Entities\Regulator.cs" />
<Compile Include="Entities\RmrActivitiesReport.cs" />
<Compile Include="Entities\RmrRecyclableMaterial.cs" />
<Compile Include="Entities\RwConsolidationSite.cs" />
<Compile Include="Entities\SubmittalElement.cs" />
<Compile Include="Entities\SubmittalStatusType.cs" />
<Compile Include="Entities\SubmittalTransaction.cs" />
<Compile Include="Entities\Submitter.cs" />
<Compile Include="Entities\SubmitterRegulatorElementType.cs" />
<Compile Include="Entities\SubmitterRegulatorInfo.cs" />
<Compile Include="Entities\UstCertInstallMod.cs" />
<Compile Include="Entities\UstFacilityInformation.cs" />
<Compile Include="Entities\UstMonitoringPlan.cs" />
<Compile Include="Entities\UstTank.cs" />
<Compile Include="Entities\Violation.cs" />
<Compile Include="TempSeedSelection.cs" />
</ItemGroup>
<ItemGroup>
<EntityDeploy Include="CIWModel.edmx">
<EntityManagerName>.CIWEntities</EntityManagerName>
<CodeGenNamespace>__default__</CodeGenNamespace>
</EntityDeploy>
</ItemGroup>
<ItemGroup>
<None Include="App.Config" />
<None Include="CIWModel.edmx.ReadMe">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>CIWModel.edmx.tt</DependentUpon>
</None>
<None Include="CIWModel.edmx.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<TemplateName>DomainModelTemplate</TemplateName>
<LastGenOutput>CIWModel.edmx.ReadMe</LastGenOutput>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Common\Decade.Common\Decade.Common.DataAnnotations\Decade.Common.DataAnnotations.csproj">
<Project>{B821E9FB-0E2D-4120-A3D6-AB959B31746E}</Project>
<Name>Decade.Common.DataAnnotations</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Scripts\CERS_Install.sql" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
That's even better :)

Ok .. next thing to try is to enable the 'Copy referenced assemblies to workspace' NCrunch configuration setting for ALL the projects in your solution. My suspicion is that PostSharp may be running but is unable to process all the build outputs because they are in locations that are different to what is expected.
Remco wrote:That's even better :)

Ok .. next thing to try is to enable the 'Copy referenced assemblies to workspace' NCrunch configuration setting for ALL the projects in your solution. My suspicion is that PostSharp may be running but is unable to process all the build outputs because they are in locations that are different to what is expected.


same error with that setting on true for all projects in the solution (would be nice to have a setting to change them all at once, I have a lot of projects)

thanks.
Sorry, the configuration pane does support changing settings via multi-selection, though this isn't very obvious.

I've just set up a basic postsharp 2.1 solution running under NCrunch and there didn't seem to be any special configuration needed in order for it to work. This suggests to me that the problem you're experiencing is somehow specific to your configuration and/or the aspects you're introducing to the code.

I think the next step would be to establish whether the failure is occurring during build or run time. Postsharp works by executing specific steps during the build process, so I suggest that we take a look at the build output for the project you're experiencing problems with and check to see whether these tasks are being run. You can do this by going to your 'All solutions' NCrunch configuration and setting the 'Log verbosity' to 'detailed'. If you then click the reset button (or enable/disable) and wait for your solution to run, you should be able to obtain a full trace of the build output by selecting the problematic project inside the processing queue and looking through the details in the lower pane.

Do you see any steps being executed for postsharp? Or any errors that look suspect?
Remco wrote:Sorry, the configuration pane does support changing settings via multi-selection, though this isn't very obvious.

I've just set up a basic postsharp 2.1 solution running under NCrunch and there didn't seem to be any special configuration needed in order for it to work. This suggests to me that the problem you're experiencing is somehow specific to your configuration and/or the aspects you're introducing to the code.

I think the next step would be to establish whether the failure is occurring during build or run time. Postsharp works by executing specific steps during the build process, so I suggest that we take a look at the build output for the project you're experiencing problems with and check to see whether these tasks are being run. You can do this by going to your 'All solutions' NCrunch configuration and setting the 'Log verbosity' to 'detailed'. If you then click the reset button (or enable/disable) and wait for your solution to run, you should be able to obtain a full trace of the build output by selecting the problematic project inside the processing queue and looking through the details in the lower pane.

Do you see any steps being executed for postsharp? Or any errors that look suspect?



Looking through the details pane after a reset I only see this for each failed test. I dont see any activity at the project level (lower pane is empty).


System.ArgumentException: Unable to get metadata for Decade.CIW.Model.HwUnit. Make sure it is a valid entity type or POCO type with a KeyAttribute
at IdeaBlade.EntityModel.EntityMetadataStore.GetEntityMetadata(Type entityType, Boolean canThrowException)
at IdeaBlade.EntityModel.EntityAspect.get_EntityGroup()
at IdeaBlade.EntityModel.EntityAspect.IdeaBlade.EntityModel.IStructuralObject.get_EntityGroup()
at IdeaBlade.EntityModel.DataEntityProperty`2.SetValue(TInstance instance, TValue value)
at Decade.CIW.Model.HwUnit.set_NumberOfTanks(Nullable`1 value) in c:\DevServer\Corsair\Applications\CERSIntegrationWizard\Decade.CIW.Model\CIWModel.IB.Designer.cs:line 3936#0
at Decade.CIW.Connectors.Envision4.Tests.MappingServiceTest.MapHwUnit_WhenCalled_UpdatesECHazwasteUnit() in c:\DevServer\Corsair\Applications\CERSIntegrationWizard\Decade.CIW.Connectors.Envision4.Tests\UnitTests\MappingServiceTest.cs:line 647#1
If you set your 'Log verbosity' under your NCrunch configuration to 'Detailed' then click the Reset button, the processing queue should start showing large amounts of trace information in the details pane when you click on any of the tasks listed. Do you see any output from postsharp against the build tasks?
Remco wrote:If you set your 'Log verbosity' under your NCrunch configuration to 'Detailed' then click the Reset button, the processing queue should start showing large amounts of trace information in the details pane when you click on any of the tasks listed. Do you see any output from postsharp against the build tasks?


I did not see any more details in the detail pain than what I posted. I did turn on the property that uses the output window.

Here are some sample entries that contain post sharp.

[08:00:50.7318-Core-26] Build analysis output: Considered "C:\Program Files (x86)\PostSharp 2.1\Reference Assemblies\.NET Framework 2.0\DevExpress.Xpf.Carousel.v11.2.Customization.dll", but it didn't exist.

Using this version instead of original version "2.0.0.0" in "C:\Program Files (x86)\PostSharp 2.1\Reference Assemblies\.NET Framework 2.0\PostSharp.dll" because there is a more recent version of this framework file.

Dependency "PostSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7".
[08:00:52.2958-Core-26] Build analysis output: Resolved file path is "C:\Program Files (x86)\PostSharp 2.1\Reference Assemblies\.NET Framework 2.0\PostSharp.dll".
[08:00:52.2958-Core-26] Build analysis output: Reference found at search path location "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}".
[08:00:52.2958-Core-26] Build analysis output: For SearchPath "c:\DevServer\Corsair\Applications\CERSIntegrationWizard\packages\Decade.Ideablade.All.6.1.7\lib\net".
[08:00:52.2958-Core-26] Build analysis output: Considered "c:\DevServer\Corsair\Applications\CERSIntegrationWizard\packages\Decade.Ideablade.All.6.1.7\lib\net\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "c:\DevServer\Corsair\Applications\CERSIntegrationWizard\packages\Decade.Ideablade.All.6.1.7\lib\net\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: For SearchPath "{TargetFrameworkDirectory}".
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: For SearchPath "{Registry:Software\Microsoft\.NETFramework,v4.0,AssemblyFoldersEx}".
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\framework\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\NUnit 2.5.3\bin\net-2.0\framework\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\framework\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v4.0\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v4.0\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\Common Files\microsoft shared\VSTT\10.0\UITestExtensionPackages\PostSharp.dll", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files (x86)\Common Files\microsoft shared\VSTT\10.0\UITestExtensionPackages\PostSharp.exe", but it didn't exist.
[08:00:52.2958-Core-26] Build analysis output: Considered "C:\Program Files\Reference Assemblies\Microsoft\VSTO40\v4.0.Framework\PostSharp.dll", but it didn't exist.


[08:00:52.2958-Core-26] Build analysis output: #ReferenceDependencyPaths=;C:\Program Files (x86)\PostSharp 2.1\Reference Assemblies\.NET Framework 2.0\PostSharp.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.ServiceModel.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Management.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Transactions.dll;C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.Entity.Design.dll



Ok - based on your description it seems like the postsharp build steps just aren't firing. We need to find out why. Can you tell me any more about how your PostSharp environment is configured? If there's any way you can reconstruct the issue in a small throw-away project that you can share, this will be very helpful as I may be able to recreate it and help more with troubleshooting.
Remco wrote:Ok - based on your description it seems like the postsharp build steps just aren't firing. We need to find out why. Can you tell me any more about how your PostSharp environment is configured? If there's any way you can reconstruct the issue in a small throw-away project that you can share, this will be very helpful as I may be able to recreate it and help more with troubleshooting.


I have a sample project that is similar to my main app. I just added a test project and a dummy test that is failing exactly the same as my main app. It is zipped up and ready to send. Just tell me how you want it delivered.

Thanks!

Post a reply

Log in to reply.