Operation not permitted on IsolatedStorageFileStream. when using MvvmCross file plugin - visual-studio-2013

I have an instance of IMvxFileStore implementation for for Windows Phone injected into my service.
Let say I want to store settings in a file located at appsettings\userprofiles\profile1.txt
Using the file plugin, I first call the API EnsureFolder exists, passing in the full path to my profile settings file appsettings\userprofiles\profile1.txt to ensure that this folder has been created and does exist.
Just for sanity, I check to ensure that the folder has been created using the FolderExist API. This always returns true atleast for now.
The code looks like this:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
_fileStore.EnsureFolderExists(filename);
if (_fileStore.FolderExists(filename))
{
// what do do????
}
return filename;
}
However, when I attempt to write content to the file using WriteToFile API, passing in the file name returned from the method above and some string, as follows
try
{
_fileStore.WriteFile(filename, content);
}
catch (Exception ex)
{
Logger.Error(ex);
}
, I get the following exception:
System.IO.IsolatedStorage.IsolatedStorageException was caught
HResult=-2146233264 Message=Operation not permitted on
IsolatedStorageFileStream. Source=mscorlib StackTrace:
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, FileAccess access, FileShare share, Int32 bufferSize,
IsolatedStorageFile isf)
at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path,
FileMode mode, IsolatedStorageFile isf)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFileCommon(String
path, Action`1 streamAction)
at Cirrious.MvvmCross.Plugins.File.WindowsPhone.MvxIsolatedStorageFileStore.WriteFile(String
path, String contents)
at TrackuTransit.Core.Services.DataStore.StorageItemFileRepository.Put(String
filename, StorageItem data) InnerException:
My dev environment is setup as follows:
- Surface Pro 3
- Visual Studio 2013 Community
- Windows Phone 8.1 SDK and Simulator
- MvvmCross 3.0.0.4. (yes,, it is old and will be updated after MVP).
Before I go digging into the MvvmCross code base, anyone with ideas on what I could be doing wrong here?

Upgraded the project to .NET 4.5 and also upgraded to MvvmCross 3.5.1 and still ran into the same problem. Although I lost a couple of days due from the upgrade, I am glad it is over with.
The problem I am running into here has to do with the fact that I am calling
_fileStore.EnsureFolderExists(filename);
and passing in the full path to the file. Underneath the scenes, MvvmCross is calling
IsolatedStorageFile.CreateDirectory(filename);
which appears to be creating a directory with the same file name. So passing in "images\image1.png" to the above API appears to create a directory or hold some IO resource related to "images\images.png".
When you attempt to write to file using
_fileStore.WriteFile(filename, content);
MvvmCross is attempting to create a file stream using
var fileStream = new IsolatedStorageFileStream(path, FileMode.Create, isf))
and the exception is thrown right here.
Fix is to ensure you are passing to IMvxFileStore.EnsureFolderExists API just the folder in question. In this case it is "images". Then you pass to IMvxFileStore.WriteFile the relative path to the file including the file name such as "images\image1.png" and you are good to go.
Fixed code looks like this:
private string GetStorageItemFileName(string filename)
{
Guard.ThrowIfNull(string.IsNullOrWhiteSpace(BaseDirectory), Messages.RepositorBackingStoreIsNull);
filename = _fileStore.PathCombine(BaseDirectory, filename);
// assumption is that filename does not contain directory information
_fileStore.EnsureFolderExists(BaseDirectory);
return filename;
}

Related

QT 5.2 app cannot start (Bad allocation error) when Qt5Core.dll is in app directory

I have a funny problem on my machine
Windows 7 x64, using QT 5.2 for the GUI
I'm not able to start the app I always receive the error
First I thought I had a broken dll, so through some trial and error I found a solution:
I add the QT5Core.dll via enviroment path, and NOT directly to the app folder. Then the programm works. If I copy the dll back to the app Folder, Same problem as before!?!?!?1
I'm really confused, because the error only occurs on my machine?
Debugging doesn't really help,
In code, the error occures here:
MyApplication::MYApplication(int argc, char** argv, int version)
: QApplication(argc, argv, version) // <<< this call fails!
{ }
somebody can help me?
Why is the location of the qt5core.dll a problem?!?!?
UPDATE
I used the profiling function of depends and found the following behaviour:
Failing
GetProcAddress(0x76800000 [c:\windows\syswow64\KERNEL32.DLL], "CreateSymbolicLinkW") called from > "dirone\xxxx.EXE" at address 0x00FF2877 and returned 0x7688CCE9.
First chance exception 0xE06D7363 (Microsoft C++ Exception) occurred in "c:\windows\syswow64\KERNELBASE.DLL" at address 0x765CC41F.
Exception: "bad allocation"
Working
LoadLibraryW("C:\BuildPackages\QT\plugins\platforms\qwindows.dll") called from "dirtwo\QT5CORE.DLL" at address 0x66AA5154.
Loaded "c:\buildpackages\qt\plugins\platforms\QWINDOWS.DLL" at address
0x0F380000. Successfully hooked module.
somehow the path to the qwindows.dll is hardcoded into the dll (there is no environment path to this directory)
If I rename the qwindows.dll or delete it, startup failes again.
BUT the qwindows.dll is bundeld with our product. It is in a subdirectory ./platforms/
AND the files are the same (diff returns equal)
Somebody have some clue what I should try next?
Check if you already have some qt related environmental variables.
Crashes are usually due to this, remove those envronmental variables first. Check whether you have any other qt installed libraries.
it would be better if you can post the cal stacks.
Some other dlls are needed that reside in the directory of the qt5core.dll. When you add this path to the search path the dlls are found. When you simply copy the dll these dlls can not be found. You can check dependencies with the depends tool.
Candidates for the additional dlls are:
icuin51.dll and icuuc51.dll
Found the Problem:
The enviromentvariable:
QT_QPA_PLATFORM_PLUGIN_PATH=C:\BuildPackages\QT\plugins\platforms
was set to the path. If removing this variable, everything works as it should!

mono gtk# - hello world deploy to windows

I have this really simple Hello World example i wrote on a linux host using Mono and gtk#. It simply shows a windows with a button. Now i tried to get the binary running on windows but failed. i installed the gtk# with the standalone installer from the mono homepage. when i start the application it failes due to:
System.DllNotFoundException was unhandled: Unable to load DLL
'libglib-2.0-0.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E) Source=glib-sharp
Any suggestions?
BR
You need either to run your app via mono.exe or just add the mono.exe location to the PATH environment variable value. You can do that in run-time like that:
[STAThread]
public static void Main(string[] args)
{
var dllDirectory = #"C:\Program Files (x86)\Mono\bin";
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dllDirectory);
Run();
}
private static void Run()
{
Gtk.Application.Init();
Forms.Init();
var app = new App();
var window = new FormsWindow();
window.LoadApplication(app);
window.SetApplicationTitle("Game of Life");
window.Show();
Gtk.Application.Run();
}
You will have to register the DLL 'libglib-2.0-0.dll' in Windows using regsvr32 libglib-2.0-0.dll from the command prompt. An alternative is to just package all the dependencies with your executable.
Hope this was helpful.
-Dave

ApprovalTests....Moving the assemblies after compile

First up, great library!
If I compile, then move the assemblies when I verify it still looks for the *.approved.txt in the location it was compiled in, which in my case no longer exists.
I'm running into this issue on Teamcity where we build and test in separate tasks.
So the build step will build in c:\BuildAgent\SomeGuid...
I take the artifacts from the build and run the tests in c:\BuildAgent\SomeOtherGuid...
This fails as Approvals.Verify still references "SomeGuid"
[Fact]
public void ShouldCreateCorrectOutgoingFiles() {
var textToVerfiy = "Here's some text To Verify";
Approvals.Verify(textToVerfiy);
}
...
: System.IO.DirectoryNotFoundException : Could not find a part of the path 'r:\w\254cbbd5ec9b56bc\project\ScenarioTests\myTests'.
Stack Trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
at ApprovalTests.ApprovalTextWriter.WriteReceivedFile(String received)
at ApprovalTests.Approvers.FileApprover.Approve()
at ApprovalTests.Core.Approvals.Verify(IApprovalApprover approver, IApprovalFailureReporter reporter)
at ApprovalTests.Approvals.Verify(IApprovalWriter writer, IApprovalNamer namer, IApprovalFailureReporter reporter)
at ApprovalTests.Approvals.Verify(IApprovalWriter writer)
at ApprovalTests.Approvals.Verify(String text)
Any ideas on how I can tweak it to look in relative directory to executable.
You have to write a custom namer. It's pretty easy. Take a look at these files.
http://bit.ly/IApprovalNamer
http://bit.ly/XUnitStackTraceParser
http://bit.ly/AttributeStackTraceParser
Once you do that, you'll have to register the namer for use, to do that simply call.
Approvals.RegisterDefaultNamerCreation(()=> new MyCustomNamer());

VSHost crash, REGDB_E_INVALIDVALUE loading Specific Project

Whenever I load a solution in Visual Studio with a specific project set as the startup project, I get a VSHost32.exe crash. If I keep on going and launch the application, I get a COMException:
{"Invalid value for registry (Exception from HRESULT: 0x80040153 (REGDB_E_INVALIDVALUE))"}
With a stacktrace:
at System.Runtime.InteropServices.RuntimeEnvironment.GetDeveloperPath()
at System.AppDomain.SetupFusionStore(AppDomainSetup info)
at System.AppDomain.SetupDomain(Boolean allowRedirects, String path, String configFile)
This can occur when a project's config file has developmentMode set, but the machine doesn't have a devPath set.
<runtime>
<developmentMode developerInstallation="true"/>
</runtime>
Removing that will fix it up.
Navigate to C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config and remove the below setting from your machine config
<developmentModedeveloperinstallation=”true”/>

PlatformVerificationTask internal error: "The file exists"

Anyone have any insight as to what this error is, and how to fix/avoid it?
Warning 1 An internal error occurred in PlatformVerificationTask. System.IO.IOException: The file exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.Path.GetTempFileName()
at Microsoft.CompactFramework.Build.DeviceTypeResolver.CreateDynamicAssembly(String fileName)
at Microsoft.CompactFramework.Build.DeviceTypeResolver.LoadAssembly(String codebase, Boolean canlock)
at Microsoft.CompactFramework.Build.DeviceTypeResolver..ctor(ICollection references)
at Microsoft.CompactFramework.Build.AsmmetaContext..ctor(String ndpversion, String platformFamily, String platformID, ICollection references)
at Microsoft.CompactFramework.Build.Tasks.PlatformVerificationTask.Execute()
I have doctored up a project to run the compiler to build .NET CF dlls from within VS2010, according to this SO question ( Building Compact Framework applications with VS2010 (without VS2005) ) . The build was working but now it stopped with this odd error.
I figured it out. By... uh.... Reading the documentation.
The doc page for System.IO.Path.GetTempPathName says
The GetTempFileName method will raise an IOException if it is used to create more than 65535 files without deleting previous temporary files.
The GetTempFileName method will raise an IOException if no unique temporary file name is available. To resolve this error, delete all unneeded temporary files.
So... I deleted the tmp????.tmp files from C:\Users\USERNAME\AppData\Local\Temp, and everything worked again.

Resources