The debugger keeps giving me this 'System.IO.FileLoadException' error message in the output window of Visual Studio everytime I call the toJSONString() method in a dll assembly I had created earlier. See method below. I used NuGet to load and reference the newtonsoft-json.dll library, so why a runtime attempt keeps failing is beyond me.
Object output;
...
public String toJSONString()
{
String strOut = "";
if (output != null)
{
strOut = JsonConvert.SerializeObject(output);
}
return strOut;
}
In the Solutions Explorer window, under References, I checked the path for Newtonsoft.Json which is C:\temp2\DataTables_Examples\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll. That dll file does exist there. I don't know why the app doesn't see it? Any help would be appreciated.
It may be an issue with your package versioning.
Try this solution presented for someone with a similar error.
Have you any software opened, that is viewing the library or a folder of it?
(like NotePad++ or whatever) Also it would be better, if you include the package directly in your project. Maybe you should try to find out, if the file exists for your studio(https://msdn.microsoft.com/en-us//library/system.io.file.exists(v=vs.110).aspx).
(example from the page)
string curFile = #"c:\temp\test.txt";
Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");
Maybe this link also helps, to check your (studio)acces rights:
Checking file/folder access permission
Related
I am currently dealing with the error word for word:
Assemblies 'C:\Users\Jake\Desktop\AudioFileSorter\AudioFileSorter\obj\Debug\Interop.QTOControlLib.dll' and 'C:\Users\Jake\Desktop\AudioFileSorter\AudioFileSorter\libs\Interop.QTOControlLib.dll' refer to the same metadata but only one is a linked reference (specified using /link option); consider removing one of the references.
My references include several files:
AxInterop.QTOControlLib.dll
Interop.QTOControlLib.dll
Interop.QTOLibrary.dll
Interop.Shell32.dll
taglib-sharp.dll
These files are all located and referenced from a folder called libs within the base location for my project: AudioFileSorter\AudioFileSorter\libs\
An additional control reference was included as the Apple QuickTime Control 2.0 from the COM references. With the exception of this reference all other references were added by right clicking 'References' in the Solution Explorer and clicking 'Add Reference' and then browsing the libs folder to pull dll file.
Obviously, I have no idea what I am doing and I don't know how to solve it. The project worked fine yesterday and after trying to build the project to a release build everything got messed up and now I have this error. I have tried removing one of the duplicate references but then i end up just missing the reference when the app calls it during this code line:
private void SortM4PFiles(string[] files)
{
WriteLine("Begin compiling .m4p files...");
foreach (string file in files)
{
axQTControl1.URL = file;
// Create new movie object
QTOLibrary.QTMovie mov = new QTOLibrary.QTMovie();
mov = axQTControl1.Movie;
string title = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationFullName];
string artist = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationArtist];
string album = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationAlbum];
songs.Add(new Song(title, album, artist, file));
songs[songs.Count - 1].setType(".m4p");
WriteLine("Evaluated " + title);
}
// Make sure the previous .m4p is not in use
// This will prevent an IOException when the file is in use and cannot be moved
axQTControl1.URL = "";
}
Any help or explanation would be greatly appreciated. Thank you.
This was the tutorial for using the QuickTime control and reading m4p and m4a metadata.
I was trying to convert one project from packages.config to PackageReference... & I got this issue. After looking into it, I realized that, there are two references added for the same dll.
How? One from nuget & one from local COM dll. I had remove one reference to fix the issue.
I started running into a small problem regarding debugging my program. It would start off showing no errors, then I would press debug to test it. It would throw me an error saying
"Could not copy the file "obj\x86\Debug[programName].exe" because it was not found."
I have proceeded to tamper with various things, and came to the conclusion that it was a class that I am using to read ini files by importing a dll. The two most likely lines in that class are these:
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
To test this, I removed the class and all references from the project, and it would build the project successfully. Then, I could look at the path and find the executable that was previously missing. Thinking the problem fixed, I put the class back in and as you would expect, it broke with the same error. It actually deleted the executable file before building, so in my head, it is obvious why it couldn't be found.
However, the not so obvious part is: The program was building and executing with this class in it up until this morning with no changes performed on it. Plus, the class works perfectly inside of my Unity3D game where it is reading the ini file this c# program creates.
Can anyone tell me why this is happening, and if there is a fix to it? I already tried creating a new project and re-importing everything, and it produces the same errors.
EDIT
After commenting and uncommenting each line, I found that the three commented lines in this are causing the problem:
public bool SaveToIni()
{
IniFile file = new IniFile("/LoadUpSettings.ini");
try
{
file.IniWriteValue("Screen", "Screen Height", cbbScreenHeight.SelectedItem.ToString());
file.IniWriteValue("Screen", "Screen Width", cbbScreenWidth.SelectedItem.ToString());
//file.IniWriteValue("Controllers", "Razer Hydra", ckbRazerHydra.Checked.ToString());
//file.IniWriteValue("Controllers", "Oculus Rift", ckbOculusRift.Checked.ToString());
//file.IniWriteValue("Screen", "Fullscreen", ckbFullscreen.Checked.ToString());
return true;
}
catch
{
MessageBox.Show("Please fill out all values");
return false;
}
}
This is the IniWriteValue function inside the IniFile class.
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
Oddly enough, if i remove the ckbRazerHydra.Checked.ToString(), and put in a standard string such as "True", it still doesn't work, although with those 3 lines commented out, the project builds completely.
EDIT
I managed to fix this problem to an extent. I just have to run my program in release version. If I run it in debug mode, I will always get the error saying the exe couldn't be copied because it wasn't found. However, Release mode seems to almost always work.
The bin and obj folders are meant for output only. When you tell Visual Studio to do a clean or a rebuild it will delete all files in these folders. You can safely delete these folders at any time and you shouldn't lose anything in the process.
You are never meant to place any files in these folders. If you want to add an external assembly (EXE or DLL) to your project you should add it to your project using the Add->Existing Item command on a project. Then you can tell your project to reference that file and it will use the local relative path.
For example, if you create a "lib" folder in your project root and place some.dll inside it, you can then add a reference to the file located in your project and it will use the relative path ..\lib\some.dll.
The problem is with files in your current project that you have set to
Copy to output directory=copy always/copy if newer
When you add a file this way VS will delete all other previous files that other projects dumped into your current project bin/.
In order to avoid this situation add the files and leave them with Copy to output directory=Do not copy option and then use MSBuild Copy task to dump your files.
If you are using docker you can simple put a COPY command - the same thing but not with MSBuild.
I believe this is the default behavior of some this MSBuild internal task and a workaround is the only option.
I can't use "Zipfile" class in the name space "System.IO.Compression" my code is :
using System;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string startPath = #"c:\example\start";
string zipPath = #"c:\example\result.zip";
string extractPath = #"c:\example\extract";
ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest,true);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
}
the error is :
The name 'zipfile' does not exist in the current context
How I can solve it ?
You need an extra reference for this; the most convenient way to do this is via the NuGet package System.IO.Compression.ZipFile
<!-- Version here correct at time of writing, but please check for latest -->
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
If you are working on .NET Framework without NuGet, you need to add a dll reference to the assembly, "System.IO.Compression.FileSystem.dll" - and ensure you are using at least .NET 4.5 (since it doesn't exist in earlier frameworks).
For info, you can find the assembly and .NET version(s) from MSDN
For those who are green programmers in .NET, to add the DLL reference as MarcGravell noted, you follow these steps:
To add a reference in Visual C#
In Solution Explorer, right-click the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the components you want to reference, and then click OK.
From the MSDN Article, How to: Add or Remove References By Using the Add Reference Dialog Box.
you can use an external package if you cant upgrade to 4.5. One such is Ionic.Zip.dll from DotNetZipLib.
using Ionic.Zip;
you can download it here, its free. http://dotnetzip.codeplex.com/
Just go to References and add "System.IO.Compression.FileSystem".
In solution explorer, right-click References, then click to expand assemblies, find System.IO.Compression.FileSystem and make sure it's checked. Then you can use it in your class - using System.IO.Compression;
Add Reference Assembly Screenshot
A solution that helped me:
Go to Tools > NuGet Package Manager > Manage NuGet Packaged for Solution... > Browse >
Search for System.IO.Compression.ZipFile and install it
System.IO.Compression is now available as a nuget package maintained by Microsoft.
To use ZipFile you need to download System.IO.Compression.ZipFile nuget package.
I know this is an old thread, but I just cannot steer away from posting some useful info on this. I see the Zip question come up a lot and this answers nearlly most of the common questions.
To get around framework issues of using 4.5+... Their is a ZipStorer class created by jaime-olivares: https://github.com/jaime-olivares/zipstorer, he also has added an example of how to use this class as well and has also added an example of how to search for a specific filename as well.
And for reference on how to use this and iterate through for a certain file extension as example you could do this:
#region
/// <summary>
/// Custom Method - Check if 'string' has '.png' or '.PNG' extension.
/// </summary>
static bool HasPNGExtension(string filename)
{
return Path.GetExtension(filename).Equals(".png", StringComparison.InvariantCultureIgnoreCase)
|| Path.GetExtension(filename).Equals(".PNG", StringComparison.InvariantCultureIgnoreCase);
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
//NOTE: I recommend you add path checking first here, added the below as example ONLY.
string ZIPfileLocationHere = #"C:\Users\Name\Desktop\test.zip";
string EXTRACTIONLocationHere = #"C:\Users\Name\Desktop";
//Opens existing zip file.
ZipStorer zip = ZipStorer.Open(ZIPfileLocationHere, FileAccess.Read);
//Read all directory contents.
List<ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
foreach (ZipStorer.ZipFileEntry entry in dir)
{
try
{
//If the files in the zip are "*.png or *.PNG" extract them.
string path = Path.Combine(EXTRACTIONLocationHere, (entry.FilenameInZip));
if (HasPNGExtension(path))
{
//Extract the file.
zip.ExtractFile(entry, path);
}
}
catch (InvalidDataException)
{
MessageBox.Show("Error: The ZIP file is invalid or corrupted");
continue;
}
catch
{
MessageBox.Show("Error: An unknown error ocurred while processing the ZIP file.");
continue;
}
}
zip.Close();
}
Add System.IO.Compression.ZipFile as nuget reference it is working
The issue here is that you just Added the reference to System.IO.Compression it is missing the reference to System.IO.Compression.Filesystem.dll
And you need to do it on .net 4.5 or later (because it doesn't exist on older versions).
I just posted a script on TechNet Maybe somebody would find it useful it requires .net 4.5 or 4.7
https://gallery.technet.microsoft.com/scriptcenter/Create-a-Zip-file-from-a-b23a7530
I know this question have been asked before. But i have tried the answers in the other questions without any luck. I have removed the Namespacing from the .rpt file reference and also set the build action of the file to be Embedded Resource but nothing helps i still get the same error. The error occurs here:
public override string FullResourceName {
get {
return "RptManifest3.rpt";
} <--------
set {
// Do nothing
}
}
When the code reaches the arrow i get the error. Anybody who can help with this ?
Finally i could solve the problem
just go to the references and choose all the 'dll's starts with 'crystalldesicion' there.
after you choose them all, find the 'Copy Local' property in properties table, now change its value to 'true'.
build the project and save it all.
now its ready to action
Is there a way to find out the assembly name at design-time (i.e. not using reflection or runtime APIs such as System.Reflection.Assembly.GetEntryAssembly) from within Visual Studio?
The scenario requires a tool to get the assembly name that a Visual Studio project will eventually compile into.
This is like parsing the AssemblyName property of the .csproj - I am wondering if there are any APIs that can give this information reliably.
Please do not respond back with runtime APIs that use reflection - there is no assembly file present at the time I need the assembly name - just the metadata of the assembly in the csproj file.
if you are calling the tool via a post/pre-build event, this data is very easy to access.
Just go to the "project properties->Build Events" tab, then select either "edit pre-build" or "edit post-build", depending on when you want the tool to run. This should bring up an edit window with the ever helpful "Macros >>" button. Press this and you will be given a heap of macros to use and should be pretty much everything you need.
The "API" you could use is LINQ to XML after all the .csproj file is just xml. (and you can get the location of the .csproj file if you need from the solution file which for some reason is not XML but can be easily parsed)
You can use "TargetName" available in Macros for Post-build events. It will give you the assembly name for your project.
After a quick run through MSDN I found this article which might be a good start for some further research:
Accessing Project Type Specific Project, Project Item, and Configuration Properties
I think you will need to write some regular expression that will give you the value of "AssemblyTitle" attribute in AssemblyInfo.cs file.
Something like this:
public class Assembly
{
public static string GetTitle (string fileFullName) {
var contents = File.ReadAllText (fileFullName); //may raise exception if file doesn't exist
//regex string is: AssemblyTitle\x20*\(\x20*"(?<Title>.*)"\x20*\)
//loading from settings because it is annoying to type it in editor
var reg = new Regex (Settings.Default.Expression);
var match = reg.Match (contents);
var titleGroup = match.Groups["Title"];
return (match.Success && titleGroup.Success) ? titleGroup.Value : String.Empty;
}
}