Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target platform detection failure bug #34

Closed
OmegaExtern opened this issue May 4, 2017 · 5 comments
Closed

Target platform detection failure bug #34

OmegaExtern opened this issue May 4, 2017 · 5 comments
Milestone

Comments

@OmegaExtern
Copy link

I have discovered a bug in DllExport (v1.5.2), it breaks the compilation with the following error:

The "DllExportAppDomainIsolatedTask" task failed unexpectedly.
System.ArgumentException: Unknown cpu platform 'MyCustomPlatform'.
Parameter name: platformTarget

Server stack trace: 
   at RGiesecke.DllExport.Utilities.ToCpuPlatform(String platformTarget) in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport\Utilities.cs:line 76
   at RGiesecke.DllExport.MSBuild.ExportTaskImplementation`1.Execute() in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport.MSBuild\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 414
   at RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask.Execute() in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport.MSBuild\RGiesecke.DllExport.MSBuild\DllExportAppDomainIsolatedTask.cs:line 397
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.Build.Framework.ITask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()	DllExport			

For easier reproducing of this issue, you can download VS2017 solution from here, and then try to build it:
DllExport-Platform-issue.zip

Please examine C# project file in the file attached above. You will see that PlatformTarget is set to x86, but $(Platform) is set to MyCustomPlatform.
The bug is that DllExport uses the incorrect value for detecting "target platform" value. As you can see, it obviously uses $(Platform) (MyCustomPlatform) instead of PlatformTarget (x86).
And here is the picture of that:
image

Please fix it :)

@3F
Copy link
Owner

3F commented May 5, 2017

It reproduces for me with original UnmanagedExports v1.2.7

the original code uses both properties $(Platform) & $(PlatformTarget)

temporarily, try to redefine this in your project files like:

<DllExportPlatform>$(PlatformTarget)</DllExportPlatform>

@OmegaExtern
Copy link
Author

It reproduces for me with original UnmanagedExports v1.2.7

Yes, confirmed, this issue also exists in UnmanagedExports package too.

I have tried redefining DllExportPlatform to $(PlatformTarget) in csproj file as you have said:

......
    <DllExportOurILAsm>false</DllExportOurILAsm>
    <DllExportPlatform>$(PlatformTarget)</DllExportPlatform>
  </PropertyGroup>
......

But still it fails:

1>------ Build started: Project: DllExport, Configuration: Debug MyCustomPlatform ------
1>  DllExport -> E:\platform-issue\DllExport\DllExport\bin\Debug\DllExport.dll
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: The "DllExportAppDomainIsolatedTask" task failed unexpectedly.
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: System.ArgumentException: Unknown cpu platform 'MyCustomPlatform'.
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: Parameter name: platformTarget
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: 
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: Server stack trace: 
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at RGiesecke.DllExport.Utilities.ToCpuPlatform(String platformTarget) in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport\Utilities.cs:line 76
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at RGiesecke.DllExport.MSBuild.ExportTaskImplementation`1.Execute() in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport.MSBuild\RGiesecke.DllExport.MSBuild\ExportTaskImplementation.cs:line 414
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at RGiesecke.DllExport.MSBuild.DllExportAppDomainIsolatedTask.Execute() in D:\prg\projects\DllExport\DllExport\RGiesecke.DllExport.MSBuild\RGiesecke.DllExport.MSBuild\DllExportAppDomainIsolatedTask.cs:line 397
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: 
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018: Exception rethrown at [0]: 
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at Microsoft.Build.Framework.ITask.Execute()
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>E:\platform-issue\DllExport\packages\DllExport.1.5.2\tools\net.r_eg.DllExport.targets(42,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@3F
Copy link
Owner

3F commented May 6, 2017

probably your $(DllExportPlatform) still is empty - Condition="'$(DllExportPlatform)' == ''"
that is, check a correct definition of the $(PlatformTarget) (it should be after first def, because the msbuild analyzer looks this from up to down as I remember) or again, try manually: x64, x86, Win32, ...

@3F 3F added this to the v1.5.3 milestone Jun 3, 2017
@qadeem-qureshi
Copy link

I cannot seem to get your solutions to the issue to work. I have attempted to switch the platformtarget to x64 manually and that did not work either.

3F added a commit that referenced this issue Jun 5, 2017
details in my comment to this issue
#34

+PUBLIC_RELEASE const for clarify build
@3F
Copy link
Owner

3F commented Jun 5, 2017

I'm watching that original code uses anycpu keyword to get value in order from:

  • DllExportPlatform -> DllExportCpuType -> DllExportPlatformTarget

So you can also use this to skip processing in any places instead of x64/x86 as I said above.

<PropertyGroup>
    ...
  <!-- 
  
    just to be clear, how msbuild will consider your xml: 
    
    For this case, msbuild lexer can't resolve $(PlatformTarget) because its nodes still does not contain this definition. 
        That is, DllExportPlatform contain unevaluated value $(PlatformTarget) as is, in resolved context. 
        After, engine will process this, and the evaluated value should be is empty because of empty reference to variable for this name.
        
    But 'anycpu' is a evaluated value (engine don't requires additional step for evaluating) 
    so you can freely use it in any places (before calling of our DllExportMod target of course :)) 
    to skip processing from this property in order as I said above.
    
  -->  
  <DllExportPlatform>AnyCPU</DllExportPlatform>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|MyCustomPlatform'">
  <PlatformTarget>AnyCPU</PlatformTarget>
  ...
</PropertyGroup>

Well, I leave DllExportCpuType but the DllExportPlatformTarget is removed now.

Please check latest build - https://ci.appveyor.com/project/3Fs/dllexport/build/build-44/artifacts

@3F 3F closed this as completed Jun 13, 2017
3F added a commit that referenced this issue Aug 12, 2017
* NEW: The new lightweight manager & distribution via MvsSln & GetNuTool projects. Issue #38.
       Based on hMSBuild logic and includes GetNuTool core.

       Now you shouldn't use standard nuget clients anymore:
       https://www.youtube.com/watch?v=okPThdWDZMM

       Package from nuget.org already contains this, but you can also get it directly.
       Latest version: https://raw.githubusercontent.com/3F/DllExport/latest/manager/DllExport.bat
       ~18 Kb text-based embeddable batch-scripts that does not require powershell and dotnet-cli.

       To install/uninstall or to reconfigure your projects: `DllExport -action Configure`
       To manually restore package: `DllExport -action Restore`
       All available features: `DllExport -h`

       Server by default - nuget.org

* NEW: The new Wizard (configurator via MvsSln). To easy configure your projects in any place. Issue #38.
       MvsSln v1.0.1.43422: https://github.com/3F/MvsSln

* NEW: Added support of global namespaces - Issue #47.
       Use `Direct-Mod` if Cecil will not process this correctly.

* FIXED: Fixed target platform detection. Issue #34.
         Details: #34 (comment)

* FIXED: Fixed problem when the Post-Build event is triggered before our tool. Issue #35.
         Use this if still is needed:
         ```
         <Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
            ...
         </Target>
         ```

* FIXED: Fixed generation of exp + .lib via MS Library Manager for VS2017. Issue #37.
         Now it also includes processing through VsDevCmd & VcVarsAll initializer scripts.
         Use the folowing msbuild properties to override values by default:
         * $(DllExportVcVarsAll); $(DllExportVsDevCmd)

* FIXED: Fixes possible problem with multiple properties that contains *Undefined* word,
         e.g.: *Undefined*\path1;C:\path2 ...

* CHANGED: Added information about finding lib tool. Issue #44.
* CHANGED: UI. Selected platform now affects to all configurations of project instead of active as before.
* CHANGED: Now, nuget package does not contain library in `lib/.../` Details in #36.
* CHANGED: Now, we also distribute .zip package for work through our manager etc.
           https://github.com/3F/DllExport/releases

           The latest text-based manager you can find here:
           https://raw.githubusercontent.com/3F/DllExport/latest/manager/DllExport.bat
           Illustration here: https://www.youtube.com/watch?v=okPThdWDZMM
3F added a commit that referenced this issue Dec 29, 2017
* NEW: The new embeddable lightweight manager for distribution via MvsSln & GetNuTool projects. Issue #38.
       Based on hMSBuild logic and includes GetNuTool core v1.6.1.

       Now you shouldn't use standard nuget clients anymore:
       https://www.youtube.com/watch?v=9bYgywZ9pPE

       Quick start: https://www.youtube.com/watch?v=sBWt-KdQtoc
        ==============================
        DllExport -action Configure
        ==============================

       Package from nuget.org already contains manager, but you can also get it directly.
       Latest manager: https://3F.github.io/DllExport/releases/latest/manager/
       ~18 Kb text-based embeddable batch-script that does not require powershell and dotnet-cli.

       Automatic restoring still is available but you can also use: `DllExport -action Restore`
       All available features: `DllExport -h`

       Direct links to remote package (without nuget server) via `-pkg-link {uri}` key. Issue #53.
       NuGet Server by default: nuget.org.

* NEW: The new Wizard (configurator via MvsSln). To easy configure your projects in any place. Part of Issue #38.
       MvsSln v2.0: https://github.com/3F/MvsSln

* NEW: Added support of empty/global namespaces - Issue #47.
       Use `Direct-Mod` if Cecil will not process this correctly.

* NEW: Implemented another storage for configuration: '.net.dllexport.targets'. Issue #49.

* NEW: New settings for configurator (Wizard):
        * Path to custom ILAsm.
        * Flag to keep intermediate Files (IL Code, Resources, ...).
        * Timeout of execution in milliseconds.

* NEW: Implemented automatic checking existence of a correct exported proc via Conari. Issue #55.
       Wizard controls it via `$(DllExportPeCheck)`:
        * 0x01 bit - Will check count of all planned exports from final PE32/PE32+ module.
        * 0x02 bit - Will check existence of all planned exports (IL code) in actual PE32/PE32+ module.

* NEW: Implemented PE32/PE32+ Viewer to check manually available exports from final modules. Issue #55.
       New key for manager:
        ```
        -pe-exp-list {module} - To list all available exports from PE32/PE32+ module.
        ```

        Sample:
        ```
        DllExport -pe-exp-list bin\Debug\regXwild.dll
        ```

* FIXED: Fixed target platform detection. Issue #34.
         Details: #34 (comment)

* FIXED: Fixed problem when the Post-Build event is triggered before our tool. Issue #35.
         Use this if still is needed:
         ```
         <Target Name="PostBuildEventBeforeDllExport" BeforeTargets="DllExportMod">
            ...
         </Target>
         ```

* FIXED: Fixed generation of exp + .lib via MS Library Manager for VS2017. Issue #37.
         Now it also includes processing through VsDevCmd & VcVarsAll initializer scripts.
         Use the folowing msbuild properties to override values by default:
         * $(DllExportVcVarsAll); $(DllExportVsDevCmd)

* FIXED: Fixes possible problem with multiple properties that contains *Undefined* word,
         e.g.: *Undefined*\path1;C:\path2 ...

* CHANGED: Added information about finding lib tool. Issue #44.

* CHANGED: UI. Selected platform now affects to all configurations of project instead of active as before.

* CHANGED: Now nuget package does not contain library in `lib/.../` Details in #36.

* CHANGED: Now we also distribute .zip package for work through our manager etc.
           https://github.com/3F/DllExport/releases

* NOTE: How to avoid EXP0014: RunIlAsm. The library manager still cannot be found.
        https://www.youtube.com/watch?v=zUejJ4vUPGw
        Related Issue #44

* NOTE: Quick start (Configuring, Automatic restoring, Pe-Viewer):
        https://www.youtube.com/watch?v=sBWt-KdQtoc

* NOTE: The latest text-based manager:
        https://3F.github.io/DllExport/releases/latest/manager/

           Other versions you can find from GitHub Releases:
           * https://github.com/3F/DllExport/releases

           Or get it from nuget packages starting with v1.6+

* NOTE: PE-features via Conari v1.3.0 https://github.com/3F/Conari

* KNOWN: Bug when - "Build successful but methods are not exported." Issue #59
         For today, anyone else may also try to use https://github.com/3F/Conari to avoid similar @Genteure's problem.

* DIFF(v1.6-RC):

    * FIXED: Wizard. Fixed incorrect layout for zh_CN Simplified Chinese (Thanks @Genteure). Issue #61
    * FIXED: Fixes automatic restoring the package via msbuild. Issue #62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants