lovettchris / SgmlReader

SgmlReader is a .NET library that is handy for converting SGML content (like HTML and OFX) into well formed XML via XmlReader, XmlDocument, XDocument or XPathDocument. It runs on Windows and Linux using Mono.
Apache License 2.0
45 stars 15 forks source link

Warning: Resolved file has a bad image (netcoreapp3.1 and net5.0) #10

Closed victor-david closed 3 years ago

victor-david commented 3 years ago

When a project with TFM netcoreapp3.1 or net5.0 uses package Microsoft.Xml.SgmlReader, a build warning occurs:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2182,5): warning MSB3246: Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'SgmlReader.exe' or one of its dependencies. The module was expected to contain an assembly manifest.

This occurs for all versions from 1.8.15 to 1.8.20

<ItemGroup>
  <!-- tried everything from 1.8.15 onward -->
  <PackageReference Include="Microsoft.Xml.SgmlReader" Version="1.8.20" />
</ItemGroup>

If the project does not target netcoreapp3.1 or net5.0, no warning is emitted.

To repro:

  1. Using Visual Studio 2019 latest version (16.9.2 as of today), create a new app that targets netcoreapp3.1 or net5.0. Don't make any changes to the new app.
  2. Add package Microsoft.Xml.SgmlReader
  3. Build

Expected: Normal build

Actual: Above warning emitted.

My actual app is more involved of course, but the warning is the same. And then when my app needs to use the Sgml reader, it throws with:

Could not load file or assembly 'SgmlReaderCore, Version=1.8.20.0, Culture=neutral, PublicKeyToken=ab3ea86545595e2b'. The system cannot find the file specified.

Any advice appreciated. Thanks

p.s. I looked on StackOverflow first and the same issue is reported there, but there's no answer. Thought maybe this might get to you easier.

lovettchris commented 3 years ago

Thanks for the bug report. I think I have fixed it in a new version 1.8.21. Let me know, thanks.

victor-david commented 3 years ago

Thanks Chris. With 1.8.21, the warning is gone and things appear to be working as they should again. In case others read this, my situation is:

MyNet5App -> uses MyLib -> which uses Microsoft.Xml.SgmlReader

When MyLib targets netstandard2.0;netstandard2.1, MyNet5App can't parse SGML because of the cannot load SgmlReaderCore meantioned above. And in fact, SgmlReaderCore.dll doesn't wind up in the app bin directory.

When MyLib also targets netcoreapp3.1;net5.0, then SgmlReaderCore.dll still doesn't wind up in the app bin directory, but MyApp does parse sgml as it should. I imagine this is because I don't understand how all the TFMs relate to each other. :(

At any rate, many thanks! for your quick response. Things are working as they should, and I'm back in business again getting my app going in .Net5

lovettchris commented 3 years ago

this is now fixed.