Path Issue Causing System.IO.FileNotFoundException - c#

I added a solution to my project, just for unit tests (NUnit)
I have included references to all of the dlls the test solution needs
but..
I am getting the following file not found error:
System.IO.FileNotFoundException: Could not load file or assembly '\bin\Debug\bin\aLibrary.dll' or one of its dependencies. The system cannot find the file specified.
The issue is that on build, all of my dlls are correctly getting placed into
MySolution/bin/Debug , which is what I have the path set to in the project properties, but the error is telling me that the application is looking in MySolution/bin/Debug/bin
The solution settings show the correct path
If I copy those dll files from MySolution/bin/Debug to MySolution/bin/Debug/bin all works as expected.
Question
I have no idea where the path is being set. How do I correct or where should I look? Any ideas are welcome.
Thanks
Thanks

Right click on the project, go to properties, reference paths and check if you need to change the path: more described here: https://msdn.microsoft.com/en-us/library/ayds71se(v=vs.120).aspx

Related

How can I change path for packages folder for MsBuildTasks in module FormAndList (aka UserDefinedTable)?

I'm trying to make DNN module FormAndList (aka UserDefinedTable) to compile while I included it's project into solution, which is placed in different directory (3 folders up). And I edited MSBuild.Community.Tasks.Targets file so that it would find correct path to library MSBuild.Community.Tasks.dll. And it works for Debug mode, but when I compile it in Release mode it gives me this error:
The "MSBuild.Community.Tasks.XmlRead" task could not be loaded from the assembly D:\Projects\SolutionFolder\Host\DesktopModules\UserDefinedTable\BuildScripts\MSBuild.Community.Tasks.dll. Could not load file or assembly 'file:///D:\Projects\SolutionFolder\Host\DesktopModules\UserDefinedTable\BuildScripts\MSBuild.Community.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> 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.
I compared both MSBuild.Community.Tasks.Targets and ModulePackage.targets files with another module, which works perfectly, but I didn't find any crutial difference between them.
Problem is that during compilation it tries to find MSBuild.Community.Tasks.dll iside folder where build scripts are, but it should search for it in D:\Projects\SolutionFolder\packages\MSBuildTasks.1.5.0.235\tools.
I already edited all places that I found with path's in .csproj and MSBuild.Community.Tasks.Targets but it works only for Debug mode. What am I missing?
In your projects you have something like:
<Import Project="..\..\..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\..\..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
and
<Import Project="packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets')" />
I don't think you need those lines.
also try to use:
<MSBuildCommunityTasksPath>$(SolutionDir)\packages\MSBuildTasks.1.5.0.235\tools</MSBuildCommunityTasksPath>

Could not load file or assembly (run-time error)

I placed a dll file in the bin folder of a class library project and added a reference to it. Added namespace but when I am creating object of a class of this dll it is giving me run time error -
Could not load file or assembly 'dll name' or one of its dependencies. The system cannot find the file specified.
I tried using the below code to load the dll:
Assembly MyDALL = Assembly.LoadFile("Test.dll");
Type MyLoadClass = MyDALL.GetType("Test.Class1");
object obj = Activator.CreateInstance(MyLoadClass);
Now it looks for its dependent dll in given error again.
Any solution to this?
You should try to load the .dll from the directory you are running your application in. You can get that from code using:
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
Note that if you put your .dll in the /bin directory, it might get overwritten next time you compile your application.
You might be better off including it into the project, and then marking it for output by right clicking it in the Solution Explorer, selecting Properties, and setting Copy to Output Directory to Copy Always or Copy if newer.
That way it will be published to your /bin directory automatically.

Could not load file or assembly Telerik.OpenAccess

I added references to telerik dlls in the codeBut, when I am building the project I am receiving an error randomly.
Error1Unknown build error, 'Could not load file or assembly'Telerik.OpenAccess, Version=2015.1.220.1, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342' or one of their dependencies. Can not find the file specified.
I am not using openaccess assembly at all. I have no idea why this keeps coming randomly. I am not even able to find the dll anywhere to add it to the project.
Kindly help me fix this issue.
For me (and after searching around, for many others) this was due to dll files erroneously remaining in the bin folder, even after cleaning the solution. In my case the dlls were somehow left over while switching from one git branch (which included some dlls that depended on Telerik.Openaccess) to another.
I manually cleaned out my bin folder and rebuilt my solution and the problem went away.
The same problem is discussed in the Telerik forums: https://www.telerik.com/forums/unable-to-build-the-application-after-adding-telerik-references.
What you can do is to:
delete the contents of the licenses.licx file and save it.
delete any references to the Telerik.OpenAccess.dll in the project. If needed edit the solution file of the project in a text editor and remove the reference from it.
Last but not least delete your VS and .NET cache - Clean Up ASP.NET and Visual Studio Cache and Temp Files

System.IO.FileNotFoundException Reference not found on when run on users computer

I am making a program in C# with Visual Studio Express 2013. I am using Ionic.zip (dotnetzip). When i run it from the .../bin/release directory or from Visual studio, it runs perfectly fine. when the end user has it on their computers, or I run it from another location, when it tries to perform an action using ionic.zip, it crashes with the following exception
System.IO.FileNotFoundException: Could not load file or assembly 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c' or one of its dependencies. The system cannot find the file specified.
File name: 'Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c'
I have absolutely no idea how to fix this, and have been researching for the last 3 days how to with no success. Any help will be appreciated.
Thanks,
James
CHeck dependencies - either directly, or possibly a not installed framework reference. If the assemblz is in the search paths if should be found.
You need to have an installer or script copy the DLL to the executing directory(where the executable is) or into the computers PATH.
First include that file in your resources after that in its properties:
Select Build Action -> Content
Copy to Output Directory -> Copy if newer
I am attaching a picture. Now you can access its correct path as follows:
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\Resources\\yourfile.exe";

How to find out where my error is coming from?

I have an annoying error that's been popping up, and I don't know where it is coming from. The error is:
Error 31 Unable to copy file "app.config" to "bin\Debug\Framework.Tests.dll.config". Could not find file 'app.config'. Framework.Tests
The problem is, I don't have a bin\Debug folder anywhere, and it does not say from where it is trying to copy app.config. Double clicking on the error doesn't bring me to any code where it is trying to copy, so that doesn't help me either. So I don't know where I should make the app.config.
How can I find this out?
You have added a reference to a file called app.config or Visual Studio did this for you. The file does not exist on the disk, presumably because after adding the reference you later deleted the file.
Search for the missing file in your Solution Explorer, and either delete the reference or create the file.
It is most likely in the root folder of one of your projects, and should have a yellow triangle warning icon showing that the file is missing.
In an MSTest project the app.config is the one that you would like to provide any calls to the ConfigurationManager class.
It resides in the root of your test project.
The bin\debug folders will be created once the project compiles for the first time. Show all files in the solution explorer should help as they are not (and should not) be included in the project.
HTH
You probably do have a bin\Debug folder beneath your project folder, being the build target folder created by Visual Studio when you build your project for the Debug configuration.
My guess is that something (a test framework perhaps) still has the DLL file loaded, so Visual Studio can't delete and replace the existing Framework.Tests.dll.config file with the contents of your app.config. [Note: the project build action for app.config files is to copy it to the target folder renamed to match the executable with an extension of .config appended.]

Categories

Resources