最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - OpenAccessEnhancer works in VS2017 and VS2019, but not in VS2022 (solved but not understood) - Stack Overflow

programmeradmin4浏览0评论

I'm building an old C# solution. I manage doing this in Visual Studio 2017 and 2019, but not in VS2022.

For your information: both applications in the solutions are 32-bit, and the compilation result needs to be 32-bit too.

As VS2019 is the most recent which is working, I go from here:

First of all, my solution consists of three projects:

  • a general one, containing common information, classes, ...
  • a client application
  • a server application

When building this in VS2019, this is the sequence:

Rebuild started...
1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: MyProject.Client, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: MyProject.Server, Configuration: Debug Any CPU ------

When doing this in VS2022, this is the sequence:

1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: MyProject.Server, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: MyProject.Client, Configuration: Debug Any CPU ------

(I have no idea if the sequence makes any difference.)

The problem arises in the chapter "", hence let's have a look:

In VS2019 (the succeeding one):

3>Task "OpenAccessEnhancer"
3>  "C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll" -reference:... -attributeMapping -fluentMapping
3>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
3>Done executing task "OpenAccessEnhancer".

In VS2022 (the failing one):

2>Task "OpenAccessEnhancer"
2>  Assembly loaded during TaskRun (Telerik.OpenAccess.Tools.OpenAccessEnhancer): Telerik.OpenAccess.SDK, Version=2016.2.822.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342 (location: C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\Telerik.OpenAccess.SDK.dll, MVID: 12e34e50-0159-46b0-bc4e-bf3a18087324, AppDomain: [Default])
2>  "C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll" -reference:... -attributeMapping -fluentMapping
2>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
2>C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll(-1,-1): OpenAccess Enhancer error 0: The specified assembly 'C:\Users\DDM\AppData\Local\Temp\_ptil_77936\MyProject.Server.dll' cannot be loaded. The problem might be that the enhancer runs in a .NET framework 2.0 vm and the assembly to enhance is a .NET 4.0 assembly or you are trying to enhance a x86 assembly in a 64 bit process or a x64 assembly in a 32 bit process. Please change the required version inside the enhancer.exe.config or venhance.exe.config or switch to 'Any CPU' for this project.
2>Done executing task "OpenAccessEnhancer" -- FAILED.
2>Done building target "OpenAccessEnhancer" in project "MyProject.Server.csproj" -- FAILED.

For your information: I already tried making following replacement in enhancer's configuration file: Original:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <!--The enhancer is compiled against .NET 4.0.-->
    <!--To be able to enhance an .NET 2.0 assembly please comment out the next line:-->
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

After update:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0.30319"/>
  <!--<startup> orig -->
    <!--The enhancer is compiled against .NET 4.0.-->
    <!--To be able to enhance an .NET 2.0 assembly please comment out the next line:-->
    <!--<supportedRuntime version="v4.0"/> orig -->
  </startup>
</configuration>

I'm working with VS2019, version 16.11.42.
I'm working with VS2022 64-bit, version 17.13.1.

I believe the cause of this issue is in the used platform (before VS was 32-bit, now it is 64-bit), hence a screenshot of my task manager, showing this difference:

Can somebody help me with a migration procedure for unblocking my situation?

Edit: Some extra information:
I have another application, also 32-bit, very similar, and that application does not have any compilation problems. Hereby the compiler output for the enhancer chapter:

2>Task "OpenAccessEnhancer"
2>  "C:\...\MyOtherProduct\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyOtherProduct\MyOtherProduct.Server\obj\Debug\MyOtherProduct.Server.dll" -reference:... -attributeMapping -fluentMapping
2>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
2>Done executing task "OpenAccessEnhancer".

Solution found but not understood:
My working solution had its platform target set as "Any CPU", while my failing solution had its platform target set as "x86". Changing that seems to be the solution, which solves my problem.
Except: I don't understand WHY this solves my problem.
Can anybody explain?

Thanks in advance

I'm building an old C# solution. I manage doing this in Visual Studio 2017 and 2019, but not in VS2022.

For your information: both applications in the solutions are 32-bit, and the compilation result needs to be 32-bit too.

As VS2019 is the most recent which is working, I go from here:

First of all, my solution consists of three projects:

  • a general one, containing common information, classes, ...
  • a client application
  • a server application

When building this in VS2019, this is the sequence:

Rebuild started...
1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: MyProject.Client, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: MyProject.Server, Configuration: Debug Any CPU ------

When doing this in VS2022, this is the sequence:

1>------ Rebuild All started: Project: MyProject, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: MyProject.Server, Configuration: Debug Any CPU ------
3>------ Rebuild All started: Project: MyProject.Client, Configuration: Debug Any CPU ------

(I have no idea if the sequence makes any difference.)

The problem arises in the chapter "", hence let's have a look:

In VS2019 (the succeeding one):

3>Task "OpenAccessEnhancer"
3>  "C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll" -reference:... -attributeMapping -fluentMapping
3>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
3>Done executing task "OpenAccessEnhancer".

In VS2022 (the failing one):

2>Task "OpenAccessEnhancer"
2>  Assembly loaded during TaskRun (Telerik.OpenAccess.Tools.OpenAccessEnhancer): Telerik.OpenAccess.SDK, Version=2016.2.822.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342 (location: C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\Telerik.OpenAccess.SDK.dll, MVID: 12e34e50-0159-46b0-bc4e-bf3a18087324, AppDomain: [Default])
2>  "C:\...\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll" -reference:... -attributeMapping -fluentMapping
2>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
2>C:\...\MyProject.Server\obj\Debug\MyProject.Server.dll(-1,-1): OpenAccess Enhancer error 0: The specified assembly 'C:\Users\DDM\AppData\Local\Temp\_ptil_77936\MyProject.Server.dll' cannot be loaded. The problem might be that the enhancer runs in a .NET framework 2.0 vm and the assembly to enhance is a .NET 4.0 assembly or you are trying to enhance a x86 assembly in a 64 bit process or a x64 assembly in a 32 bit process. Please change the required version inside the enhancer.exe.config or venhance.exe.config or switch to 'Any CPU' for this project.
2>Done executing task "OpenAccessEnhancer" -- FAILED.
2>Done building target "OpenAccessEnhancer" in project "MyProject.Server.csproj" -- FAILED.

For your information: I already tried making following replacement in enhancer's configuration file: Original:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <!--The enhancer is compiled against .NET 4.0.-->
    <!--To be able to enhance an .NET 2.0 assembly please comment out the next line:-->
    <supportedRuntime version="v4.0"/>
  </startup>
</configuration>

After update:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0.30319"/>
  <!--<startup> orig -->
    <!--The enhancer is compiled against .NET 4.0.-->
    <!--To be able to enhance an .NET 2.0 assembly please comment out the next line:-->
    <!--<supportedRuntime version="v4.0"/> orig -->
  </startup>
</configuration>

I'm working with VS2019, version 16.11.42.
I'm working with VS2022 64-bit, version 17.13.1.

I believe the cause of this issue is in the used platform (before VS was 32-bit, now it is 64-bit), hence a screenshot of my task manager, showing this difference:

Can somebody help me with a migration procedure for unblocking my situation?

Edit: Some extra information:
I have another application, also 32-bit, very similar, and that application does not have any compilation problems. Hereby the compiler output for the enhancer chapter:

2>Task "OpenAccessEnhancer"
2>  "C:\...\MyOtherProduct\packages\Telerik.DataAccess.Fluent.2016.2.822.1\tools\enhancer\enhancer.exe" -verboseMode:3 -assembly:"C:\...\MyOtherProduct\MyOtherProduct.Server\obj\Debug\MyOtherProduct.Server.dll" -reference:... -attributeMapping -fluentMapping
2>  Telerik AD Telerik Data Access Enhancer, Version 2016.2.822.1, Copyright (C) 1996-2016 Telerik AD. All rights reserved.
2>Done executing task "OpenAccessEnhancer".

Solution found but not understood:
My working solution had its platform target set as "Any CPU", while my failing solution had its platform target set as "x86". Changing that seems to be the solution, which solves my problem.
Except: I don't understand WHY this solves my problem.
Can anybody explain?

Thanks in advance

Share Improve this question edited Mar 11 at 7:39 Dominique asked Mar 10 at 16:09 DominiqueDominique 17.7k19 gold badges78 silver badges151 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

VS2019 and VS2017 are both 32-bit processes, so when you set the project platform target to x86 (32-bit), the entire compilation process (including calling third-party tools) also runs in a 32-bit process, and there is no conflict between them.

VS2022 is a 64-bit process. If the external tool (Enhancer) is executed in a 64-bit environment with MSBuild/IDE, and the target assembly is compiled as 32-bit (x86), there may be a loading conflict: the 64-bit process cannot directly load the 32-bit target assembly. The error message "you are trying to enhance a x86 assembly in a 64 bit process or a x64 assembly in a 32 bit process" is exactly this reason.

The assembly compiled by "Any CPU" is universal in architecture and can be run as a 32-bit process under 32-bit CLR or as a 64-bit process under 64-bit CLR. For Enhancer, "Any CPU" assemblies are no longer "32-bit only" or "64-bit only", so they can be loaded and processed in 64-bit processes.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论