非管理导出:无法编译程序集 [英] Unmanaged Exports: Cannot compile assembly

查看:168
本文介绍了非管理导出:无法编译程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个可以从非托管代码访问的.NET程序集(Delphi 5)。

I want to create a .NET assembly that can be accessed from unmanaged code (Delphi 5).

我发现非管理导出,并遵循其中的步骤,但是我无法成功编译甚至基本示例:

I have found Unmanaged Exports and followed the steps there but I am unable to successfuly compile even the basic example:

using RGiesecke.DllExport;

namespace DelphiNET
{
    public class Class1
    {
        [DllExport("add")]
        public static int Add(int left, int right)
        {
            return left + right;
        }
    }
}

DelphiNET.csproj 项目文件:

...
<ItemGroup>
  <Compile Include="Class1.cs" />
  <Compile Include="DllExport\DllExportAttribute.cs" />
  <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="DllExport\RGiesecke.DllExport.targets" />
...

这是错误:

------ Build started: Project: DelphiNET, Configuration: Release Any CPU ------
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:TRACE /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\DelphiNET.dll /target:library Class1.cs DllExport\DllExportAttribute.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
DelphiNET -> C:\DelphiNET\bin\Release\DelphiNET.dll
ILDasm: calling 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe' with /quoteallnames /nobar "/out:C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.il" "C:\DelphiNET\bin\Release\DelphiNET.dll"
C:\DelphiNET\bin\Release\DelphiNET.dll : warning EXP0009: Platform is AnyCpu, generating creating binaries for each CPU platform in a separate folder...
ILAsm: calling 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ILAsm.exe' with /nologo "/out:C:\DelphiNET\bin\Release\x86\DelphiNET.dll" "C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.x86.il" /DLL "/resource=C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.res"  /optimize  
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : 
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembling 'C:\Documents and Settings\Lukas\Local Settings\Temp\tmp29F\DelphiNET.x86.il'  to DLL --> 'C:\DelphiNET\bin\Release\x86\DelphiNET.dll'
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Source file is ANSI
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : 
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::.ctor
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::.ctor
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::.ctor
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::get_CallingConvention
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::set_CallingConvention
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::get_ExportName
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : Assembled method RGiesecke.DllExport.DllExportAttribute::set_ExportName
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : 
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : ***** FAILURE ***** 
C:\DelphiNET\DllExport\RGiesecke.DllExport.targets(8,5): error : 
Done building project "DelphiNET.csproj" -- FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

操作系统:WinXPSP3,Microsoft Visual C#2008 Express Edition SP1,.NET 3.5 SP1

OS: WinXPSP3, Microsoft Visual C# 2008 Express Edition with SP1, .NET 3.5 SP1

任何想法怎么了?谢谢。

Any idea what's wrong? Thanks.

编辑23:40:

我发现了这个bug。它的功能是 - 添加添加的名称也是一样的。当您更改其中一个时,它可以正常工作。

I have found the bug. It is in the name of the function - add and Add are too same. When you change one of them, it works.

推荐答案


当您采取时,您甚至可以为您准备好这个

这是一个项目模板,可以设置所有内容,应该能正常工作。

It's a project template that sets everything up and should work just fine.

我在以前的版本中找到了一些观点,在那里我做了一些并不总是如此的假设。
我以前实现的一个潜在问题是用于发布配置的/ optimize开关。在这种情况下,ILAsm会阻止IL,因为我没有看到新版本。

I did find some points in the previous version, where I made some assumptions that weren't always true. And one potential problem with my previous implementation was the /optimize switch which is used for release configurations. Sometimes ILAsm would choke on the IL in that case, I haven't seen that with the new version.

这篇关于非管理导出:无法编译程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆