-2

I have a solution with 3 projects. One is a library, the other two are console apps which both use this library.

I was having problems running one of the applications - a call into my lib that calls System.Buffers.Binary.BinaryPrimitives was generating an assembly exception.

I noticed their app.config files are different:

App A

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>

App B

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
</configuration>

All those additional assemblies are dependencies of my library project, so should presumably be in both. Why the library project itself isn't referenced I don't know.

I have never touched the config files so they are autogenerated but not equivalently. Why? And how can I get VS to regenerate?

The only difference in approach I can think of is that when I started using my library in App A, VS suggested adding a reference which I accepted. In App B, I believe I added the dependency manually.

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • The DLL is copied into the bin folder, but did you check its version? One console app could use an assembly-binding redirect while the other does not. –  Jan 20 '20 at 19:37
  • I've re-written this question after realising the cause is the app.config files – Mr. Boy Jan 20 '20 at 21:05
  • Manually editing app.config resolves the issue but leaves me worried :) – Mr. Boy Jan 20 '20 at 21:56

1 Answers1

0

References are mentioned in csproj file, you can access it by right clicking your project, unload, edit. there it will look something like this. also you can manage your project references under Reference 'folder'

<ProjectReference Include="..\YourProject.csproj">
  <Project>{68836A56-12B9-4740-A78D-78F027336CBF}</Project>
  <Name>YourProject</Name>
</ProjectReference>

Mostly you do not edit app.config for reference purposes. Shortly, app.config is used for runtime settings.

Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
  • also you did not mention what is the problem with your project, so it is possible that app.config is unrelated to it – Yehor Androsov Jan 20 '20 at 21:10
  • I've looked in both app .csproj files and can see no differences. Both reference my library project. How can I force it to rebuild my app.config file? – Mr. Boy Jan 20 '20 at 21:49
  • @Mr.Boy I am still not sure how your problem is related with app.config, but you can try this approach https://stackoverflow.com/a/17795636/7313094 – Yehor Androsov Jan 20 '20 at 21:57
  • Required assemblies are not listed in app.config. manually adding them fixes the issue – Mr. Boy Jan 21 '20 at 22:03
  • @Mr.Boy i literally mentioned it in my answer, "References are mentioned in csproj file" – Yehor Androsov Jan 22 '20 at 09:34