In my application, i have some zip files:
It is present in the Resources.Designer.cs:
internal static byte[] ContactDocuments
{
get
{
object obj = ResourceManager.GetObject("ContactDocuments", resourceCulture);
return ((byte[])(obj));
}
}
I have this code to extract the file tp c:\temp:
File.WriteAllBytes(#"C:\Temp\ContactDocuments.zip", Properties.Resources.ContactDocuments);
The solution is build without any errors.
However, when I run the application, I get the error"value cannot be null" at the point the above code is executed.
I have been looking at the properties of the zip file, but i did not find a solution.
#mjwills was pointing in the right direction.
I had to "Right click on the project. Click Properties. Click Resources" and add the resource:
Now, i can access this resource when running the application.
Thanks
Related
I've got some issues running Puma.Net. I've got all the functions looking fine in the code but when it comes this point:
Value = pumaPage.RecognizeToString();
It then gives an error saying the library dibapi.dll can't be found. But I just can't even add it as a reference it says something like
Can't add reference Make sure the file is accessible and that it is a assembly or Com-Component.
So I gave it all the rights it needs to be read, write & executed. I even gave it full controll on all the users but it just won't work.
Maybe I made a mistake somewhere so here is the full code of the programm.
static void Main()
{
string Image = "V:/Test_images/value.PNG";
Console.WriteLine("Running the Program!");
var pumaPage = new PumaPage(Image);
string Value;
using (pumaPage)
{
pumaPage.FileFormat = PumaFileFormat.RtfAnsi;
pumaPage.EnableSpeller = false;
pumaPage.Language = PumaLanguage.Digits;
Value = pumaPage.RecognizeToString();
}
Console.WriteLine("The Value is" + Value);
Console.ReadLine();
}
I've added the Puma.Net dll and "using Puma.Net;" so it should work. Does someone got any idea what could be wrong?
Here is also the errormessage that appears all the time.
The Error Message which appears
If you need a translation just tell me.
Btw it is a Console Application and I would love to keep it that way. If it is not possible then I can also try to use turn it into a Form Application but that's a whole new part for me so it could take a while to get into it.
You need to copy dibapi.dll to the output folder as described in the documentation:
Steps to add Puma.NET to your project:
1. Add reference to Puma.Net.dll;
2. Make sure that after project building the output folder (i.e. bin\Debug or bin\Release)
contains files Puma.Net.dll and puma.interop.dll. If the last is not present (IDE didn’t
copy it) copy it to the folder manually;
3. Copy dibapi.dll to the output folder;
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;
}
}
I have the following method code:
private Image GetMapIcon()
{
//TODO Fix path
return Image.FromFile("D:\\Work\\FindandCompare\\Main\\NHSChoices.FindAndCompare.Web\\Content\\img\\mapIcon.png");
}
As you can see the path will only work on my machine. I tried all sorts to get it to work without being so specific, but I couldn't! For example:
private Image GetMapIcon()
{
//TODO Fix path
return Image.FromFile(Url.Content("~/Content/img/mapIcon.png"));
}
The method is sitting within an MVC Controller.
I do not want to add a whole new Class Library project to the VS Solution to hold a resource. Is there an easier way that will work once this is deployed to the server?
You can use Server.MapPath:
private Image GetMapIcon()
{
return Server.MapPath("~/Content/img/mapIcon.png")
}
To include the image in the publish simply highlight the image in the solution explorer then change the 'Build action' to 'Content'.
I'm trying to extract the file name from a ProjectItem and already found out a few things:
Using projectItem.Properties.Item("FullPath").Value.ToString() will sometimes fail, namely with HTML files.
Using projectItem.FileNames[0] seemed to be the solution, it worked for all types of files inside projects.
But when trying to get a file path from a solution file (a file that is saved directly in a solution folder, not inside a project), the call failed with an ArgumentException. Some more investigation and trial-and-error later I seem to have found the cause: For solution files the FileNames property is 1-based, not 0-based. Now I'm completely lost and fail to see the system behind all this. My current solution is:
Check if the Kind of the project item is equal to VSConstants.GUID_ItemType_PhysicalFile (then it is a "regular" file). If yes, return projectItem.FileNames[0].
In all other cases return projectItem.FileNames[1].
var projItemGuid = new Guid(projectItem.Kind);
try
{
return (projItemGuid == VSConstants.GUID_ItemType_PhysicalFile)
? projectItem.FileNames[0]
: projectItem.FileNames[1];
}
catch (Exception e)
{
throw new FileNotFoundException(
$"The file path of {projectItem.Name} could not be retrieved" +
$"\nThe index might be wrong.) \nOriginal exception: {e.Message}");
}
Is this exhaustive or am I missing something? Is getting a file name from a ProjectItem really this annoying and unsafe?
I have been trying to communicate with my Unity C# script through my Android Application using
"UnityPlayer.UnitySendMessage("Cube", "Test","HELLO") - where "Cube" is my Unity Object, "Test" is the name of the method present in the C# script it is using and "HELLO" is the message String I want to pass.
This line is placed in my onClick function, like this:
ImageButton right_button = (ImageButton) findViewById(R.id.right_arrow);
right_button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
UnityPlayer.UnitySendMessage("Cube", "Test","HELLO");
}
});
But when I run my android application and as soon as I click this button, I get this error:
09-11 14:22:37.526: E/AndroidRuntime(1330): java.lang.NoClassDefFoundError: com.unity3d.player.UnityPlayer
I have included classes.jar in my build path also.
Is there anything else I am missing out?
Thanks in advance!
Check if the class.jar file is in the Build Path of your Project. And if so, check if it is selected (check box is marked).
Tip: if you get ClassDefNotFound runtime errors (or similar), you might need to perform this extra step:
go to Project > Properties > Java Build Path -> Order and Export tab and check (tick) the classes.jar, Android x.y and Android Dependencies items; then Apply and rebuild the probject.
Happened to me the other time too.
I clean, re-link and rebuild my eclipse project. Re-Export my jar file to unity and also restart Unity. Build again and the error is gone.