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

Notification

Icon
Error

NCrunch not happy with unsafe code
kestral
#1 Posted : Sunday, December 30, 2018 2:45:04 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2018(UTC)
Posts: 2
Location: Australia

Thanks: 1 times
If I have a method as below that demonstrates my problem.

Code:
        public static void Junk()
        {
            unsafe
            {
            }
        }


NCrunch has a build failure. It has the following message.

Quote:
Libraries\NumKeys.cs (157, 13): Unsafe code may only appear if compiling with /unsafe


WARNING - ..\..\..\..\program files (x86)\microsoft visual studio\2017\professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets (2110, 5): MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Users\andrewc\AppData\Local\NCrunch\18788\24\_ncrunchreferences\FairCom.IsamMtc.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.


All my projects in this solution have "allow unsafe code" checked and compile ok without NCrunch. I'm currently getting past this by wrapping the unsafe code with #if !NCRUNCH/#endif which allows it to compile, but obviously prevents me from being able to test the code.

In the NCrunch configuration, I have the "Use CPU architecture" set to "x86".

Is there some way to allow this to build with NCrunch enabled so I'm able to run tests against it ?
Remco
#2 Posted : Sunday, December 30, 2018 11:26:31 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,671

Thanks: 737 times
Was thanked: 944 time(s) in 899 post(s)
Hi, thanks for posting!

Can you tell me a bit more about the templates used for these projects? My guess is that something in the project XML is causing NCrunch to exclude the declaration for unsafe code. If you can share the XML (or at least the top part of it), I might be able to help narrow this down.

NCrunch definitely has no problems with unsafe code. We test quite thoroughly in this area :)

Edit: I've just re-read the warning the compiler gave you, and I'm fairly certain you're suffering from a derivative of this problem. Make sure the 'Use Build Platform' and 'Use Build Configuration' settings are aligned with your project file, or that the project file default platform and configuration contains the unsafe code declaration. I think it's unlikely you'll be able to build this project outside Visual Studio (even without NCrunch).
1 user thanked Remco for this useful post.
kestral on 12/31/2018(UTC)
kestral
#3 Posted : Monday, December 31, 2018 7:06:30 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/30/2018(UTC)
Posts: 2
Location: Australia

Thanks: 1 times
Thanks for that info.

I went through and set all the Configuration and Platform to Any CPU and it's all working now. Still not sure where I had a mixup on the x86 version but if I need it again I'll look through the same options.
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.027 seconds.