How to insert DLL into project - c#

It's my 3 day of working with C#, so my question is noobish, sorry.
I wrote small application, which works with System.Web.Script.Serialization, from System.Web.Extensions library. I have add reference to this DLL (it's from GAC).
But after installation of published application, it can not work on systems, where this DLL doesn't exist in GAC.
So I want to build this DLL into my application, to not depend on the existence of DLL.
What have I tried:
Added reference to DLL and turned option "Copy Local" to "True"
Copied DLL to the project folder and create reference to that file
In "Prerequisites" turned on option ".NET 3.5 Framework SP1 Client Profile"
In "Prerequisites" turned on option ".NET 4 Framework Client Profile (x86 and x64)"
And still I'm getting message Could not load file or assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
When in my system application works fine.
Please, tell me, what should I do to compile application with this DLL.
System: Win7 x86, MS Visual C# 2010 Express (I have trial of professional, if it can help, but hope it can be solved in the Express edition too).

System.Web.Extensions depends on System.Web, which is not part of the client profile, you should change your prerequisites

Related

Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

I'm setting up a new project on my dev laptop and when I build the project from Visual Studio, everything goes as expected, but when I do from a powershell script, it returns this:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.CSharp.targets(316,9):
error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly
C:\disk_path\packages\Microsoft.Net.Compilers.2.3.2\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Could not load file or assembly 'Microsoft.Build.Utilities.Core,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly
and all its dependencies are available, and that the task contains a
public class that implements Microsoft.Build.Framework.ITask.
[C:\disk_path\Code\Client.Models\Client.Models.csproj]
C:\disk_path\packages\Microsoft.Net.Compilers.2.3.2\build\Microsoft.Net.Compilers.props(13,5):
error : Microsoft.Net.Compilers is only supported on MSBuild v14.0
and above [C:\disk_path\Code\Client.Models\Client.Models.csproj]
The most frustrating thing is that my colleague that has exactly the same dev laptop (from prerequisites perspective), has no problem with it. Any hints that can help me sort this out are more than welcome.
*disk_path is not the actual name of the folder, but the path on the disk in which I have the code
Open the Visual Studio Installer (in VS 2019 you can open it from the Tools menu with the "Get Tools and Features..." option). Then choose to install the .NET development tools that you need. For example Microsoft.Build.Utilities v2.0 is in .NET 3.5, and Microsoft.Build.Utilities.Core v14.0.0.0 is in .NET 4.0.
Different versions of Visual Studio will have various versions of the .NET SDK preinstalled.
I had to install MS VS 2017 (I had only VS2019 installed on my machine). That's it.

From where does the System.ComponentModel.Composition.dll is being referred in my system?

I have a C# project that generates some.dll and it references a bunch of DLLs, one of them is System.ComponentModel.Composition.dll which is found under C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0.
I built some.dll and deployed on a Windows XP system. The application that uses this some.dll runs normally. But when I try to look for the System.ComponentModel.Composition.dll under C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 on the Windows XP system, I could not find it.
I just want to understand how the application is running properly.
The reason why I want to understand it is, I built the some.dll in a different system and deployed on another Windows XP system. When I try to start the application, the application crashes with error:
Exception ::Could not load file or assembly 'System.ComponentModel.Composition.resources, Version=4.0.0.0, Culture=en-NZ, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
The reference assemblies are used at compile time. Usually, as here, to refer to assemblies that are installed as part of the .NET Framework. Which will place these assemblies somewhere under either C:\Windows\Assembly (for the GAC) or C:\Windows\Microsoft.Net.
It would tend to suggest in this case that the machine with the component missing does not have the correct version of .NET installed.

Could not load file or assembly System.DirectoryServices. This assembly is built by a runtime newer than the currently loaded runtime [duplicate]

I have downloaded published (code behind files are no there, combined with dll in bin folder) web application from Window Server 2008 where it is hosted, and open it with Visual Studio when I debug that application it shows following error:
"Could not load assembly because this assembly is built by a runtime newer than the currently loaded runtime"
I don't know how can I solve this problem and test application locally.
Please help me.
This errors happens when the DotNet framework you are using is of older version than the one used to build the assembly. You need to check which version of framework is used to build those assemblies and then use the same or higher to debug too.
I was getting this same error when running an installer for a Windows service, even when running the installer on the PC the installer was built on.
It turned out that although the Windows service project had been updated to .NET 4.5, the Setup project that was making the installer was still set to use .NET 2.0.
To check if the Setup project is using an older version of .NET than the project to be installed, in the Visual Studio Solution Explorer:
Expand the Setup project;
Under the Setup project, expand Detected Dependencies;
Under Detected Dependencies select Microsoft .NET Framework and check the Version property. Select the appropriate .NET version from the dropdown list;
Re-build the Setup project to create a new version of the installer.
This error can have a lot of other reasons, too. I had the same problem, and nothing helped until I stumbled across this:
TlbExp.exe error:This assembly is built by a runtime newer
I just ran into this issue when the assembly was built with a target framework of .NET 4, and v4.0.30319 was installed on the server, and other 4.0 apps were running successfully.
The problem arose because the app had originally been built targeting 2.0, and new 4.0 assemblies were pushed, but not the app.config file, which we generally update separately.
This means the supportedRuntime attribute was not updated in the config and caused the error. Adding the following to the app.config fixed our issue:
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
One the the assemblies reference in the project might be built using a newer version of .net, check version of every assembly reference and correct accordingly.
Also check the application pool that this web site is running as. It could be framework 2.0 default on some older windows servers. Change it to framework 4.0.

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.

Reference Component could not be found

i'm trying to develop an application but then these warnings popped out. I have tried disabling my anti-virus (Avira) but it still won't work.
Warning 1 Resolved file has a bad image, no metadata, or is otherwise inaccessible. Could not load file or assembly 'MyAssembly.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. ConsoleApplication1
Warning 2 The referenced component 'MyAssembly' could not be found.
Can anybody please help me? Thanks!
What .NET runtime version is your application being developed with?
If the error is to be trusted, your project is say a .NET 3.5 (2.0 runtime) project but the MyAssembly library is developed in .NET 4.0 resulting in the error you see.
You cannot reference newer runtime version assemblies in an older runtime version project. You'd have to "upgrade" your project to at least match the framework version of the assembly given to you.
Right click on your project file and choose properties. Depending on what version of Visual Studio you are using this screen may look different, but go to the application tab and see what the target framework is.
Then go to the assembly you referenced in your references and check the "Runtime Version" in the properties section:

Categories