dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

Projects with AssemblyName != Filename cannot be found #20120

Open mattleibow opened 3 years ago

mattleibow commented 3 years ago

Description

I just noticed that my "bait and switch" projects are no longer happy in .net core. Not sure when things changed, but it used to work because this is a project format that I have always used with cross-platform apps. And it works with netfx.

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' at SharedThings.TheThing.get_Message() at ConsoleApp2.Program.Main() in C:\Projects\Testing\WpfApp2\ConsoleApp2\Program.cs:line 10

I do have a ClassLibrary.dll in the bin directory, so it is there to be found. Also, if I switch to a <Reference> directly to the output dll of SharedLibrary.Platform, the app works.

And, if I do that, run the app, and then switch back to <ProjectReference> without rebuilding (just hit F5), it suddenly starts using SharedLibrary instead of SharedLibrary.Platform.

I have a solution with 4 projects:

Effectively, I have a way to write shared code and a shared app, then swap out the shared implementation with a real implementation.

Configuration

I tried using 3.1.411, 5.0.400 and 6.0.100-rc.1.21408.2

Regression?

I think so...

Other information

Sample project: SharedThings.zip

image

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 3 years ago

Tagging subscribers to this area: @vitek-karas, @agocke, @vsadov See info in area-owners.md if you want to be subscribed.

Issue Details
### Description I just noticed that my "bait and switch" projects are no longer happy in .net core. Not sure when things changed, but it used to work because this is a project format that I have always used with cross-platform apps. And it works with netfx. > Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. > File name: 'ClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' > at SharedThings.TheThing.get_Message() > at ConsoleApp2.Program.Main() in C:\Projects\Testing\WpfApp2\ConsoleApp2\Program.cs:line 10 I do have a `ClassLibrary.dll` in the bin directory, so it is there to be found. Also, if I switch to a `` directly to the output dll of `SharedLibrary.Platform`, the app works. And, if I do that, run the app, and then switch back to `` without rebuilding (just hit F5), it suddenly starts using `SharedLibrary` instead of `SharedLibrary.Platform`. I have a solution with 4 projects: - SharedLibrary - TFM: netstandard - AssemblyName: SharedLibrary - SharedLibrary.Platform - TFM: netcoreapp - AssemblyName: SharedLibrary - SharedApp - TFM: netstandard - Deps: SharedLibrary - WindowsApp - TFM: netcoreapp - Deps: SharedLibrary.Platform Effectively, I have a way to write shared code and a shared app, then swap out the shared implementation with a real implementation. ### Configuration I tried using `3.1.411`, `5.0.400` and `6.0.100-rc.1.21408.2` ### Regression? I think so... ### Other information Sample project: [SharedThings.zip](https://github.com/dotnet/runtime/files/6996724/SharedThings.zip) ![image](https://user-images.githubusercontent.com/1096616/129657881-1b332dac-d875-42ac-aa00-6f3d5425339b.png)
Author: mattleibow
Assignees: -
Labels: `area-AssemblyLoader-coreclr`, `untriaged`
Milestone: -
vitek-karas commented 3 years ago

The reason why this fails at runtime is that the generated .deps.json is wrong - it doesn't contain ClassLib.dll:

{
  "runtimeTarget": {
    "name": ".NETCoreApp,Version=v3.1",
    "signature": ""
  },
  "compilationOptions": {},
  "targets": {
    ".NETCoreApp,Version=v3.1": {
      "WpfApp2/1.0.0": {
        "dependencies": {
          "ClassLibrary": "1.0.0",
          "SharedThings": "1.0.0"
        },
        "runtime": {
          "WpfApp2.dll": {}
        }
      },
      "SharedThings/1.0.0": {
        "dependencies": {
          "ClassLibrary": "1.0.0" << Reference to non existing target - the .deps.json is effectively invalid
        },
        "runtime": {
          "SharedThings.dll": {}
        }
      }
    }
  },
  "libraries": {
    "WpfApp2/1.0.0": {
      "type": "project",
      "serviceable": false,
      "sha512": ""
    },
    "SharedThings/1.0.0": {
      "type": "project",
      "serviceable": false,
      "sha512": ""
    }
  }
}

I honestly don't know how the SDK is supposed to work in this case (if it should work at all).

In my mind: The solution builds two different instances of ClassLibrary.dll both of which should make it to the output. I think this should cause a failure since there's no way for the SDK to figure out which one should win.