dotnet core : Can not find assembly file Microsoft

2020-04-02 07:27发布

I have a project that i have not run for some while, build with dotnet core 1.1.2 dependencies.

in the meanwhile I have updated visual studio, possible installed some dotnet core stuff for 2.0 and my application do not run anymore.

InvalidOperationException: Can not find assembly file Microsoft.CSharp.dll at 'C:\dev\EarthML\EarthML.Mapify\src\EarthML.Mapify.Portal\bin\Debug\net462\win10-x64\refs,C:\dev\EarthML\EarthML.Mapify\src\EarthML.Mapify.Portal\bin\Debug\net462\win10-x64\'
Microsoft.Extensions.DependencyModel.Resolution.AppBaseCompilationAssemblyResolver.TryResolveAssemblyPaths(CompilationLibrary library, List<string> assemblies)

What would I do to start figuring out why it dont work?

标签: c# .net-core
6条回答
来,给爷笑一个
2楼-- · 2020-04-02 07:57

In my C# project, a few .NET Standard classlib's support a Core console application and a Winforms .net 4.7 program. Yesterday I opened my project, one of the .NET standard dll's gave above error, leaving references with an exclamation mark, same for all libs that depend on it in the solution ! It looked very alarming.

I kept working on my solution, though.. I use Visual Studio 15.8.1 here, the issue seems to be a spook. A fake warning. The exclamation marks remain while working on the project, but nothing happens, it does not disturb anything or interrupt rebuilds. The assembly runs as expected.

Few minutes ago I solved it, by removing the Microsoft.CSharp reference, then rebuild all. It was in only one library, so the rebuild solved all exclamation marks in the solution. The reference has gone away, clear sky.

查看更多
祖国的老花朵
3楼-- · 2020-04-02 07:58

clean the solution and rebuild it . if not worked create new project then copy dll and paste . good luck .

查看更多
▲ chillily
4楼-- · 2020-04-02 08:01

Have you included the Microsoft.CSharp.dll reference? Expand your project, right click on References, click Add Reference, search Microsoft.CSharp, check the box, click OK.

Select Microsoft.CSharp

查看更多
该账号已被封号
5楼-- · 2020-04-02 08:01

I upgraded the application to dotnet core 2.0 and razor pages and got around the issue.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2020-04-02 08:09

I had <DependsOnNETStandard>true</DependsOnNETStandard> and I had to change it to <DependsOnNETStandard>netstandard1.6</DependsOnNETStandard>

<PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    <IsServiceFabricServiceProject>True</IsServiceFabricServiceProject>
    <AssemblyName>MyProject</AssemblyName>
    <Platforms>AnyCPU;x64</Platforms>
    <DependsOnNETStandard>netstandard1.6</DependsOnNETStandard>
</PropertyGroup>

Source: From neman on GitHub Isue

查看更多
孤傲高冷的网名
7楼-- · 2020-04-02 08:10

This seems to be a bug with the current version of Visual Studio (15.3). The underlying problem is when the Views are trying to build, they are not referencing the GAC, and thus, have none of their dependencies.

While only a work-around, your best bet when encountering this problem is to copy over the missing DLLs. I set them up as components in my project with a copy action. Once it gets fixed (currently Triaged: https://developercommunity.visualstudio.com/content/problem/96927/runtime-error-after-upgrading-to-vs-153-invalidope.html), then it's a matter of deleting them.

EDIT

Alternately, according to https://github.com/dotnet/sdk/issues/1488, adding this as a reference to the project should work instead of adding all the dependencies:

<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="2.0.0" />
查看更多
登录 后发表回答