I am saving data-files on the persistant datapath of the android device focus 3 I am building for. The current file saving and editing system seems to work well in the editor and works if i create and write to the file in the same "session" but as soon as the scene or build is reloaded then i get the following error when trying to write to the file.
02-06 09:33:52.696 16111 16133 E Unity : IOException: Sharing violation on path /storage/emulated/0/Android/data/com.Project.ProjectName/files/gamedata.json
02-06 09:33:52.696 16111 16133 E Unity : at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous,
What could be the cause of this. I use the toJson() function to write and read the plaintext file-class.
gameData = JsonUtility.FromJson<GameData>(text);
FileStream iStream = new FileStream(plaintext_saveFile, FileMode.OpenOrCreate);
StreamWriter sWriter = new StreamWriter(iStream);
string jsonString = JsonUtility.ToJson(gameData);
sWriter.Write(jsonString);
Additionally when trying to implement a simple AES cryptography solution i get the following error:
02-06 09:31:19.699 16111 16133 E Unity : CryptographicException: Bad PKCS7 padding. Invalid length 82.
02-06 09:31:19.699 16111 16133 E Unity : at Mono.Security.Cryptography.SymmetricTransform.ThrowBadPaddingException (System.Security.Cryptography.PaddingMode padding, System.Int32 length, System.Int32 position) [0x00000] in <00000000000000000000000000000000>:0
02-06 09:31:19.699 16111 16133 E Unity : at Mono.Security.Cryptography.SymmetricTransform.FinalDecrypt (System.Byte[] inputBuffer, System.Int32 inputOffset, System.Int32 inputCount) [0x00000] in <00000000000000000000000000000000>:0
I mostly attempted to follow this tutorial: https://videlais.com/2021/02/28/encrypting-game-data-with-unity/
I have tried changing the filestream mode from create to openandcreate.
It looks like you're still using the default package name ("com.Project.ProjectName"). Unity may have some additional protection for data under that name (not sure, though). I recommend going to Project Settings -> Player Settings -> Other Settings -> and set the Package Name field to a unique value. Then try again.
Related
I am trying to play sounds on a secondary soundcard using NAudio in a Unity project.
It works successfuly using the Play button in the editor, but not in the executable build.
Here is the error i get :
System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Windows.Forms.Form..ctor () [0x00000] in <0b0c181c86c84da989ad80998d3a0a84>:0
at NAudio.Wave.WaveWindow.OnMdiChildActivate (System.EventArgs e) [0x00000] in <554b80148c284b99953f098db496ebd4>:0
at (wrapper remoting-invoke-with-check) NAudio.Wave.WaveWindow..ctor(NAudio.Wave.WaveInterop/WaveCallback)
at NAudio.Wave.WaveCallbackInfo.Connect (NAudio.Wave.WaveInterop+WaveCallback callback) [0x00009] in <554b80148c284b99953f098db496ebd4>:0
at NAudio.Wave.WaveOut..ctor (NAudio.Wave.WaveCallbackInfo callbackInfo) [0x0004e] in <554b80148c284b99953f098db496ebd4>:0
at NAudio.Wave.WaveOut..ctor () [0x00014] in <554b80148c284b99953f098db496ebd4>:0
at MainVideoScript.playSound (System.Int32 deviceNumber) [0x0002e] in <0d2c0b09fee74d5099fd910768d58ea9>:0
I am running on Windows 10, and the Target platform=Windows, so why the platform doesn't support what I am trying to do? What can I change?
Here is the code i am trying to run:
string soundPath = System.IO.Path.Combine(Application.streamingAssetsPath, #"clic2.wav");
waveReader = new NAudio.Wave.WaveFileReader(soundPath);
var wave = new NAudio.Wave.WaveOut();
wave.DeviceNumber = deviceNumber;
wave.Init(waveReader);
wave.Play();
I am using 2019.2.8f1
You need to make sure the Api compatibility Level is correct in Edit \ Project Settings \ Player
I have a completed game working properly in Android and is published on Play store already. Now I wanted to submit it on iTunes. As soon as I started building the same project for iOS, I got this strange Error -
IOException: Sharing violation on path /Users/abhi/Projects/Unity/XCode Proj/Hammer Inc/Unity-iPhone.xcodeproj/project.pbxproj
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:320)
System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
(wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
System.IO.File.OpenRead (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:363)
System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/StreamReader.cs:167)
System.IO.StreamReader..ctor (System.String path)
(wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)
System.IO.File.OpenText (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:368)
System.IO.File.ReadAllLines (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:560)
AdColonyPostProcessBuild.updateXcodeProject (System.String pbxProjectFilePath, System.String thirdPartyFrameworkDirectoryPath, .Framework[] frameworksToAdd) (at Assets/Editor/AdColonyPostProcessBuild.cs:356)
AdColonyPostProcessBuild.OnPostProcessBuild (BuildTarget target, System.String path) (at Assets/Editor/AdColonyPostProcessBuild.cs:340)
UnityEditor.HostView:OnGUI()
I got this error, after I was having some trouble with GPG Plugin and as mentioned here, I deleted the files and folders related to Google Play gaming, since I planned to use Game Center in iOS.
I am currently using Native-X, Adcolony, Revmob in the same project (I know that's too much, but that was due to an experiment on choosing proper network). I am not sure which of the plugin is causing conflicts.
I tried removing the AdColonyPostProcessBuild.cs file, but it gave the following error -
KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (.TKey
key) (at
/Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/
corlib/System.Collections.Generic/Dictionary.cs:150)
UnityEditor.XCodeEditor.PBXResolver.ResolveName (System.String guid) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:49)
UnityEditor.XCodeEditor.PBXResolver.ResolveName (System.String guid) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:53)
UnityEditor.XCodeEditor.PBXParser.GUIDComment (System.String guid,
System.Text.StringBuilder builder) (at Assets/Editor/iOS/PBX
Editor/PBXParser.cs:218)
UnityEditor.XCodeEditor.PBXParser.SerializeString (System.String
aString, System.Text.StringBuilder builder, Boolean useQuotes, Boolean
readable) (at Assets/Editor/iOS/PBX Editor/PBXParser.cs:546)
UnityEditor.XCodeEditor.PBXParser.SerializeDictionary
(System.Collections.Generic.Dictionary`2 dictionary,
System.Text.StringBuilder builder, Boolean readable, Int32 indent) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:481)
UnityEditor.XCodeEditor.PBXParser.SerializeValue (System.Object value,
System.Text.StringBuilder builder, Boolean readable, Int32 indent) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:439)
UnityEditor.XCodeEditor.PBXParser.SerializeDictionary
(System.Collections.Generic.Dictionary`2 dictionary,
System.Text.StringBuilder builder, Boolean readable, Int32 indent) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:489)
UnityEditor.XCodeEditor.PBXParser.SerializeValue (System.Object value,
System.Text.StringBuilder builder, Boolean readable, Int32 indent) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:439)
UnityEditor.XCodeEditor.PBXParser.Encode
(UnityEditor.XCodeEditor.PBXDictionary pbxData, Boolean readable) (at
Assets/Editor/iOS/PBX Editor/PBXParser.cs:177)
UnityEditor.XCodeEditor.XCProject.CreateNewProject
(UnityEditor.XCodeEditor.PBXDictionary result, System.String path) (at
Assets/Editor/iOS/XCProject.cs:620)
UnityEditor.XCodeEditor.XCProject.Save () (at
Assets/Editor/iOS/XCProject.cs:645) XCodePostProcess.OnPostProcessBuild
(BuildTarget target, System.String path) (at
Assets/Editor/iOS/XCodePostProcess.cs:35) UnityEditor.HostView:OnGUI()
Did anyone faced this issue before and found any solution? I don't want to delete every SDK from the project and start building it again.
I see you have a couple of issues. That sounds like a bummer. But, I would definitely like to help.
What's Happening:
Regarding the first error that you've provided it looks like it's having an issue reading the pbxproj file that Unity creates for the iOS build process.
Typically, when building for iOS, Unity will create a .pbxproj file in conjunction with the rest of the XCode items and then place that in the target build directory you specify. After that it triggers any post process build logic that has been hooked in by the developer.
AdColony's AdColonyPostProcessBuild.cs file is generally intended to be run last out of the post process build logic, because we rely on parsing the .pbxproj file itself, and then adding the information in line by line. The reason we prefer to do this last is because there exist current solutions to this problem that don't necessarily facilitate all the configurations we need, but other developers use it.
The first error looks like it's an access violation issue with the AdColonyPostProcessBuild not being able to access the .pbxproj file, so it can read in all of the lines. Because of this it's throwing an IOException seen here:
IOException: Sharing violation on path /Users/abhi/Projects/Unity/XCode Proj/Hammer Inc/Unity-iPhone.xcodeproj/project.pbxproj
and
System.IO.File.ReadAllLines (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:560)
AdColonyPostProcessBuild.updateXcodeProject (System.String pbxProjectFilePath, System.String thirdPartyFrameworkDirectoryPath, .Framework[] frameworksToAdd) (at Assets/Editor/AdColonyPostProcessBuild.cs:356)
This brings me to my next point.
The second error that you've listed is something that arises out of an alternative post process build logic called "XCode Editor For Unity".
You can find it here:
https://github.com/dcariola/XCodeEditor-for-Unity
This solution is a C# implementation of a solution known as mod_pbxproj, and other developers have opted for this solution. However, when using it in conjunction with AdColony it will typically break if the XCode Editor For Unity is performed after the AdColonyPostProcessBuild.cs is run.
This is because some of the information used for the XCode Editor For Unity parsing has been duplicated and is being read in twice, when AdColonyPostProcessBuild.cs is run.
AdColony has configured our post process logic to run last, relying on the ability to parse the information after the XCode Editor For Unity has been run.
The Suggested Solution
The information you've provided has been very helpful, but it's hard to say for certain why these may be arising.
What will facilitate this process is if you could list any other plug-ins you're using that have a post process build applied for iOS builds AND if you can also provide any indications of their priority or order of occurrence on build.
Following that, the line numbers I see in your error output appear a bit inconsistent with the current version of the AdColonyPostProcessBuild.cs file in our current available package.
I would first suggest going to this link, downloading the current package, and re-importing the AdColonyPostProcessBuild.cs
https://github.com/AdColony/AdColony-Unity-SDK
If that doesn't resolve the issue, I would then open up the AdColonyPostProcessBuild.cs file and change its priority to be lower, preferably to be the last post process build item to run. You can do this by changing the number '200' on line 302, to a great number, like '1000'.
If this doesn't resolve your problem I will need to know more about your environment configuration like other plug-ins you are using, and deviations you've made from the default AdColonyPostProcessBuild.cs file.
Regards!
AdColony Support
This problem arose for me because I was using the Facebook SDK with Adcolony's SDK. The Facebook code leaves a streamReader open which produces the error when the Adcolony script is run. Change lines in Assets\Facebook\Editor\iOS\third_party\XCodeEditor-for-Unity\XCProject.cs
from (lines 76-77):
projectFileInfo = new FileInfo(Path.Combine(this.filePath, "project.pbxproj"));
string contents = projectFileInfo.OpenText().ReadToEnd();
to:
projectFileInfo = new FileInfo(Path.Combine(this.filePath, "project.pbxproj"));
StreamReader sr = projectFileInfo.OpenText();
string contents = sr.ReadToEnd();
sr.Close();
(credit to the answer here: "IOException: Sharing violation on path" on building a Unity project on Mac OS X with Facebook Unity SDK 5.1)
I'm having trouble accessing my web service from Unity if it is not running on port 80. This is the C# code that I'm using in Unity
private void RunSimulation()
{
string url = #"http://192.168.1.116:9000/simulate";
WWW goServer = new WWW(url);
}
On 192.168.1.116, I have a program written in go that is listening on port 9000. I can easily reach this URL from a web browser and I will get my expected result.
When I try this in Unity, if I examine the contents of my goServer variable, I will see the message
System.Security.Exception: No valid crossdomain policy available to allow access
There is a crossdomain policy file. It is located at /var/www/html/crossdomain.xml Is has the following contents:
<allow-access-from domain="*" to-ports="*" secure="false"/>
<site-control permitted-cross-domain-policies="all"/>
This file existed before and there were .php programs that were able to successfully be called. I added the to-ports"*" to try to get it to work, but no luck.
I have tried having my go server listen on port 80. When I do this, I am able to connect from Unity. Any idea?
(The input sanitizer is defeating me and I can't figure out how to post without the input form telling me that my links are not allowed, so I'm going to omit 192.168.1.116:9000)
I was not getting anything at serverurl.com:9000/crossdomain.xml
So I put some code into my go server to respond to this request and return a response with headers Access-Control-Allow-Origin, Access-Control-Allow-Headers, and Access-Control-Allow-Credentials.
I set the ENABLE_CROSSDOMAIN_LOGGING environment variable. I see this in the log file plus a bunch more
Determining crossdomain.xml location for request: /simulate?asdfa=sadfsa
About to parse url: /simulate?asdfa=sadfsa
Determining crossdomain.xml location for request:/simulate?asdfa=sadfsa
About to parse url: /crossdomain.xml
About to parse url: /simulate?asdfa=sadfsa
Determining crossdomain.xml location for request: /simulate?asdfa=sadfsa
Download had OK statuscode
Received the following crossdomain.xml
----------
----------
received policy
BuildFlashPolicy caught an exception while parsing
/crossdomain.xml: Policy can't be constructed from empty stream.
ArgumentException: Policy can't be constructed from empty stream.
at MonoForks.System.Windows.Browser.Net.FlashCrossDomainPolicy.FromStream (System.IO.Stream originalStream) [0x00000] in :0
at MonoForks.System.Windows.Browser.Net.CrossDomainPolicyManager.BuildFlashPolicy (Boolean statuscodeOK, MonoForks.System.Uri uri, System.IO.Stream responsestream, System.Collections.Generic.Dictionary`2 responseheaders) [0x00000] in :0
UnityEngine.WWW:get_assetBundle()
PlayEditorMain:RunSimulation() (at Assets\Scripts\Play Editor Scripts\Menu Scripts\PlayEditorMain.cs:526)
PlayEditorMain:ButtonPressed(GameObject) (at Assets\Scripts\Play Editor Scripts\Menu Scripts\PlayEditorMain.cs:261)
MainMenuButton:OnClick() (at Assets\Scripts\Play Editor Scripts\Menu Buttons\MainMenuButton.cs:23)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:765)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:1435)
UICamera:ProcessMouse() (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:1063)
UICamera:Update() (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:909)
(Filename: Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs Line: 526)
Unable to determine the audio type from the URL (/simulate?asdfa=sadfsa) . Please specify the type.
UnityEngine.WWW:GetAudioClip(Boolean, Boolean, AudioType)
UnityEngine.WWW:GetAudioClip(Boolean, Boolean) (at C:\BuildAgent\work\d63dfc6385190b60\artifacts\EditorGenerated\Utils.cs:308)
UnityEngine.WWW:GetAudioClip(Boolean) (at C:\BuildAgent\work\d63dfc6385190b60\artifacts\EditorGenerated\Utils.cs:301)
UnityEngine.WWW:get_audioClip() (at C:\BuildAgent\work\d63dfc6385190b60\artifacts\EditorGenerated\Utils.cs:293)
PlayEditorMain:RunSimulation() (at Assets\Scripts\Play Editor Scripts\Menu Scripts\PlayEditorMain.cs:526)
PlayEditorMain:ButtonPressed(GameObject) (at Assets\Scripts\Play Editor Scripts\Menu Scripts\PlayEditorMain.cs:261)
MainMenuButton:OnClick() (at Assets\Scripts\Play Editor Scripts\Menu Buttons\MainMenuButton.cs:23)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:765)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:1435)
UICamera:ProcessMouse() (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:1063)
UICamera:Update() (at Assets\3rd Party\NGUI\Scripts\UI\UICamera.cs:909)
[C:/BuildAgent/work/d63dfc6385190b60/Runtime/Audio/AudioClip.cpp line 118]
(Filename: Assets/Scripts/Play Editor Scripts/Menu Scripts/PlayEditorMain.cs Line: 526)
So I think I am now returning the correct headers, but I'm thinking that I also need to return the contents in the body. I'm thinking that I'll just return the same contents that the crossdomain.xml file I get when I query it on port 80.
I know that the crossdomain.xml endpoint on my server is being hit. If I understand what the logfile that unity is outputting, the problem might just be that the body is empty and I have an empty stream.
No proxy needed, unity has logging crossdomain stuff built in: take a look at the the debuging section of the unity3d manual on the security sandbox and turn on crossdomain debugging with ENABLE_CROSSDOMAIN_LOGGING. Then look for the results in the logs.
Just to be sure, a crossdomain file is reachable at http://192.168.1.116:9000/crossdomain.xml?
What I had to do was implement my own version of the crossdomain.xml endpoint. It currently looks like this.
func crossdomain(res http.ResponseWriter, req *http.Request) {
log.Println("At the top of crossdomain")
if origin := req.Header.Get("Origin"); origin != "" {
res.Header().Set("Access-Control-Allow-Origin", origin)
}
res.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
res.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token")
res.Header().Set("Access-Control-Allow-Credentials", "true")
body := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">" +
"<cross-domain-policy>" +
"<site-control permitted-cross-domain-policies=\"all\"/>" +
"<allow-access-from domain=\"*\" to-ports=\"*\" secure=\"false\"/>" +
"<allow-access-from domain=\"*\" to-ports=\"*\"/>" +
"<allow-access-from domain=\"*\"/>" +
"<allow-http-request-headers-from domain=\"*\" to-ports=\"*\"/>" +
"<allow-http-request-headers-from domain=\"*\"/>" +
"<site-control permitted-cross-domain-policies=\"all\"/>" +
"</cross-domain-policy>"
io.WriteString(res,body)
}
func main() {
http.HandleFunc("/simulate", simulate)
http.HandleFunc("/crossdomain.xml", crossdomain)
listenErr := http.ListenAndServe(":9000", nil)
}
I'm having a issue trying to write input to linux process. Here the code goes:
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WorkingDirectory = "'/home/"+user+"/pacotes/"+nome_pacote.Text+"-1.0/'";
process.StartInfo.FileName="dh_make";
process.StartInfo.Arguments="-n -s";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.Start();
Thread.Sleep(3000);
process.StandardInput.WriteLine();
And here goes the error:
System.IO.IOException: Write fault on path /home/vinholi/Ubuntu One/Uso do linux em flash drives/Programa gerador de .deb/GeradorDeb/GeradorDeb/bin/Debug/[Unknown]
at System.IO.FileStream.FlushBuffer (System.IO.Stream st) [0x00000] in :0
at System.IO.FileStream.FlushBuffer () [0x00000] in :0
at System.IO.FileStream.Dispose (Boolean disposing) [0x00000] in :0
One likely explanation for this error is that the process exited before you're attempting to write to it. I tried this with /bin/date and a legitimate StartInfo.WorkingDirectory and the assembly is /Workspace/export/misc/H.exe. This yields:
Unhandled Exception:
System.IO.IOException: Write fault on path /Workspace/export/misc/[Unknown]
at System.IO.FileStream.WriteInternal (System.Byte[] src, Int32 offset, Int32 count) [0x00097] in /Workspace/mono/mcs/class/corlib/System.IO/FileStream.cs:658
at System.IO.FileStream.Write (System.Byte[] array, Int32 offset, Int32 count) [0x000aa] in /Workspace/mono/mcs/class/corlib/System.IO/FileStream.cs:634
at System.IO.StreamWriter.FlushBytes () [0x00043] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:222
at System.IO.StreamWriter.FlushCore () [0x00012] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:203
at System.IO.StreamWriter.Write (System.Char[] buffer) [0x00022] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:351
at System.IO.TextWriter.WriteLine () [0x00000] in /Workspace/mono/mcs/class/corlib/System.IO/TextWriter.cs:257
at X.Main () [0x00066] in /Workspace/export/misc/H.cs:17
You are getting this every time when you're using an invalid directory in process.StartInfo.WorkingDirectory. There's nothing that can be done about that, though the error message should be made clearer.
Your directory is invalid because of the quotation marks. You also should not concatenate path names the way you did as it makes your application non-portable to non-Unix operating systems. Instead, write it as:
var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
process.StartInfo.WorkingDirectory = Path.Combine (home, "pacotes", nome_pacote.Text+"-1.0");
Using Environment.GetFolderPath() makes it easier to run your application on a Mac (where home directories are in /Users/<username> instead of /home/<username>).
One other possibility is that the binary that you're launching is a dangling symlink. Check if the binary exists or is a symlink pointing to a valid binary.
As another response stated "One likely explanation for this error is that the process exited before you're attempting to write to it."
And that was the problem I had -- even after setting the WorkingDirectory as described in the other answer. And in your same situation: C#, Mono, Ubuntu.
Ultimately the solution in my case was to set the Arguments so that the process was not exiting, and was really trying to read input from the StandardInput.
The path you are trying to write too can't be written too.
" /home/vinholi/Ubuntu One/Uso do linux em flash drives/Programa gerador de .deb/GeradorDeb/GeradorDeb/bin/Debug/"
Looks like its a usb drive. Check the following:
Its not readonly.
Its not been mounted readonly.
The usb drive is not out of space.
If I run this code on the device, it returns "got it":
if (Directory.Exists (NSBundle.MainBundle.BundlePath + "/ARCSDev")) {
Console.WriteLine ("got it");
} else {
Console.WriteLine ("can't find it");
}
Which means the directory is in the main bundle.
I need to use that file in this method call:
private void generateChart (int chartNumber, string palette)
{
string filePath = NSBundle.MainBundle.BundlePath + "/ARCSDev";
Console.WriteLine("Filepath - " + filePath);
Loader loader = new Loader (filePath);
loader.LoadChart (Convert.ToString (chartNumber));
The above code works fine on the simulator, but not on the device.
I get the following stack trace when the error occurs on the device:
System.InvalidOperationException: Operation is not valid due to the current state of the object
at System.Linq.Enumerable.Max[TileIndexRecord] (IEnumerable`1 source, System.Func`2 selector) [0x00000] in <filename unknown>:0
at MyCompany.Data.Arcs.Loader.ExtractWriteableBitmap (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette, Double dpi, MyCompany.Data.Arcs.Raschts.ChartIndexFile indexFile, MyCompany.Data.Arcs.Raschts.RasterChartFile chartFile) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:571
at MyCompany.Data.Arcs.Loader.GetHiResImage (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:362
at ARCSViewer.SecondViewController.generateChart (Int32 chartNumber, System.String palette) [0x0004e] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:118
at ARCSViewer.SecondViewController.ViewDidAppear (Boolean animated) [0x00007] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:84
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at ARCSViewer.Application.Main (System.String[] args) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Main.cs:17
The directory contains unix executable files and radiance files.
Can anyone explain whats going on? The file is definitely in the right place (the bundle) as I've tested the code that checks for existence with other files that I know to be there as well..
It might be an issue of case sensitivity, the simulator is case-insensitive while the device is case sensitive. Check your files to see if you're accessing all of them with the right case (i.e. not only the directory).
The permissions on the devices are very different (far more restricted) from the simulator. There's a lot of place you do not have access for various reasons (e.g. changing some files would break the application digital signature which would disallow your application from running anymore).
Also if your application does not follow Apple guidelines on where (and when) to store data your application will be rejected (if you target the appstore).
There's a nice article from Xamarin on how to work with the iOS file system.
I solved the problem, several parts of my application use code like below:
fs = new FileStream(fileName, FileMode.Open);
I needed to change every occurrence of FileStream() to the following:
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
As my files are in the bundle and don't need to make use of write operations, this limits the file stream to only read operations and allowed the files to be read in properly.