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

System.Data.Common.dll has an incorrect format #23279

Closed
darrensteadman opened this issue Aug 21, 2017 · 6 comments
Closed

System.Data.Common.dll has an incorrect format #23279

darrensteadman opened this issue Aug 21, 2017 · 6 comments
Milestone

Comments

@darrensteadman
Copy link

I am in the process of updating a project that uses Windows Workflow to use some netstandard2.0 dependent assemblies.

When I build the project I get the following warning

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Xaml.targets(347,5): warning : Could not compile workflow expressions because file 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Data.Common.dll' has an incorrect format. Workflows in this project may still run, if they do not require expression compilation. If the file is a platform-specific library or executable, consider building the project using MSBuild.exe from a command prompt of the targeted platform.

The problem is the workflows now do not run and I get the following

Expression Activity type 'CSharpReference`1' requires compilation in order to run. Please ensure that the workflow has been compiled.

This project has been working fine when all assemblies were targeting net461. This has only happened since introducing the netstandard2.0 libraries.

I am running VS 2017 15.3.1 and the official .NET Core 2.0 SDK.

This problem is actually really easy to reproduce, just create a standard .NET framework project and then add any netstandard2.0 assembly to the project and just add a blank Workflow .xaml file and compile. You'll get the warning or you might need to fix the first warning you get by following the links below first.

You may need to also modify the project file to stop the problem noted at https://github.com/dotnet/sdk/issues/1509 and you might also want to modify the project file so that nuget plays nicely like in https://github.com/dotnet/sdk/issues/901

@danmoseley
Copy link
Member

@weshaggard @ericstj ?

@ericstj
Copy link
Member

ericstj commented Aug 21, 2017

This looks like a BadImageFormatException when reading C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Data.Common.dll. Can you double check that the file is not corrupt? You can run signtool verify /pa "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\System.Data.Common.dll" from a development prompt.

@ericstj
Copy link
Member

ericstj commented Aug 21, 2017

That doesn't seem to be it. I'm reproducing it now on other assemblies. Looking into it.

@ericstj
Copy link
Member

ericstj commented Aug 21, 2017

The problem here is that the workflow XAML compiler is loading reference assemblies for execution. Its similar to https://github.com/dotnet/corefx/issues/23229.

The offending method is Microsoft.Activities.Build.Utilities.GetLocalAssembly(string). This ends up loading the reference from the target framework for execution in the build process.

@ericstj
Copy link
Member

ericstj commented Aug 21, 2017

Workaround is the following, note that this relies on private MSBuild item names and could be broken in the future. Note that this requires both a workaround for the xaml compiler and the workaround from #23174 since the workflow compiler is emitting a static set of reference filenames into a generated file and trying to load them at runtime.

  <Target Name="ReplaceNetFxNetStandardRefWithLib" AfterTargets="ImplicitlyExpandNETStandardFacades">
    <ItemGroup>
      <Reference Remove="@(_NETStandardLibraryNETFrameworkReference)" Condition="'%(FileName)' != 'netfx.force.conflicts'"/>
      <Reference Include="@(_NETStandardLibraryNETFrameworkLib)">
        <Private>true</Private>
      </Reference>
    </ItemGroup>
  </Target>
  <Target Name="RemoveNetFxForceConflicts" AfterTargets="ResolveAssemblyReferences">
    <ItemGroup>
      <ReferencePath Remove="@(ReferencePath)" Condition="'%(FileName)' == 'netfx.force.conflicts'" />
    </ItemGroup>
  </Target>

@ericstj
Copy link
Member

ericstj commented Aug 21, 2017

Moved this to SDK: dotnet/sdk#1522

@ericstj ericstj closed this as completed Aug 21, 2017
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants