dlls missing after publishing .NET Web - c#

My web project use .NET Framework 4.7.2 and use some references like
System.IO
System.Net
System.Net.Http
System.Net.Http.Formatting
My project works perfectly in local.
However, when I publish my web project on a target directory (for online), and look what it contains in /bin/ :
System.IO is missing
System.Net is present
System.Net.Http is missing
System.Net.Http.Formattingis present
Therefore, when I use my website, I get the obvious error Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
All references have Copy Local = True in Properties but some dll are always ignored. If i copy the dlls from local directory to target directory i get the error Server Error in '/' Application. Cannot load a reference assembly for execution. Exception Details: System.BadImageFormatException: Cannot load a reference assembly for execution. Exactly the same problem as this one.
However the delete/rebuild solution, or adding compilation options solution, doesn't work for me
What do I need to do to get these missing dlls to the destination folder?

Go to Solution Explorer on VS, open references tree, right click on the library(dll) and select properties on the menu. On properties box Copy Local should be True

Related

Could not load file or assembly C# Console Application with Class Library

I've created a Class Library in C# .Net Framework 4.8, and in the solution I've also included a Console Application, same target.
I'm running both in a x64 configuration.
No errors on build.
I referenced the App in the Library, and when I run a Button in a Form in the Class Library I'm getting an error:
System.IO.FileNotFoundException: Could not load file or assembly
'ExampleApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or
one of its dependencies. The system cannot find the file specified.
File name: 'ExampleApp, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
I've combed the internet and SO for a solution. I tried repairing Visual Studio, I tried deleting the .vs folder in the projects, I tried things like:
solution 1
and
solution 2
I seriously tried everything I could think of. It has to be something to do with the .dll dependencies imho, because the only one that my ExampleApp is using is the Microsoft.CognitiveServices.Speech reference which I installed via NugetPackage in my solution.
No idea how to debug this further or get a proper trace stack from this error...
Any ideas on how to proceed?
Thanks
Solved by changing the .dll's Copy Local property to True
Exactly #Yafim Simanovsky, I solved also my problem by changed <Private> flag to True.
My problem (“Could not load file or assembly…”) was with new Designer ‘WpfSurface.exe’ from VS 2022, which after changing the reference tags ‘Private’ to True, was able to copied all dependent .dll files to Cache.

Could not load file or assembly 'Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=myKey' or one of its dependencies.

After running an ASP.NET C# application with SQL SERVER version 2012, I get the following error message:
An error occurred during local report processing.
The definition of the report 'C:\inetpub\wwwroot\psla\Reports\PD Listing Report - Per ED.rdlc' is invalid.
An unexpected error occurred in Report Processing.
Could not load file or assembly 'Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
What could be the cause? I have tried searching the net and there are references to version=11.0.0.0 but there are no references to version=12.0.0.0 for 'Microsoft.SqlServer.Types'. Reviewing the reference Manager for visual studio 2015, I was only able to find up to version=11.0.0.0.
In your Package Manager download the 12 version from Nuget
https://www.nuget.org/packages/Microsoft.SqlServer.Types/
Also see that entry for this is backward compatible in web.config
In your references folder right click and set copy local = true
It appears that some library in your project is referencing Microsoft.SqlServer.Types, Version=12.0.0.0 but .NET runtime cannot find it at execution.
On the web server, where the application is running, make sure that there exists a following directory: C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\12.0.0.0__89845dcd8080cc91\
Also make sure that this directory has the file Microsoft.SqlServer.Types.dll of version 12 (12.0.2000.8). Different versions of the file can be downloaded from https://www.nuget.org/packages/Microsoft.SqlServer.Types/

Assembly's dependent Assemblies are not copied

I have a scenario where i have library say for example : SomeLibrary.dll which references to System.Net.Http and System.Net.Http.Formatting just an example with Copy Local flag true, and that assembly is actually consuming some types of these two dlls.
Then i create a new Project and i add reference to SomeLibrary.dll with Copy Local flag true, when use methods of this dll which are internally using the above 2 libraries, the runtime error comes saying:
Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
What i was expecting was it should have dependent assemblies on which SomeLibrary.dll depends should also be in the bin folder copied, which is not happening.
Am i missing something here?
UPDATE:
For your information, i am able to make it work by adding reference seperateely to those 2 dlls but wondering why i need to add seperately if i have reference to SomeLibrary.dll which is dependent on those 2 dlls.
I just had a very similar sounding problem, where I had assembly A depending on assembly B, and B depended on System.Net.Http.Formatting.dll. For some reason on my build server it wasn't copying System.Net.Http.Formatting.dll so it was missing in the final package it created (though in my case it wasn't in either projects' output folder). It worked fine locally on my development machine and I verified the assembly existing in the same place on the build server as it did on my machine (C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies).
I worked-around the problem with this answer to the related question, which was to switch to using the Microsoft.AspNet.WebApi.Client NuGet package to pull in that assembly explicitly. Unfortunately I'm still not sure what the problem was.

Assembly reference resolves to different path than what was specified

I'm trying to reference Oracle.DataAccess.dll in my c# project assembly. When running the project I get the following error:
Could not load file or assembly 'Oracle.DataAccess, Version=2.112.2.50, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I'm really confused because when I right click references and add an assembly I navigate to a copy of the dll that I have in a folder contained within the project and add the reference. When I look at the properties of the reference, though, it shows a path of
C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\Oracle.DataAccess.dll
and sure enough there is a dll in there by that name, but it's an old version. Why does this reference not point to the path that I specified when adding it, and how can I get it to use the dll at the location that I specified?
We take a couple of steps to resolve issues like this when we know that the specific version does not matter to the built application:
1) In the properties for the reference within the project, ensure the Specific Version property is set to False.
2) Save the project, the edit it in notepad or the text editor of your choice. Find the DLL reference and remove all version and key information and ensure the hint path points to your copy of the file. For example:
<Reference Include="Oracle.DataAccess">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Assemblies\Oracle.DataAccess.dll</HintPath>
</Reference>
Visual Studio can be a bit flaky when it comes to references. Many times we have to just edit the project file directly. Setting the properties of the reference directly doesn't always stick. Right-click your project, select Edit Project File, and make the change there. It should stick.

Sql Server CLR load assembly failed

I am trying to deploy an CLR TVF (table value function). In the code I am using JavaScriptSerializer to parse some JSON string, so I reference the System.Web.Extensions dll and my problems start there.
Project builds fine, but when I try to register the dll I receive the following error:
Assembly 'my_assembly_name' references
assembly 'system.web.extensions,
version=4.0.0.0, culture=neutral,
publickeytoken=31bf3856ad364e35.',
which is not present in the current
database. SQL Server attempted to
locate and automatically load the
referenced assembly from the same
location where referring assembly came
from, but that operation has failed
(reason: 2(The system cannot find the
file specified.)). Please load the
referenced assembly into the current
database and retry your request.
I referenced system.web.extensions from:
C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Extensions.dll
I can set copy load to true or manually copy the assembly but then referencing errors go deeper -
Assembly 'my_assembly_name' references
assembly
'system.servicemodel.activation,
version=4.0.0.0, culture=neutral,
publickeytoken=31bf3856ad364e35.',
which is not present in the current
database. SQL Server attempted to
locate and automatically load the
referenced assembly from the same
location where referring assembly came
from, but that operation has failed
(reason: 2(The system cannot find the
file specified.)). Please load the
referenced assembly into the current
database and retry your request.
Everything works fine until I reference the Web.Extensions.dll. Target Framework is .NET 4.
Any ideas/solutions?
Acording to the documentation, any .NET assembly can be referenced but each dependant assembly must also be registered in the database (visible in the "Programmability - Assemblies" node in SQL Server Manager).
Once the SQL Server Database has the dependant assemblies available they will be present in the Add Reference Dialog window in Visual Studio.
This SQL code below works. I had needed the System.Web.dll assembly
(you need the correct version my 2005 SQL is 64 bit)
CREATE ASSEMBLY [System.Web] AUTHORIZATION dbo
FROM 'c:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\System.web.dll'
WITH PERMISSION_SET = UNSAFE
The system will try to automatically register dependent assemblies but can only do it from the same directory as the file you are attempting to register.
In my case it also registered the following assemblies in the database for System.Web to operate correctly...
System.Configuration.Install
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.EnterpriseServices
System.Runtime.Remoting
System.Runtime.Serialization.Formatters.Soap
System.ServiceProcess
System.Web.RegularExpressions
System.Windows.Forms
My system is using 3.5 Framework so I cannot test importing System.Web.Extensions.dll for you but it may require other assemblies from another folder to register, and since it is a 4.0 assembly it may be referencing some 2.0 or 3.5 assemblies that are in a different folder.
I suspect you will end up with a rather large list of assemblies imported to get it to work but it is definitly possible to do.
The operation can probably be done more easily by having one folder with all the dependent dlls in it and register from there.
Sadly integration of the .NET Framework CLR with SQL Server 2005 / 2008 is only a limited subset of the framework and the System.Web.Extensions doesn't seem to be a supported assembly / namespace.
For a full list of supported assemblies check out MSDN: http://msdn.microsoft.com/en-us/library/ms403279.aspx

Categories

Resources