Could not load file or assembly or one of its depencencies. The system cannot find the file specified - c#-2.0

I am working to program (that was written by other people), this program is written in C#, using Visual Studio 2010. Almost everything was fine (except some logical problems) until i tried to rum my program in Release mode instead of Debug mode. This program downloads testing modules (PingTest.dll) and runs in when computer is Idle. Debug version stores all files in running folder while Release version "installs" into c:\Users\Macke\AppData\Local\NetMon\ and re-runs from there (all files needed to run are also storred there). So when i run NetMon.exe it crashes. I've added some try/catch and found an error:
Could not load file or assembly 'CountDow_Idle, version=1.0.0.2, Culture=neutral, PublicKeyToken=null' or one of its depencencies. The system cannot find the file specified.
The part of the code that causes it:
AppDomain aDom = AppDomain.CreateDomain("TestingDomain");
Assembly testAsm = null;
using (FileStream fs = File.Open(TMP_MOD_NAME, FileMode.Open))
{
using (MemoryStream ms = new MemoryStream())
{
byte[] buffer = new byte[1024];
int read = 0;
while ((read = fs.Read(buffer, 0, 1024)) > 0)
ms.Write(buffer, 0, read);
testAsm = aDom.Load(ms.ToArray());
}
}
INetMonTest iTest = null;
foreach (Type type in testAsm.GetExportedTypes())
{
if (type.BaseType.FullName == "CountDown_Idle.INetMonTest")
{
try
{
iTest = (INetMonTest)aDom.CreateInstanceAndUnwrap(AssemblyName.GetAssemblyName(TMP_MOD_NAME).FullName, type.FullName);
}
catch (Exception ex)
{
MessageBox.Show("AppDomain creation failed:\n\n" + ex.Message);
}
break;
}
}
I've allready looked for correct versions (in AssemblyInfo.cs file)
So maby anyone could help me.
Thanx in advance

The problem was found! Check names of your project files.
Debug file name is CountDown_Idle.exe, while release file name is NetMon.exe (it is renamed in auto installation). So i tried to run debug version from any place of my computer, it workd but if i changed it into NetMon.exe (instead of CountDown_Idle.exe) it didn't worked.. Now installer keeps the original file name and everything runs great. The thing is that program must be named NetMon.exe and i can't change it (even in program code) that it would work...

Related

Uploading files to Web Application in a sub-dirctory using ASP.NET MVC

I made an ASP.NET MVC web application that is existed in a Sub-Directory. The problem is every time I try to upload file I get this error "Could not find a part of the path".
The code is working perfectly on my local machine and other web apps, so I think the problem is related to the web app being exist in the sub-directory, but I don't know how to solve it.
Thanks in advance.
This is my function
public byte newImage(HttpPostedFileBase newFile, string uploadPath)
{
if (newFile != null && newFile.ContentLength > 0)
{
if (newFile.ContentLength > 3000000) //means file size maximum is 3 MB
return 1; //means the file size is more than 3 MB
var fileName = Path.GetFileName(newFile.FileName);
var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath(uploadPath), fileName);
newFile.SaveAs(path);
return 0; //means file uploaded successfuly
}
return 2; //means no file was chosen
}//Upload New Image
Did you "map" the upload folder properly? You can read more here.
DirectoryInfo yourUploadDir = new DirectoryInfo(HostingEnvironment.MapPath("~/YourUploadFolder"));
I figured out what's wrong. It seems I forgot to add ~ -_-
So if anyone faced this error, first check if you forgot to add ~. I suppose it worked well on my local machine and other web apps because they were on the root, but once it's placed on a sub-directory, We need to use relative path using this tilde ~.

Get current script path or current project path using new test runner

I am porting old vm unittest files using the new test package. Some relies on input files in sub directories of my test folder. Before I was using Platform.script to find the location of such files. This works fine when using
$ dart test/my_test.dart
However using
$ pub run test
this is now pointing to a temp folder (tmp/dart_test_xxxx/runInIsolate.dart). I am unable to locate my test input files anymore. I cannot rely on the current path as I might run the test from a different working directory.
Is there a way to find the location of my_test.dart (or event the project root path), from which I could derive the locations of my files?
This is a current limitation of pub run.
What I currently do when I run into such requirements is to set an environment variable and read them from within the tests.
I have them set in my OS and set them from grinder on other systems before launching tests.
This also works nice from WebStorm where launch configurations allow to specify environment variables.
This might be related http://dartbug.com/21020
I have the following workaround in the meantime. It is an ugly workaround that gets me the directory name of the current test script if I'm running it directly or with pub run test. It will definitely break if anything in the implementation changes but I needed this desperately...
library test_utils.test_script_dir;
import 'dart:io';
import 'package:path/path.dart';
// temp workaround using test package
String get testScriptDir {
String scriptFilePath = Platform.script.toFilePath();
print(scriptFilePath);
if (scriptFilePath.endsWith("runInIsolate.dart")) {
// Let's look for this line:
// import "file:///path_to_my_test/test_test.dart" as test;
String importLineBegin = 'import "file://';
String importLineEnd = '" as test;';
int importLineBeginLength = importLineBegin.length;
String scriptContent = new File.fromUri(Platform.script).readAsStringSync();
int beginIndex = scriptContent.indexOf(importLineBegin);
if (beginIndex > -1) {
int endIndex = scriptContent.indexOf(importLineEnd, beginIndex + importLineBeginLength);
if (endIndex > -1) {
scriptFilePath = scriptContent.substring(beginIndex + importLineBegin.length, endIndex);
}
}
}
return dirname(scriptFilePath);
}

IIS 7.5 issue on reading large CSV files

I have an MVC 4 application that currently reads data from a CSV file (this is based on client requirements, even if I wanted to have a database for it). All is working well when I debug and run it from visual studio. However, when I deploy it on IIS 7.5, it is unable to read large CSV files (currently, the largest i have is around 6000kb). I tried different techniques on reading the files, but it just produces the same result. But small files are being read perfectly.
Here is my code in parsing the file:
using (CsvReader csv =
new CsvReader(new StreamReader(_filePath), false, ';'))
{
while (csv.ReadNextRecord())
{
int fieldCount = csv.FieldCount;
string currentRow = "";
for (int i = 0; i < fieldCount; i++)
{
currentRow += csv[i] + ";";
}
this.AddKYCFolder(this.CreateKYCFolder(currentRow.Split(';')));
}
}
Any ideas on this?
Many thanks!
Thank you for taking time to look into my question. Apparently, there were some methods that uses parallelism (Parallel.For) that is, I suppose, not compatible with my IIS setup. The log4net error logging greatly helped me to find the source of error.

Setting/overriding an app deployment folder

Is there a way to set or override a project deployment folder in Mono for Android? For example, my application right now deploys to /data/data/SolutionEngine/files/.__override__
The nature of the application is that it loads plug-ins using Reflection, and by default it looks in the /Adapters sub-folder from the app root. This is how it works on the desktop and the Compact Framework, so for simplicity we'd like to continue to do the same on Android.
If I have a single solution that has the app and some plug-ins in it, I'd like those files to get deployed in the proper structure when I start debugging.
You could write out the plugins as android assets (see screenshot below). Please Note: You might need to change the extension to .mp3. See here. I didn't have this issue though.
Once you do that, you should be able to get the assets by using the Asset Manager. You can copy them to a different folder or do whatever with them. Here is a sample of reading them into memory and them writing out the name.
const String pluginPath = "Plugins";
var pluginAssets = Assets.List(pluginPath);
foreach (var pluginAsset in pluginAssets)
{
var file = Assets.Open(pluginPath + Java.IO.File.Separator + pluginAsset);
using (var memStream = new MemoryStream())
{
file.CopyTo(memStream);
//do something fun.
var assembly = System.Reflection.Assembly.Load(memStream.ToArray());
Console.WriteLine(String.Format("Loaded: {0}", assembly.FullName));
}
}

How to read resource file from classpath in BlackBerry app?

I need to read a resource file from classpath in my BlackBerry application. The directory structure of my project is pretty common: under src directory there are 2 child dirs, one represents source packages root, another - resources root.
When I try to read any resource from classpath Class.getResourceAsStream method retures null
InputStream rStream = null;
String path = "/res/default_config.xml";
try {
rStream = getClass().getResourceAsStream(path);
} finally {
try {
if (rStream != null) {
byte[] data = IOUtilities.streamToBytes(rStream);
System.out.println(new String(data));
rStream.close();
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
How should I read classpath resource properly?
And have you tried to put xml file directly into src folder and use getClass().getResourceAsStream("default_config.xml"); ?
Actually cannot reproduce.
Tested on simulator 8800 eJDE 4.2.1.
File was placed in src/res/ folder.
I think you specified the path as incorrect way. You just remove the / from the beginning of the path you specified. If you are specifying /. then it will check for you resource folder
Even though it's generated as a COD file for running on the device, the JAR file is also created each build. It might be worth checking to make sure your xml file is being put in the directory that you expect it to be in as you can definitely store resources in sub-directories in your application and retrieve them using getClass().getResourceArStream();

Resources