Could not load file or assembly, newtonsoft.json - c#

I have a c# console application that is using JSON and it works fine when run on my development machine. When i try to move the application to another machine to run it i get the following exception when it comes to the part of my code which requires json:
Could not load file or assembly, newtonsoft.json 4.5.0.0
I presume i need to download/install this on the machine i want to run the application on. How would i go about doing that?

Download the Newtonsoft.Json.dll from http://json.codeplex.com/releases/view/107620 and place it in application's BIN folder.

Locate the missing assembly in the solution explorer (under references), right-click and select properties, then select
copy local: true
and the dll will be copied to your output folder and should be distributed with your program.

Related

Visual studio: Build action=Content causes error for dll file

I am trying to build a project in C# which uses some unmanaged dll files (MSVCRT.DLL, DFORRT.DLL, ...). There is no direct reference to the MSVCRT.DLL file in the project(this file is referenced by another dll and not directly by my program)
I want this dlls to be copied to bin directory. if i set build action to Content i get this error on run time:
The procedure entry point _wcstoui64 could not be located in dynamic link library msvcrt.dll.
Which is weird. I cant use other build actions because i want my dlls to be published too(Build action=None wont cause any error but doesn't let me to publish my dlls)
If i completely remove all references to all the dlls and treat them like data files, or pictures(files that are not used in code but should be copied to the output) again i get the same error.
What is causing the problem? how can i publish my dlls?

add reference to msvcr90.dll in .net project

One of our self hosted customer, do not have the public installation of msvcr90.dll. In order to make our app work on their machine, after each deployment we manually add msvcr90.dll and Microsoft.VC90.crt file in our app folder. and this requires a restart of the machine. is there a way I can add these two files in the project and make my project reference these files? I tried adding msvcr.dll in the project but I am getting following error:
"A reference to msvcr90.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."
I have that problem before same as yours but all i do is, Set the project to run as Administrator account and inside of the project, i manually code to copy the dll in system32 folder and it worked fine.
All DLL's can't be added into VS project. It depends on what framework, versions of DLL's came from. If not meet the requirements then VS project won't accept on it.

C# Web Api/ MVC.net not loading assemblies properly

I'm new to C# and .net in general, and I need to use it to work with the SDK for a major piece of software we use.
I can add the assemblies they tell me to add in a console application and everything works fine. When I try to add them to any web application (either MVC or WebAPI), I keep getting errors saying other assemblies are missing. Eventually I just added every assembly/reference (not sure the correct term for this, pretty much just .dll files) in the sdk folder and now it is working. This definitely cannot be the correct way to do this.
Is there something I am missing that allows assemblies/references to load other assemblies/references, or is something else the cause of my issue?
UPDATE:
The exceptions are usually something like this:
Could not load file or assembly 'Server, Version=1.5.1.0, Culture=neutral, PublicKeyToken=d11ef57bba4acf91' or one of its dependencies. The system cannot find the file specified.
And it does not occur during build, only when the function is actually being called from the web application( in my case, since it's an api, when I visit the URL that returns my JSON data)
You can use a tool called "IL Disassembler" that is installed along with Visual Studio to see what other dependencies the SDK's Assembly depends on.
The install location may vary but mine is here...
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\ildasm.exe"
Drag and drop the SDK's assembly that you are using onto the tool and click the manifest field. A dialog will open with the other assemblies that you'll need to include.
If your console application works but the web application does not then the exception should specify which assembly is missing.
Compare you console output directory with the output directory of you web build. Make sure the dll that is required is being deployed to the web directory you are running.
In visual studio with your web project find the assembly under references and select it. Make sure that the property "Copy Local" is set to TRUE.

How to include SharePoint assemblies in EXE after publishing

I have developed a simple .EXE in Visual Studio 2015, which adds an item to the specified SharePoint site and List when the user runs some process.
The file is saved in a shared network drive, and everything seems to work perfectly except for one detail.
I can't seem to work out how to run the EXE without having the following .dll files saved in the same folder:
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.dll
If I move these from the folder in which the EXE is saved in, I get this error message when running the exe:
Unhandled Exception: System.IO.FileNotFoundException: Couldt not load file or assembly 'Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral ... Or one of its dependencies ...
I (think) I have set up 'strong named assembly' by following these instructions in VS for the app, and I was able to add the SharePoint dlls to the GAC by using the VS command line and gacutil.exe (with a successful confirmation message), but I am still unable to run the EXE without having the 2 .dll files present.
Note: I developed the app to target .NET-4, but the users will be accessing the files from a system with .NET-3.5 installed, however the server on which the EXE is saved on does have the .NET-4 environment.
I was able to achieve this by using a tool called ILMerge which can be found here and is available as a NuGet package.
ILMerge allows you to merge dlls and exe files into a single exe

Unable to install or run the application....in Desktop Application

I had developed a Desktop Application in .Net. I had published and deployed it in my Client's System. But while my client running that setup, an error message is displayed :
Unable to install or run the application. The application requires that assembly Microsoft.SqlServer.Diagnastics.STrace Version 10.0.0.0 be installed in the Global Assembly Cache (GAC) first
What should I do for this ?
Open project Properties form Solution explorer in visual studio
Properties->Publish -> Application Files
In Applications Files window check Show all files at the right bottom. change publish Status of "Microsoft.SqlServer.Types.dll" "Prerequisite(Auto)" to Include click ok and publish Application.
Probably, this dll is not present in Global Assembly Cache.
you can add an assembly to GAC by following command:
GACUTIL –i <Path to Microsoft.SqlServer.Diagnostics.STrace.dll>
to find if STrace.dll file is present on your client computer, you can search it with this command line:
dir Microsoft.SqlServer.Diagnostics.STrace.dll /s
if the file is found, use the previous anwser command line to add the dll to the global asembly cache
If not, you have to add this file as prerequisit in your deployment project
if you have a setup project (lik installshield / MS setup project / Clickonce project, the prerequisit can be added on your setup project properties.
when you add a prerequisit, you should be able to choose if the prerequisit has to be packaged with your application or downloaded from the publisher site.
What solved my problem was I had to do what #ShahidRaees did except include all of the assemblies. I selected all of them except for the file ending in .pdb.
Selecting all of them should automatically update the GAC when you install the program, but I'm not 100% sure.

Categories

Resources