Build/Test Issues

Build failed on Projects with unsafe code

Started by jerry_chen on 7,774 views

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)
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'.
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.
Nice work. This consistently reproduces the issue.

I'll see what I can do about a fix. I'll get back to you soon.
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.
Thanks a lot for the quick fix.

Post a reply

Log in to reply.