Handling an IAsyncOperation<StorageFile^>^ object in C++/CX - file

I want to create a file in the local folder, so I have written the following code:
IAsyncOperation<StorageFile^>^ fileTask = Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync("example.dat");
But how should I handle the fileTask?
I have tried to call the GetResults-method, but then I get following exception:
Ausnahme ausgelöst bei 0x00007FFD211C7788 (KernelBase.dll) in Test.exe: 0x40080201: WinRT originate error (Parameter: 0x000000008000000E, 0x0000000000000040, 0x000000C00EBFC470).
Ausnahme ausgelöst bei 0x00007FFD211C7788 in Test.exe: Microsoft C++-Ausnahme: Platform::COMException ^ bei Speicherort 0x000000C00EBFC730. HRESULT:0x8000000E Eine Methode wurde zu einem unerwarteten Zeitpunkt aufgerufen.
WinRT-Informationen: Eine Methode wurde zu einem unerwarteten Zeitpunkt aufgerufen.
Next I have tried to use create_task:
create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync("example.dat")).then([this](StorageFile^ file)
{
// irrelevant
});
Exception:
Ausnahme ausgelöst bei 0x00007FFD211C7788 (KernelBase.dll) in Test.exe: 0x40080201: WinRT originate error (Parameter: 0x00000000800700B7, 0x0000000000000048, 0x000000A936DFB230).
Ausnahme ausgelöst bei 0x00007FFD211C7788 (KernelBase.dll) in Test.exe: 0xE06D7363: Microsoft C++ Exception (Parameter: 0xCCCCCCCC19930520, 0x000000A936DFB830, 0x00007FFD01398AD0, 0x00007FFD012C0000).
Sorry for the language
How could I solve this Problem?

Next I have tried to use create_task...
You are in the correct direction. It is recommended to use task class for async operation.
But the file example.dat is probably already there when you call the GetResults. Thus you won't be able to use create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync("example.dat")).then([this](StorageFile^ file) to create the file again.
To fix the problem, just modify the codes like below:
#include <ppltasks.h>
create_task(Windows::Storage::ApplicationData::Current->LocalFolder->CreateFileAsync("example.dat", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
{
});
Added CreationCollisionOption::ReplaceExisting so that everytime the new file will replace the old file. And don't forget to include the ppltask.h.

Related

Unable to load 'eeptools' package in R

After an update that I needed for another package, I can no longer use 'eeptools' to calculate the age. When I try, I always get the following error message:
Fehler: Laden von Paket oder Namensraum für ‘eeptools’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): fehlgeschlagen
es gibt kein Paket namens ‘minqa’
I have already tried deleting the package from the location and reinstalling it. Loading the "Minqa" package also failed.
I am grateful for any tips!

Global Exceptionhandler does not catch some Exception (for example StackoverflowException)

I have registered global Exceptionhandlers in my Application (C#, WPF, .NET4) at the startup-routine on the following way:
AppDomain.CurrentDomain.UnhandledException += (sender, args) => HandleException(args.ExceptionObject as Exception);
Application.Current.DispatcherUnhandledException += (sender, args) => {
HandleException(args.Exception);
args.Handled = true;
};
Where HandleException() does logging the Exception and showing a MessageBox with some additional information.
Now, there are from time to time crashes of my application on some customer machines, where HandleException() is not called. Windows is showing the following message:
In the WindowsEventLog, I get the following entries:
Entry1:
Name der fehlerhaften Anwendung: proconact.exe, Version: 1.0.0.1365, Zeitstempel: 0x511531df
Name des fehlerhaften Moduls: PresentationFramework.ni.dll, Version: 4.0.30319.588, Zeitstempel: 0x504db27d
Ausnahmecode: 0xc00000fd
Fehleroffset: 0x002ef05b
ID des fehlerhaften Prozesses: 0x1bec
Startzeit der fehlerhaften Anwendung: 0x01ce0b5dce4030a6
Pfad der fehlerhaften Anwendung: C:\Program Files (x86)\proconact_sck\proconact.exe
Pfad des fehlerhaften Moduls: C:\windows\assembly\NativeImages_v4.0.30319_32\PresentationFramewo#\c627e9b7f10b01db43645284e601f255\PresentationFramework.ni.dll
Berichtskennung: d8d69f94-777a-11e2-b4b0-b4b52f2aad4f
Entry2:
Fehlerbucket 3482664247, Typ 5
Ereignisname: CLR20r3
Antwort: Nicht verfügbar
CAB-Datei-ID: 0
Problemsignatur:
P1: proconact.exe
P2: 1.0.0.1365
P3: 511531df
P4: PresentationFramework
P5: 4.0.0.0
P6: 504db27d
P7: 329d
P8: 0
P9: System.StackOverflowException
P10:
Angefügte Dateien:
d:\Temp\WER6E9F.tmp.WERInternalMetadata.xml
Diese Dateien befinden sich möglicherweise hier:
C:\Users\roger\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_proconact.exe_b0fabce1f86d1f843de5b5b4692a3e8ecd928_2c77f03d
Analysesymbol:
Es wird erneut nach einer Lösung gesucht: 0
Berichts-ID: d8d69f94-777a-11e2-b4b0-b4b52f2aad4f
Berichtstatus: 0
What can I do that I can handle the Exception (for the meanreason to get the stacktrace for analysis where the exception occurs)?
Some exceptions cannot be caught, not even by AppDomain.UnhandledException. Because they are too nasty to permit managed code to keep running.
StackOverflowException is heart attack like that, infamous enough to give this web site its name. There is not enough stack space left to do common managed code execution duties, like running the jitter. ExecutionEngineException is another one, triggered by a destroyed garbage-collected heap and uncatchable in .NET 4.0 and up.
So no, the show is over and the WER dialog and the Windows event log entry is all that's left to look at. SO is always caused by a bug, you'll need to fix it.

SQLite on a WPF-Application

When i want to implement SQLite in a WPF-Application (.Net Framework 4), the programm failed (in the debugger-mode) with this message:
"Eine Ausnahme (erste Chance) des Typs "System.Windows.Markup.XamlParseException" ist in PresentationFramework.dll aufgetreten.
Zusätzliche Informationen: Zeilennummer "3" und Zeilenposition "9" von "Durch den Aufruf des Konstruktors für Typ "Kasse.MainWindow", der den angegebenen Bindungseinschränkungen entspricht, wurde eine Ausnahme ausgelöst.".
(this is german, here is the version, that is translated by Google-Translator):
An exception (first chance) of type System.Windows.Markup.XamlParseException 'occurred in PresentationFramework.dll.
Additional information: line number "3 " and line position "9 " "By calling the constructor for type Kasse.MainWindow" which matches the specified binding constraints, was an exception.
What should i do?
Greetings,
GreenPepper
This probably means that you are getting an exception in the constructor of the code-behind class of your window. Try setting a breakpoint and step through your constructor.

DNN Module with devxpress controls critical Error

I am using DNN module 5.6.1, and i created a custom module using Devxpress controls,
It is installing in dnn site, but when i try to add the module in a page, i getting the following Error,
A critical error has occurred.
Object reference not set to an instance of an object.
And Log is.........
AssemblyVersion: 5.6.1
PortalID: 0
PortalName: My Website
UserID: 1
UserName: host
ActiveTabID: 63
ActiveTabName: TestDNN
RawURL: /dotnetnuke_new/TestDNN.aspx
AbsoluteURL: /DotNetNuke_New/Default.aspx
AbsoluteURLReferrer: http://senthilkumar.com/dotnetnuke_new/TestDNN.aspx
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14 (.NET CLR 3.5.30729)
DefaultDataProvider: DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider
ExceptionGUID: cd7a06c5-7a69-4ebf-b51e-07f70714bfe6
InnerException: Object reference not set to an instance of an object.
FileName:
FileLineNumber: 0
FileColumnNumber: 0
Method: dnn_webrater.ctrlRater.Page_Load
StackTrace:
Message: DotNetNuke.Services.Exceptions.PageLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at dnn_webrater.ctrlRater.Page_Load(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) --- End of inner exception stack trace ---
Source:
and after logout and login, it shows the following error on the page
Error: Test Module 1 is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DotNetNuke.UI.Modules.ModuleHost.LoadModuleControl() --- End of inner exception stack trace ---
Can any one please help me to fix this error
This is a very generic error. You may want to look through your Event Log to see if there are other errors that occur at the same time more related to your specific module. Debugging the module to see what exception is coming from your module can also be helpful, rather than trying to unwind these stack traces that, more than likely, are going to be wild goose chases.
What often happens with DNN is that a module fails while loading, and then other parts of the skin and container fail because the module was never fully setup correctly. These are the NullReferenceException errors that you're seeing.
bdukes said the main things I would guess anyway keep the following problem in mind, too.
another reason for this problem could be a specific servertag used in a dnnwrapper.
for example if you are using telerik wrapper from dotnetnuke but placing telerik controls in this wrappers without having a refference on the telerik assambly.
example:
<dnncontrols:datepicker>
<calendar>
<SpecialDays>
<telerik:calendarDays />
</SpecialDays>
</calendar>
</dnncontrols:datepicker>
If you are doing this you will get a nullreference as you got. This Problem drove me crazy to find it so I decided to post it here.
I hope this will help you.
But at first I would suggest the way bdukes described (this is the normal way to go).
best regards

Code Access Security in Reporting Services 2008

I have a Delivery Extension running inside Reporting Service 2008.
It has been running fine for a long time. But now I want to make an insert into a database from within the extension.
First error I got, was this:
Exception: System.Security.SecurityException Exception Message: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Stacktrace: at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.PermissionSet.Demand()
at System.Data.Common.DbConnectionOptions.DemandPermission()
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
Then I added this, before my code that opens the connection and does the insert:
SqlClientPermission sqlPermission = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
sqlPermission.Assert();
Then the error message changed to this:
Exception: System.Security.SecurityException Exception Message: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Stacktrace: at System.Security.CodeAccessSecurityEngine.CheckNReturnSO(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 unrestrictedOverride, Int32 create)
at System.Security.CodeAccessSecurityEngine.Assert(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Assert()
Then I added the following line:
SecurityPermission permission = new SecurityPermission(PermissionState.Unrestricted);
permission.Assert();
And now the error I get is this:
Exception: System.Security.SecurityException Exception Message: Stack walk modifier must be reverted before another modification of the same type can be performed. Stacktrace: at System.Security.CodeAccessSecurityEngine.Assert(CodeAccessPermission cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Assert()
My code that contains the actual SqlConnection specific code is in an assembly referenced from the Delivery Extension. The Permission specific code was inside that assembly, but I tried moving it into the Delivery Extension assembly - but wothout any luck.
user407428 is correct, trying to enable two different modifiers is what is causing your problem. The best principle is to allow the permission for the part of the code that requires it, and then to disable the permission afterwords. So that when you need the next permission you can modify those rights again.
SqlClientPermission sqlClientPermission = new SqlClientPermission(PermissionState.Unrestricted);
sqlClientPermission.Assert();
//<your code that requires SqlClientPermission here>
CodeAccessPermission.RevertAccess();
SecurityPermission securityPermission = new SecurityPermission(PermissionState.Unrestricted);
securityPermission.Assert();
Some more things to take into account is that it is mostly not required to keep an object to the stack-walk, so the assert can be simplified to a single line, ei.
System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
If you modified the stack-walk in a encapsulating method, the inner stack would probably not be able to modify the modifiers again. Ex.
public void UseSecurityPermission()
{
CodeAccessPermission.RevertAssert();
new System.Security.Permissions.SecurityPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
<Some code that requires the SecurityPermission>
}
static void Main(string[] args)
{
new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
//< Some code that requires IOPermission>
UseSecurityPermission();
}
Even though UseSecurityPermission() reverts the stack-walk permission, it would not work, because the compiler can't get the security descriptor in the context.
Some further reading:
Programming with Stack-Walk Modifiers
At the point you are trying to modify the access permissions you may already have inherited it from higher level, or maybe you have done it somewhere before the point you are.
For example we have code like this:
SqlClientPermission sqlClientPermission = new SqlClientPermission(PermissionState.Unrestricted);
sqlClientPermission.Assert();
SecurityPermission securityPermission = new SecurityPermission(PermissionState.Unrestricted);
securityPermission.Assert();
We will have the exception like yours.

Resources