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

Notification

Icon
Error

Build failed on Projects with unsafe code
jerry_chen
#1 Posted : Wednesday, August 5, 2015 5:50:58 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/5/2015(UTC)
Posts: 3
Location: Taiwan

Thanks: 1 times
I tried to build a project with unsafe code but failed, below is the error message.

ImageDllAccessor is an unsafe class (public unsafe class ImageDllAccessor).
The project can be build by Visual Studio 2013 without problem.

Can anyone help me about this issue? Thanks!

[13:41:20.6545-LocalBuildTask-11] ERROR (Build): CSharpDllMgr: (0): System.Exception: Unable to add type: CSharpDllMgr.ImageDllAccessor due to exception: System.NotSupportedException: Ptr
於 _Mono.Cecil.SignatureWriter.WritePrimitiveValue(ElementType type, Object value)
於 _Mono.Cecil.MetadataBuilder.GetConstantSignature(ElementType type, Object value)
於 _Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
於 _Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
於 _Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
於 _Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
於 _Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
於 _Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
於 _Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
於 _Mono.Cecil.MetadataBuilder.AddTypeDefs()
於 _Mono.Cecil.MetadataBuilder.BuildTypes()
於 _Mono.Cecil.MetadataBuilder.BuildModule()
於 _Mono.Cecil.ModuleWriter.<BuildMetadata>b__0(MetadataBuilder builder, MetadataReader _)
於 _Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
於 _Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
於 _Mono.Cecil.ModuleWriter.WriteModuleTo(ModuleDefinition module, Stream stream, WriterParameters parameters)
於 _Mono.Cecil.ModuleDefinition.Write(Stream stream, WriterParameters parameters)
於 _Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
於 nCrunch.Compiler.StaticManipulation.BuiltAssembly..()
於 nCrunch.Compiler.StaticManipulation.BuiltAssembly.(Action )
於 nCrunch.Compiler.StaticManipulation.BuiltAssembly.Instrument(ComponentSourceLineMap sourceLineMap, IDictionary`2 instrumentationDirectivesByCodeFileId, IDictionary`2 codeFileIDsByFilePath, Boolean proxyProcessIsActive, Int32 componentId, IInstrumentationFilter[] instrumentationFilters)
於 nCrunch.Compiler.RemoteBuildRunner.(ComponentBuildParameters , FilePath , BuildOutput , DirectoryPath[] , FilePath[] )
於 nCrunch.Compiler.RemoteBuildRunner.Build(ComponentBuildParameters parameters)
Remco
#2 Posted : Wednesday, August 5, 2015 5:57:08 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Thanks for sharing this issue.

This problem is caused by an incompatibility in NCrunch's instrumentation. Somehow (likely through unsafe code) you've managed to find an IL configuration that NCrunch isn't able to handle. It's often difficult to be sure, but it looks like it may be related to the parameters of one of the methods on this particular type.

Is there any code you can share with me that can reproduce this issue? If I can get it to occur within the NCrunch dev environment, I may be able to introduce a fix.

It should be possible to work around the problem by setting the 'Instrument output assembly' NCrunch project-level configuration setting for this project to 'False'.
jerry_chen
#3 Posted : Wednesday, August 5, 2015 6:45:58 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/5/2015(UTC)
Posts: 3
Location: Taiwan

Thanks: 1 times
Thanks for your reply.
I found the problem is "optional pointer argument" as below.

public unsafe class ImageDllAccessor
{
public void Function(byte* pExcludeCADMask = null)
{

}
}

If I changed the function parameter to "Function(byte* pExcludeCADMask)" NCrunch can work without problem.
Remco
#4 Posted : Wednesday, August 5, 2015 9:42:09 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Nice work. This consistently reproduces the issue.

I'll see what I can do about a fix. I'll get back to you soon.
Remco
#5 Posted : Monday, August 10, 2015 7:54:21 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Sorry to keep you waiting on this, but a fix for this issue is now available in the just released v2.16 - http://www.ncrunch.net/download.
1 user thanked Remco for this useful post.
jerry_chen on 8/12/2015(UTC)
jerry_chen
#6 Posted : Wednesday, August 12, 2015 4:04:08 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/5/2015(UTC)
Posts: 3
Location: Taiwan

Thanks: 1 times
Thanks a lot for the quick fix.
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.042 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download