.NET Core 5 dependencies not included in Release compile - c#

I'm migrating a muti-project .NET 4.6 solution to .NET Core 5.02. The .csproj files were manually migrated using these instructions. The solution creates DLLs which are plugins for another application; that app loads the DLLs at runtime. The DLLs created by the solution run fine on my development PC (of course). When installing these plugins into a pristine copy of the app in Windows Sandbox, one of the DLLs fails with error:
Could not load file or assembly 'System.Drawing.Common, Version=5.0.0.2,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the
file specified.
This prevents that DLL from being loaded. A differnt DLL with a reference to Microsoft.Windows.Compatibility loads OK but it has no ref to System.Drawing.
The project in which this fails at runtime has System.Drawing installed as a package reference (no packages.config). Again, it compiles and runs correctly on the development PC.
I've tried:
uninstalling System.Drawing from NuGet, fetching it again from NuGet and reinstalling it in the solution
using Update-Package -reinstall in the project which resulted with no references needing reinstall, closing and reopening VS2019 ;)
used Publish on the project but only got a .nupkg instead of a DLL and dependencies.
I'm not allowed to post pics (new user) or I would include pics of the Dependencies tree and of the project references in the .csproj. Does anyone have any suggestions? Thank you.

The following has to be added to the project's .csproj file:
<PropertyGroup> <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> </PropertyGroup>

Related

Problem generating manifest. C# VS 2022 17.2.5

I have wpf project
for Framework .NET Framework 4.7.2
Build Any CPU
Previous Build was allways without problem.
After i opened the project from a new installation of visual studio 2022
I always get:
Problem generating manifest. Could not load file or assembly
'D:\Source\Repos..Toolbox.exe' or one of its dependencies. An attempt
was made to load a program with an incorrect format.
I Just tried:
Build Setting PlattForm Target differnet values
Nuget Package Manager Package Manager Console update-Package -reinstall
i added:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
I have some References but nothing special. To get sure i reinstalled
RestSharp.
Is there a way to find out which reference throws the error during creation of the Manifest?
Solution had nothing to do with Visual studio.
A virus scanner detected the new created .exe file and removed it.
The Error message from Manifest creation was missleading. The file was simply missing in the directory when generating the Manifest.

Issue with system.runtime DLL pointing to older version even after installing the latest version from NUGet package manager

I am currently working to integrate PowerShell script to my ASPX Web Forms and in this process, I am facing below issue which is holding me to move further as I could not even build the solution because of Reference Issues
a) Installed system.Management.automation from NuGet Package manager, however after installing I do not see the references added automatically so I have added this DLL manually from the Project location. Not sure if this will not make an issue, but assuming it should be added automatically
b) system.Management.automation 7.0 version DLL requires System.runtime Version=4.2.2.0, so I have installed System. runtime 4.3 stable version. But when I try to add the latest version it still points to the older 4.1.2.0 version and fails with below error
> Error CS1705 Assembly 'System.Management.Automation' with identity
> 'System.Management.Automation, Version=7.0.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35' uses 'System.Runtime,
> Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
> which has a higher version than referenced assembly 'System.Runtime'
> with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a' WebApplication16 C:\Users\****\source\repos\WebApplication16\WebApplication16\Default.aspx.cs 32 Active
Below are the things I have tried and none of them works
1) Created new project multiple times
2) has cleaned and rebuild the solution
3) Tried giving bindingRedirect in Web.config to make it use the latest version, no luck
4) Removed old version from References and tried to add a new system. runtime Version however it added the older version to the project
Could someone please suggest on this
I had this exact problem when working with .Net, and here is the easy solution:
Open PowerShell and execute the following command
Copy ([PSObject].Assembly.Location) C:\
That will place a copy of System.Management.Automation on your C: drive path. You can move that into your solution folder instead if you prefer.
In your Visual Studio Project, right click References tree in the Solution Explorer tab, and click Add Reference
Click Browse, and locate the .dll from step 1.
Rebuild, and you should be good to go!
You are using .Net Framework, not .Net Core, and I assume that's what is causing issue, which is very cryptic, as you can reference the DLL but can not use it.
You need to find older version of this library. Nuget won't do, as the earliest version there is 6.0.4, which is using System.Runtime 4.2.0.
Search for other, older versions on your computer, it's likely to be found in GAC folders. Once found, copy and reference it. Automation DLL version 4.x will likely work in your case.

Dependencies not copied to bin folder

I have created a new web site using Visual Studio 2017. The target framework for this site is NetCoreApp 1.1. As this is an MVC project, it references a number of Microsoft and third-party dlls from Nuget. I also have a data project that I created as a library. It is Netstandard1.6. When I build the solution, none of the dlls from the Nuget packages are copied to the bin folder. This causes the app to crash with a FileNotFound exception when attempting to debug it. The project references are being copied correctly, so it appears to only be a problem with Nuget packages. As a workaround, I can publish the project and copy that output to the bin folder, but I shouldn't have to do that, should I?
.NET Core uses the generated .deps.json file in the output to resolve assemblies, so it avoids copying the files unnecessarily during the build.
However if some assemblies try to look for other assemblies in the output directory or the files referenced in the deps.json file cannot be accessed (e.g. testing build output in IIS), you can add this to a <PropertyGroup> element in your csproj file to cause the NuGet assemblies to be copied to the output directory:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
This 'CopyLocalLockFileAssemblies' doesn't do anything on my end. The only way I found to get the content of the 'runtime' folder in my output is to use 'Publish'. This is not a solution to locally debug an application.
Edit :
Adding the Runtime IDentifiers to the project file seems to do it for me.
Also, .NET Core 3.0 fixes the issue but it is only in Preview.

FileNotFoundException when referencing DLL in .NET Core Application

I have a .NET Core console application and a .NET Core class library. Both are extremely simple, single class projects. Both are freshly built, with a fresh install of the latest .NET Core. Both target .NET Core 1.1.
This error occurs at runtime whenever I include a .NET Core class library in an application:
System.IO.FileNotFoundException: 'Could not load file or assembly
'NAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The
system cannot find the file specified.
Building either projects are fine, and Intellisense shows me the contents of the class library after including a using... statement. With the reference and code written there are no issues at compile time.
I've set the Copy Local to Yes for the referenced assembly in my console application. The referenced DLL exists in the bin folder of the console application during run time.
Here is the csproj reference:
<Reference Include="NAME">
<HintPath>path\bin\Debug\netcoreapp1.1\NAME.dll</HintPath>
<Private>true</Private>
<SpecificVersion>false</SpecificVersion>
</Reference>
This only happens with .NET Core DLLs, I have absolutely no issues with .NET Framework 4.5.* and up.
Could anybody shed some light on this issue? Any SO/MSDN pages I've found regarding this have been specific problems like targeted the incorrect version of a DLL, which doesn't help.
Referencing DLL files in a .NET Core application is not supported using the pre-2.0 tools.
The reason is that the dependency graph (deps.json file) generation does not include these files and most likely wouldn't work anyway since it cannot consolidate references / dependencies of the referenced DLL anyway.
For the upcoming 2.0 release, this scenario should work as long as you also reference all DLLs / packages that the original package is using. The syntax would be:
<Reference Include="path/to/my.dll" />
.NET Core 2.0 will also support referencing assemblies that have been built for .NET 4.6.1 this way, but it may fail at runtime if the DLL uses unsupported API calls.
After lots of digging, I found a solution for .NET Core 2.0 that works for me.
The core issue: I added the project references through Visual Studio 2017. In my web application, I referenced two .NET Core libraries; while everything compiles, at runtime, I get a FileNotFound exception pointing to one of the two DLLs.
The solution that worked for me:
Close Visual Studio
Open the .csproj with the references in it. Delete the references to the projects.
From a terminal, cd into the project folder and add the references by hand, using dotnet add reference ..\..\foo\bar.csproj
Start Visual Studio, build and run your (web) application
For me, this resolved the issue.
Not sure if this would count as a fix but it's a workaround at least.
Rather than referencing the DLL I've simply added the project for the class library to the console application, included a dependency reference to the class library project in the console application and clean/rebuilt. Working fine.
Obviously this isn't a fix for DLLs that are proprietary, but it may help.

Microsoft.Threading.Tasks not found, .net 4.0

I converted my .net application to .net 4.0 and because im using async/await I installed NuGet packages Async for .Net 4 and dependencies Microsoft BCL...
When I build my application, everything goes well but when I move my app .exe to correct environment I get the error:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies.
If I include Microsoft.Threading.Tasks.dll to my applicatin directory everything works well (this .dll is copied to my app build directory).
So the question is do I need to include this Microsoft.Threading.Tasks.dll to my app installer or Is there way to bundle this to my app .exe?
When you build your app there will be a few DLL's in the output folder. Your exe potentially needs all of the DLL's in that folder in able to run.
You should include all of the dll's with the installer that the compiler puts in to the output directory.

Categories