I'm making a programm on C# language and i'm using a special Dll file where storing class with methods that i'm using. At the project i added Dll file as a reference and then print using "library_name" at the code. It's perfectly work on my computer where i'm making it (where is visual studio) and it's also great working on another computer. But my program didn't working at virtual machine that located on second computer. When i'm trying to open it i had an exception like:
"Could not load file or assembly 'spd_lib, Version=1.0.4244.21567, Culture=neutral,PublicKeyToken=null" or one it's dependencies. The system cannot find the file specified."
Somewhere i read that .csproj file had a string where storing all the project's references, so i tried to modify it and give absolute path to the library that located on virtual machine, but it didn't working anyway and had the same exception. Can you please recommend me something to do with it ?
Forgot to say, that my program is on WInForms, so it's perfectly opening and working on virtual machine, but when i press button (there is event where i declare an object of class that located at Dll file) it's had exception and crashed. So, i'm afraid it's not .Net framework problem :/
The virtual machine where you are hosting the application, does it have .Net framework installed?
There are system dlls which are installed in your machine as you have visual studio installed, but the virtual machine might be missing those.
The dll has to be present on the Virtual machine in order for your program to work. To do it you have to mark it as Copy Local in the Visual Studio Preferences window for this particular dll (press F4 when your reference is selected) - when you do it it will be copied to the bin folder (or to any other folder when you Publish your application).
If it doesn't work you need to check from where the application requests this file. For this task you can use fuslogvw or just check it with Process Monitor.
Related
So I have a C# project and I'm trying to add USB functionality to it via the Silicon Labs CP2112 USB to i2c bridge. They provide drivers as 2 .dll files: SLABHIDtoSMBus.dll and SLABHIDDevice.dll (which apparently is needed at runtime). I've also found a SLABCP2112.cs file that is supposed to allow the dll to be used in C#.
I've added the SLABCP2112.cs to my project successfully and Intellisense recognizes the functions. The problem is that when I run the program it always throws an exception that the SLABHIDtoSMBUS.dll is not found(System.DllNotFoundException). I've tried moving the dll to various locations such as the main project folder, the 'USB' folder in the project where I've included the SLABCP2112.cs, the Windows SysWOW64 folder and finally in the c#'s projects 'bin' folder.
Placing it in the bin folder still throws an exception but changes the error to a bad image error or something similar. For good measure I've tried to add the .dll's as References in the project but this causes an error "invalid or unsupported type".
I'm assuming the problem is still that the compiler doesn't know where to look for the dll files, so where should I put them? Or if not, how do I get this working?
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.
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
I made a WPF program which uses SQLite. And by using Visual Studio 2012, it generates both Debug and Release version exe file. When I go to Debug or Release directory and run my exe file, e.g. MultiStart.exe, it can run normally.
But if I copy the MultiStart.exe to my Desktop and try to run it, it failed.
By several tests, I found that I also need to copy files MultiStart.exe.config and System.Data.SQLite.dll to my Desktop. And then it can run now.
But why? Do we have better solution so that I can make it run without addition files?
Thanks!
Why my WPF program cannot run without Visual Studio?
The question title is not really accurate since it's not really related Visual Studio. MultiStart.exe is dependent on configuration (MultiStart.exe.config) as well as other assemblies (System.Data.SQLite.dll). Without these dependencies the application cannot run (because that is how .NET works).
WPF doesn't necessarily need a config file to run so the question is what is in your config file that the application needs. It might be possible to move this configuration information into the code (e.g. connection string) and remove the app.config but then the values will be hard coded in the application.
In terms of dependent assemblies, instead of deploying them it is possible to embed them as resources and then use the AppDomain.AssemblyResolve Event to read the assembly from a resource (see Embedding assemblies inside another assembly for an example).
Another approach instead of embedding assemblies as resources is to merge them into one assembly. ILMerge is a popular choice for merging assemblies but I read that it can have issues with WPF assemblies (not sure if that applies to you). See Merging dlls into a single .exe with wpf for some other ideas for merging assemblies with WPF.
Note that setting PATH variables does not work because .NET does not use the PATH for resolving assemblies -- see How the Runtime Locates Assemblies for the details.
Another, option instead of copying the MultiStart.exe to the desktop is to use a shortcut on the desktop that links to the appropriate directory. Perhaps that is a simpler solution
You can also use ILMerge to merge all dependencies into single .exe file to simplify distributiuon of your application.
More detaiils on ILMerge can be found here: ILMerge on CodeProject
Example of usage: ilmerge /target:winexe /out:YourDestinationApp.exe
YourCurrentProgram.exe System.Data.SQLite.dll
Better solution that i used to do with my windows form apps is, Copy the entire folder, which contains supporting files. place it where you want. then create a shortcut of your .exe on your desktop. That always worked for me.
Because you are missing some dependency. You can open your config file and set the dependency...but I wouldn't recommend you to change config file manually.
You can also copy the dependent dll in system32 folder. ..but its only a trick because exe first search dlls in current folder than system 32 folder.
Because you're missing things from your PATH. Visual Studio is probably set to copy DLLs to the target directory on build.
You're almost certainly pulling in external libraries. Some of these are part of .NET, while others are packaged in libraries in specific folders. When you start your exe, it looks in your PATH and the current folder for everything (which includes all DLLs Visual Studio copied).
When you moved the exe to the desktop, suddenly it had no idea where those DLLs are. You haven't specifically added them to your PATH, and they are no longer in the current folder. This is why copying those DLLs to your desktop magically made them work.
Unless you stop use SQLite, there is not a way for you to not need that DLL (there are lots of ways to package/reference it though).
I have a WPF application . While building it I am getting the following error:
Could not load file or assembly or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Application is trying to load the assembly from virtual drive (as debug Folder)
Ex: [subst r: c:[my Assembly bin pth]
Earlier I was mounting c:\bin as a netwwork drive and was getting te following error.
This assembly may have been downloaded from the Web. If an assembly has been downloaded from the Web, it is flagged by Windows as being a Web file, even if it resides on the local computer. This may prevent it from being used in your project. You can change this designation by changing the file properties. Only unblock assemblies that you trust. See http://go.microsoft.com/fwlink/?LinkId=179545 for more information.
Edit:
I am not able to find the Unblock button in properties window by the way.
Clear out the temporary framework files for your project in:
For Windows 7, the path is:
C:\Users\[username]\AppData\Local\Temp\Temporary ASP.NET Files\
For 64 bit systems with 'Framework' in the path the full path is:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\
http://www.solutioncottage.com/ShowSolution.aspx?solID=59
Removing all temp files from the path below still works, it saved my development site hosted on a web server from (HRESULT: 0x80070057 (E_INVALIDARG))
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\
On Visual Studio 2019 I was able to fix this manually deleting the ".vs" folder into the solution directory.
Thanks
this happened to me when i got a blue screen while building.
i had to delete my packages and bin folders, and get then from TFS
at that time i had nothing in the following location...
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
to resolve i set Visual Studio in debug mode and then monitored the above directory. i deleted the files as they appeared and then the app started working again.
time to start looking for a new Dev machine.
For the Error which you were getting when you were mounting is due to blocking for Assemblies/DLL. Right click on what ever DLL's you have downloaded and you will get an option to unblock it .
For the Could not load file or assembly or one of its dependencies error, put a breakpoint in the constructor of the starting class and check it is failing due to what.
I was encountering this problem after a windows 8 blue screen error while building my wcf service. I tried all suggestions above.. but it didn't solve the problem.
Lastly, I removed and recreated the new application from IIS on the same wcf project.
Then every thing works fine.
Quoting this SO answer:
This can happen while referencing COM wrapper dlls.
Go in your Visual Studio Project, under References, select the referenced COM wrapper assemblies, right click, preferences, and make sure that Embed Interop Types and Specific Version are both set to False.
#Ernest 's answer worked for me on Visual Studio 2022
On Visual Studio 2019 I was able to fix this manually deleting the ".vs" folder into the solution directory.