Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error...
upper
#1 Posted : Monday, February 1, 2021 11:02:11 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
Today we added a SuppressMessage to method and a using: using System.Diagnostics.CodeAnalysis;

And as soon as I add the using ncrunch starts to failing running the tests with this error: NCrunch was unable to retrieve a meaningful result from this test due to an unexpected error - was the execution process terminated?

When I remove this using and add the SuppressMessage like this [System.Diagnostics.CodeAnalysis.SuppressMessage] Ncrunch is working fine --> however I can't do this becaue we have code cleanup enabled that will create the using again.

It's a .net 5.0 solution and the same error occurrs with this version NCrunch_VS2019_4.7.0.3.msi

At the moment we can't reproduce it in a sample project, we only have a more detailed log from nCrunch, I know it's not much, any idea how I can provide you more information?
https://drive.google.com...Ob6eSi/view?usp=sharing

Here is the class
Code:

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

using Upper.PrintProcessingManager.Domain.DataProvider;
using Upper.PrintProcessingManager.Domain.Excel.Print;
using Upper.PrintProcessingManager.Domain.Gateways;
using Upper.PrintProcessingManager.Domain.Gateways.MediaManager;
using Upper.PrintProcessingManager.Domain.Services.DocumentGeneration.Calculator;

namespace Upper.PrintProcessingManager.Domain.Services.DocumentGeneration.ExcelDataGeneration
{
    public class PackageDetailsPrintDeliveryDataGenerator
    {
        private readonly ICirculationAmountCalculator _circulationAmountCalculator;
        private readonly ITranslationService _translationService;

        public PackageDetailsPrintDeliveryDataGenerator(ICirculationAmountCalculator circulationAmountCalculator, ITranslationService translationService)
        {
            _circulationAmountCalculator = circulationAmountCalculator;
            _translationService = translationService;
        }

        [SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "not nullable")]
        public PackageDetailsPrintDelivery GeneratePrintDeliveryData(PrintDeliveryProjectDetail projectDetail, DateTime createdAt, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            return new(createdAt, projectDetail.PrintingCompany, CreatePublications(projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
        }

        private IReadOnlyCollection<PrintDeliveryPublication> CreatePublications(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            return packageVersions
                .Where(packageVersion => packageVersion.BranchPublications.Any(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId))
                .GroupBy(key => key.BranchPublications.Single(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId).PublicationShortName)
                .Select(group => CreatePublication(group.Key, projectDetail, group.ToList(), branches, distributionCirculations, houseCirculations))
                .OrderBy(publication => publication.PublicationShortName)
                .ToList();
        }

        private PrintDeliveryPublication CreatePublication(string publicationShortName, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            return new(publicationShortName, CreateProjectName(projectDetail.ProjectName, publicationShortName), 0, CreateRecipientTypes(projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
        }

        private IReadOnlyCollection<PrintDeliveryRecipientType> CreateRecipientTypes(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            List<PrintDeliveryRecipientType> printDeliveryRecipientTypes = new();

            IReadOnlyCollection<PackageVersion> packagedDeliveries = packageVersions
                .Where(packageVersion => packageVersion.BranchPublications.Count > 1)
                .ToList();
            if (packagedDeliveries.Any())
            {
                printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.PrintProcessor, projectDetail, packagedDeliveries, branches, distributionCirculations, houseCirculations));
            }

            IReadOnlyCollection<PackageVersion> soloDeliveries = packageVersions
                .Where(packageVersion => packageVersion.BranchPublications.Count == 1)
                .ToList();
            if (soloDeliveries.Any())
            {
                printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.Distributor, projectDetail, soloDeliveries, branches, distributionCirculations, houseCirculations));
            }

            if (packageVersions.Any())
            {
                printDeliveryRecipientTypes.Add(CreateRecipientType(RecipientType.Branch, projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
            }


            return printDeliveryRecipientTypes;
        }


        private PrintDeliveryRecipientType CreateRecipientType(RecipientType recipientType, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            return new(recipientType, CreateBranches(recipientType, projectDetail, packageVersions, branches, distributionCirculations, houseCirculations));
        }

        private IReadOnlyCollection<PrintDeliveryBranch> CreateBranches(RecipientType recipientType, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            return packageVersions.GroupBy(
                    packageVersion => new
                    {
                        packageVersion.BranchPublications.Single(BranchPublication => projectDetail.ExternalProjectId == BranchPublication.ProjectId).BranchId,
                        packageVersion.CountryId
                    })
                .Select(branchGroup => CreateBranch(recipientType, branchGroup.Key.BranchId, branchGroup.Key.CountryId, projectDetail, branchGroup.ToList(), branches, distributionCirculations, houseCirculations))
                .OrderBy(branch => branch.BranchName)
                .ThenBy(branch => branch.TargetCountryId)
                .ToList();
        }

        private PrintDeliveryBranch CreateBranch(RecipientType recipientType, string branchId, string countryId, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<Branch> branches, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            IReadOnlyCollection<PrintDeliveryDistributionInformation> printDeliveryDistributionInformation = recipientType switch
            {
                RecipientType.Distributor => CreateGroupedSoloDistributionInformation(projectDetail, packageVersions, distributionCirculations),
                RecipientType.PrintProcessor => CreateGroupedPackagedDistributionInformation(projectDetail, packageVersions, distributionCirculations),
                RecipientType.Branch => CreateHouseCirculationDistributionInformation(branchId, countryId, projectDetail, packageVersions, houseCirculations),
                _ => throw new ArgumentOutOfRangeException(nameof(recipientType))
            };
            return new PrintDeliveryBranch(branches.Single(branch => branch.BranchId == branchId).Name, countryId, printDeliveryDistributionInformation);
        }

        private static IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateHouseCirculationDistributionInformation(string branchId, string countryId, PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<HouseCirculation> houseCirculations)
        {
            DateTime earliestToDistributorDate = packageVersions
                .Select(packageVersion => GetDistributionScenario(projectDetail, packageVersion))
                .Min(distributionScenario => distributionScenario.ToDistributorDate);


            int amount = houseCirculations.Single(houseCirculation => houseCirculation.BranchId == branchId
                                                                      && houseCirculation.CountryId == countryId
                                                                      && houseCirculation.ProjectId == projectDetail.ExternalProjectId)
                .Amount;

            return new[]
                   {
                       new PrintDeliveryDistributionInformation(amount, ExcelDataGenerationResource.HouseCirculationFixedName, null, earliestToDistributorDate, null, null)
                   };
        }

        private IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateGroupedSoloDistributionInformation(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculations)
        {
            return packageVersions.GroupBy(packageVersion =>
                                           {
                                               TourCirculationDetail tourCirculationDetail = distributionCirculations.Single(distributionCirculation => distributionCirculation.DistributionSet.Id == packageVersion.DistributionSetId)
                                                   .DistributorCirculationDetails.Single(distributor => distributor.DistributorId == packageVersion.DistributorId)
                                                   .TourCirculationDetails.Single(tour => tour.TourId == packageVersion.TourId);
                                               return new
                                               {
                                                   packageVersion.DistributorId,
                                                   packageVersion.DistributorName,
                                                   GetDistributionScenario(projectDetail, packageVersion)
                                                              .ToDistributorDate,
                                                   tourCirculationDetail
                                                              .DeliveryAddress,
                                                   tourCirculationDetail
                                                              .PackagingShortname
                                               };
                                           })
                .Select(group => CreateToDistributorDistributionInformation(group.Key.DistributorName, group.Key.ToDistributorDate, group.Key.DeliveryAddress, group.Key.PackagingShortname, group.ToList(), distributionCirculations))
                .ToList();
        }


        private IReadOnlyCollection<PrintDeliveryDistributionInformation> CreateGroupedPackagedDistributionInformation(PrintDeliveryProjectDetail projectDetail, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
        {
            return packageVersions.GroupBy(packageVersion =>
                                           {
                                               PrintDeliveryDistributionScenario distributionScenario = GetDistributionScenario(projectDetail, packageVersion);
                                               return new
                                               {
                                                   distributionScenario.ToPrintProcessorDate,
                                                   distributionScenario.PrintProcessorName
                                               };
                                           })
                .Select(group => CreateToPrintProcessorDistributionInformation(group.Key.PrintProcessorName, group.Key.ToPrintProcessorDate, group.ToList(), distributionCirculationCollectionResults))
                .ToList();
        }

        private PrintDeliveryDistributionInformation CreateToDistributorDistributionInformation(string distributorName, DateTime toDistributorDate, DeliveryAddress deliveryAddress, string packagingShortname, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
        {
            PrintDeliveryAddress address = new(deliveryAddress.Name,
                deliveryAddress.AdditionalInformation,
                deliveryAddress.CountryId,
                deliveryAddress.ZipCode,
                deliveryAddress.City,
                deliveryAddress.Street,
                _translationService.TranslatePackaging(packagingShortname));
            int amount = _circulationAmountCalculator.GetTourCirculationAmount(packageVersions, distributionCirculationCollectionResults);
            return new PrintDeliveryDistributionInformation(amount, distributorName, null, toDistributorDate, "", address);
        }

        private PrintDeliveryDistributionInformation CreateToPrintProcessorDistributionInformation(string printProcessorName, DateTime toPrintProcessorDate, IReadOnlyCollection<PackageVersion> packageVersions, IReadOnlyCollection<DistributionCirculationCollectionResult> distributionCirculationCollectionResults)
        {
            int amount = _circulationAmountCalculator.GetTourCirculationAmount(packageVersions, distributionCirculationCollectionResults);
            return new PrintDeliveryDistributionInformation(amount, printProcessorName, toPrintProcessorDate, null, null, null);
        }

        private static PrintDeliveryDistributionScenario GetDistributionScenario(PrintDeliveryProjectDetail projectDetail, PackageVersion packageVersion)
        {
            return projectDetail.DistributionScenarios
                .Single(scenario => scenario.ExternalX3ScenarioId == packageVersion.BranchPublications
                            .Single(branchPublication => branchPublication.ProjectId == projectDetail.ExternalProjectId)
                            .ExternalX3DistributionScenarioId);
        }

        private static string CreateProjectName(string projectName, string publicationShortname)
        {
            return $"{projectName} ({publicationShortname})";
        }
    }
}
upper
#2 Posted : Monday, February 1, 2021 11:10:48 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
I can't edit my own topic, sorry, therefore I post an additional info here:


Now matter what code we add to this specific class or to any class in this project, NCrunch fails (R# test runner and VS test runner are working).
When I remove this new class everything is working fine --> I also submitted a bug report.

When I try to debug an affected test with NCrunch it shows the following error:

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.' -->

C:\Temp\NCrunch\22172\60\StreuplanManager\Src\PPMS\v\1.00\Upper.PrintProcessingManager.Audit.Test\bin\Debug\nCrunch.TestRuntime.DotNetCore.dll

Here is the dll hat NCrunch created:
https://drive.google.com...rJ5xfh/view?usp=sharing

It seems that when we place the parameter of the method
public PackageDetailsPrintDelivery GeneratePrintDeliveryData(....) in different lines NCrunch starts to working fine --> it seems that NCrunch is creating a "wrong" dll file.

Can I help you to find the reason?

At least it helps if we add the parameter in separate lines --> but I think that's just a workaround.
Remco
#3 Posted : Monday, February 1, 2021 12:01:36 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,319

Thanks: 819 times
Was thanked: 1096 time(s) in 1039 post(s)
Hi, thanks for sharing this issue. Can you try the following and let me know if you see any difference here?

- Try placing the SuppressMessage attribute declaration inside an '#if !NCRUNCH' block. Does this allow NCrunch and the code cleanup to both work?
- Can you try turning off the 'Instrument Output Assembly' setting for all the projects in your solution?
- Can you check the contents of this troubleshooting page to see if any of the suggestions apply in your situation?
- Can you set NCrunch in compatibility mode to see if this makes any difference?
upper
#4 Posted : Monday, February 1, 2021 12:05:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
Remco;15292 wrote:
Hi, thanks for sharing this issue. Can you try the following and let me know if you see any difference here?

- Try placing the SuppressMessage attribute declaration inside an '#if !NCRUNCH' block. Does this allow NCrunch and the code cleanup to both work?
- Can you try turning off the 'Instrument Output Assembly' setting for all the projects in your solution?
- Can you check the contents of this troubleshooting page to see if any of the suggestions apply in your situation?
- Can you set NCrunch in compatibility mode to see if this makes any difference?


sorry for the confusion, that's the reason

It seems that when we place the parameter of the method
public PackageDetailsPrintDelivery GeneratePrintDeliveryData(....) in different lines NCrunch starts to working fine --> it seems that NCrunch is creating a "wrong" dll file.



so just adding a break after the first parameter works, no matter if the SuppressMessage attribute is available or not.


Here is the dll that NCrunch created:
https://drive.google.com...rJ5xfh/view?usp=sharing
upper
#5 Posted : Monday, February 1, 2021 12:13:07 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
Setting the Instrument Output Assembly for the project file where the file exists to false also works --> even if we don't put the parameter of the method in a separate line --> so it seems there is a bug, maybe the lenght of the parameters are too long?

What do you think?

br
Remco
#6 Posted : Monday, February 1, 2021 10:57:05 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,319

Thanks: 819 times
Was thanked: 1096 time(s) in 1039 post(s)
This may be an instrumentation problem. If you turn on the 'Instrument Output Assembly' setting and set the 'Instrumentation Strategy' setting to 'Legacy', does this also resolve the problem consistently?

I get suspicious when I hear about something that works when only text based changes are made in code (i.e. splitting a method signature across multiple lines). This is because we don't actually process the code at text level, we only work with the compiled assemblies .. and moving text around shouldn't change this. Such a situation suggests this problem may simply be heavily intermittent and dependent on memory allocation patterns within the runtime.
upper
#7 Posted : Tuesday, February 2, 2021 6:18:08 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
Remco;15296 wrote:
This may be an instrumentation problem. If you turn on the 'Instrument Output Assembly' setting and set the 'Instrumentation Strategy' setting to 'Legacy', does this also resolve the problem consistently?

I get suspicious when I hear about something that works when only text based changes are made in code (i.e. splitting a method signature across multiple lines). This is because we don't actually process the code at text level, we only work with the compiled assemblies .. and moving text around shouldn't change this. Such a situation suggests this problem may simply be heavily intermittent and dependent on memory allocation patterns within the runtime.


Do you mean 'Instrumentation Mode'?

I turned on 'Instrument Output Assembly' and set 'Instrumentation Mode' to 'Legacy' but that does not solve the problem.

Only turning off 'Instrument Output Assembly' or turning it on and move at least on parameter to the next line solves the problem.

What's also interesting is, that all the tests fail (even from other assemblies) when this issue occurs.
Remco
#8 Posted : Tuesday, February 2, 2021 11:45:21 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,319

Thanks: 819 times
Was thanked: 1096 time(s) in 1039 post(s)
1 user thanked Remco for this useful post.
upper on 2/4/2021(UTC)
upper
#9 Posted : Wednesday, February 3, 2021 3:55:54 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
I will try it tomorrow and report back, thx.
upper
#10 Posted : Thursday, February 4, 2021 7:55:42 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/21/2016(UTC)
Posts: 31
Location: Austria

Thanks: 8 times
Was thanked: 8 time(s) in 7 post(s)
upper;15301 wrote:
I will try it tomorrow and report back, thx.


I just tried your fix and I can confirm that it's now working again (even without placing the parameter in a new line).

Thank you very much.
1 user thanked upper for this useful post.
Remco on 2/4/2021(UTC)
Tonyh
#11 Posted : Sunday, February 14, 2021 6:03:45 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/10/2017(UTC)
Posts: 5
Location: Australia

Also having the same result, but with a different cause in a .net 5 solution. Also tests run in R# OK

When try to run tests in debug mode get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." message.

The problem is caused by deleting the following property from an interface.
public interface ISWCalendarData
{
// TODO consider private, readonly
public string DataApi { get; set; }
.........
Remco
#12 Posted : Sunday, February 14, 2021 6:15:41 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,319

Thanks: 819 times
Was thanked: 1096 time(s) in 1039 post(s)
Tonyh;15323 wrote:
Also having the same result, but with a different cause in a .net 5 solution. Also tests run in R# OK

When try to run tests in debug mode get "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." message.



Can you confirm whether the build posted above solves this issue for you?
Tonyh
#13 Posted : Sunday, February 14, 2021 6:19:32 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/10/2017(UTC)
Posts: 5
Location: Australia

Hi Remco,
I wondered if it might, but thought it wise to see if you thought it was worth trying.
Will try tomorrow and report back.
Tonyh
#14 Posted : Sunday, February 14, 2021 11:19:58 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/10/2017(UTC)
Posts: 5
Location: Australia

Thanks Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.092 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download