Visual Studio 2017 adding unwanted dll's after publishing - c#

I have a web application built using .NET Framework 4.5.1
When i publish it from VS2017, VS2017 adds unwanted dll's, not listed in the references, which are :
System.Web.Mvc.dll
System.Web.Razor.dll
System.Web.Webpages.Deployment.dll
System.Web.Webpages.Razor.dll
When i try to publish from VS2013 it gives runtime error (razor missing) and my project doesn't have any cshtml file and of course it's not using any razor views.
Why does VS2013 require razor and is there any way to stop VS2017 adding razor and other unwanted dll's when publishing?
Thank you!!
**EDIT: ** From researching, i found that adding <PreserveCompilationContext>false</PreserveCompilationContext> in my csproj file, would stop VS2017 from adding razor, but after publishing now i get runtime error Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Have you tried examining the Options under the Debug menu in Visual Studio, one of the settings allows you to control this (under package/publish) by choosing Items to deploy: Only Files Needed to Run This Application
It is also possible that one of the assemblies you are referencing is required by another assembly.
snapshot of the configuration window

Related

Xamarin.Android Creating Xamarin.ios.dll files

Our app appears to be creating Xamarin.ios.dll files within the debug folders on the build. we then get the following error on certain events
System.IO.FileNotFoundException: Could not load file or assembly 'Xamarin.iOS, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' or one of its dependencies.
We believe this is coming from one of the packages added to the project. is there an easy way to discover which package it is?
Assembly Folder:
After removing Xamarin.forms and adding the the latest version im still not given the option add the Xamarin.forms to the shared references.
References which can be added:
The app will only build if Xamarin.iOS is with the Assembly folder as shown in the previous image
we get this Error if we do not add the Xamerin.iOS.dll to the shared assembly folder:
Reported as an issue in VS
"Xamarin.iOS" is contained in "Xamarin.Forms", so try to uninstall the "Xamarin.Forms" Nuget Package and install the latest version.
Then delete the "bin" and "obj" folder under project path, and clean&rebuild the project.

Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I got the project from colleague and got this error when building project:
Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I guess this dll is in .NET Framework Dll Folder: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework, but after searching, I find many dll of other version, but I didn't find any System.Runtime.dll is 4.2.1.0.
Here's another similar question but no answer to it.
Is System.Runtime.dll 4.2.1.0 really exists in .NET Framework?
I know this is an old post, but I think it's useful to share my solution with others that encounter this exact problem.
I created a new Console App via the terminal: dotnet new console
I opened the folder of the Console App in Visual Studio 2019.
I tried to run the code using ctrl + f5
That's when I encountered: Could not load file or assembly 'System.Runtime, Version=5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
To solve it, instead of opening the Console App folder in Visual Studio 2019, I had to open the file inside of it that ended with .csproj and then doing ctrl + f5. After that it ran smoothly. Hope this will help someone else. Been troubleshooting for a long time to find the solution.
TL;DR: open the .csproj file in Visual Studio 2019 instead of the project folder that it resides in.
This happens when you open the folder instead of the solution file. Simply ensure that you load the solution file and not the directory of your project.
This is quite an annoying issue. From what I noticed, it's being caused by dependentAssembly once you install a new package or update it. At least that was the root cause for me.
Try checking the dependentAssembly newVersion inside your Web.config. If I'm correct, you should have something like:
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.3.0" />
</dependentAssembly>
Make sure that your Web.config dependentAssembly matches the version defined inside the Web.Base.config (or the version inside the Nuget Package Manager). If not, change the newVersion= to the version you have installed in your Nuget Package Manager.
If that doesn't work, you could check this link out. Might be an option which will work for you.
I had this problem today for System.Runtime 4.2.2.0. It happened when opening the folder for a solution in Visual Studio instead of opening the solution file instead. Closing Visual Studio 2019 down and clicking on the solution file to open it fixed my issue.
To solve the problem, I originally guess System.Runtime.dll should be in .NET Framework Dll Folder, because in Nuget Page of this dll, the version history doesn't contains 4.2.1.0, but after reading #Scircia answer, I try to add the latest Nuget System.Runtime.dll to the project by Right Click On Project > Property Page > References > Add. the Nuget version of the dll is 4.3.1, but its dll version is 4.6.27406.3.
After Adding, a new error show:
Assembly 'XXXX(It's secret), Version=x.x.x.x, Culture=neutral, PublicKeyToken=xx' uses 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
But the dll I add is 4.6.27406.3, why got this 4.0.0.0 error? After some try, I finally find the main cause is, in the project many component use .NET Framework 3.5 so it should be run at 3.5, but when I Right Click On Project > Property Page > Build > Target Framework, it shows currently use 4.0.
So I follow these step to change the Target Framework from 4.0 to 3.5 Click OK, then again from 3.5 to 4.0, then the error is solved. That is, through 4.0 > 3.5 > 4.0, the web.config is auto modifed and seems some dll that need 3.5 is removed, become a real 4.0, and in Framework 4.0 the System.Runtime.dll works good.
Since it says need 4.2.1.0, but I add 4.6.27406.3 works, so I suppose that use a higer version than 4.2.1.0 is allowed, not need to use exactly 4.2.1.0.
But another point is, since the project need to run at 3.5 to make the Web UI package works, after changing to 4.0, some of the UI control lost function.
So I conclude that the XXXX(It's secret).dll should not be use in the .NET Framework 3.5 project.
Besides I use Resharper to see the XXXX.dll shows that it's .NETCoreApp.
My quick solutions was deleting the [application name].config file to make it ran.
It might be good enough if you only need to make the program run.

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0?

I have an issue in Newtonsoft.json library. When i try to run project using visual studio, it's working properly. But when i tried to create .exe on this, it shows a run time error
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependancies.
The system cannot find the file specified.
In refereence and bin folder newsoft.json file available. Also in package folder also available.
Why this error triggers only when i create .exe?
Please help me..
I had the same problem, but my project was a console application made with .Net full, referencing another .Net standard project which had the NewntonSoft referenced.
Both projects needs to use package management the same way. This article explains this better:
https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx
.NET projects are not normally run as a standalone *.exe file.
You're choice is either create a setup project for your program or to copy the whole bin\Release folder. This folder should contain all the necessary non-standard libraries (the standard .NET libraries are provided by the operating system).
Try to match the versions of the package on all the sub projects, by upgrading on it.
Installed Costura.Fody library file. Now its working as expected.

VS compiler warning on .net version of system.windows.forms

I'm using VS2015 and working in a solution with numerous projects.
One project in my solution (call it "MyDllProject") is a class library targeted for .NET version 4.0. It does itself reference numerous dlls, including (in this case) System.Windows.Forms. The reference in the project file is as follows:
<Reference Include="System.Windows.Forms" />
So it is not referencing a specific version. From the properties tab, it seems it is picking up that file from the following location:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Windows.Forms.dll
On my system, I have numerous other versions of System.Windows.Forms in various other subdirectories (v3.5, v4.5, v4.5.1, v4.6, v4.6.1) under the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\ root. But it seems to me my system is getting the right one.
MyDllProject builds just fine, cleans fine, rebuilds fine and seems happy as a clam.
Numerous other projects in my solution also refer to MyDllProject and they themselves also build, clean, and rebuild just fine.
HOWEVER.... there is an old ASMX web site "project" in this solution. ASMX websites don't have project files per se.... all their project information is in the solution file. Not sure if that is relevant. Like everything else in the solution, this ASMX web site is targetted for .net version 4.0. And when I build that web site, either by building the entire solution or by just building the web site project, I get the following warning:
(0,0): warning : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: MyDllProject, Version=14.0.0.0, Culture=neutral, PublicKeyToken=null. The dependencies are: System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly.
Now everything seems to work generally in my MyDllProject, and in the ASMX web site, but I like to follow the best practices and get warnings out of my build, or at least understand them. And I don't fully understand how this warning comes about, how it comes ONLY from building this one ASMX web site, and how to get rid of it.
Thanks in advance for any insights or suggestions.

How to know which assemblies are depended on system.web.mvc?

I'm using asp.net mvc 4 in my project, but there are some assemblies that are trying to find 3.0.0.0.
Project works fine on my development machine, but throws an error "Could not load System.Web.Mvc version 3.0.0.0" on the server.
Also, I see the warning in my Visual Studio
Found conflicts between different versions of the same dependent
assembly. In Visual Studio, double-click this warning (or select it
and press Enter) to fix the conflicts; otherwise, add the following
binding redirects to the "runtime" node in the application
configuration file:
I don't want to add binding redirect in my web.config, I want to update the assembly that depend on older version of system.web.mvc to the newer one, but I have no idea what is the name of that assembly. How can I know that?
Delete the reference to System.Web.Mvc in the Solution references. Then add only the reference of MVC Ver 4.0 Dll from project folder path - \packages\Microsoft.AspNet.Mvc.4.0\lib\net40.
Once you compile the project, It will list out the controller or views which are not compatible with MVC 4.0. You can identify the assemblies based on error details.

Categories