Why StorageFile.GetFilesAsync() crash in dll?
up vote
0
down vote
favorite
I have made a dll of UWP and using the StorageFile.GetFilesAsync()
in it.
Here is the code:
Task.Factory.StartNew(async () =>
StorageFolder SFolder = KnownFolders.RemovableDevices;
try
IReadOnlyList<StorageFile> SFile = await SFolder.GetFilesAsync();
catch (Exception ex)
throw ex;
);
After I ran the program, it crashed with the exception:
{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
It seems I have no permission to access the file. However, I checked the UWP program which referenced the dll, the UWP program has already declared the Capabilities of Removable Storage yet.
What's wrong with it? Would you please tell me how to solve this? Thank you.
uwp
add a comment |
up vote
0
down vote
favorite
I have made a dll of UWP and using the StorageFile.GetFilesAsync()
in it.
Here is the code:
Task.Factory.StartNew(async () =>
StorageFolder SFolder = KnownFolders.RemovableDevices;
try
IReadOnlyList<StorageFile> SFile = await SFolder.GetFilesAsync();
catch (Exception ex)
throw ex;
);
After I ran the program, it crashed with the exception:
{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
It seems I have no permission to access the file. However, I checked the UWP program which referenced the dll, the UWP program has already declared the Capabilities of Removable Storage yet.
What's wrong with it? Would you please tell me how to solve this? Thank you.
uwp
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have made a dll of UWP and using the StorageFile.GetFilesAsync()
in it.
Here is the code:
Task.Factory.StartNew(async () =>
StorageFolder SFolder = KnownFolders.RemovableDevices;
try
IReadOnlyList<StorageFile> SFile = await SFolder.GetFilesAsync();
catch (Exception ex)
throw ex;
);
After I ran the program, it crashed with the exception:
{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
It seems I have no permission to access the file. However, I checked the UWP program which referenced the dll, the UWP program has already declared the Capabilities of Removable Storage yet.
What's wrong with it? Would you please tell me how to solve this? Thank you.
uwp
I have made a dll of UWP and using the StorageFile.GetFilesAsync()
in it.
Here is the code:
Task.Factory.StartNew(async () =>
StorageFolder SFolder = KnownFolders.RemovableDevices;
try
IReadOnlyList<StorageFile> SFile = await SFolder.GetFilesAsync();
catch (Exception ex)
throw ex;
);
After I ran the program, it crashed with the exception:
{System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
It seems I have no permission to access the file. However, I checked the UWP program which referenced the dll, the UWP program has already declared the Capabilities of Removable Storage yet.
What's wrong with it? Would you please tell me how to solve this? Thank you.
uwp
uwp
edited Nov 12 at 9:44
Martin Zikmund
22.3k33058
22.3k33058
asked Nov 11 at 10:46
102425074
1138
1138
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25
add a comment |
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
As the documentation states, there are two prerequisites for using the KnownFolders.RemovableDevices
folder:
To access the removable devices folder, you must:
- In the app manifest, specify the Removable Storage capability.
- In the app manifest, register at least one File Type Association declaration. This declaration explicitly indicates the file types
(extensions) that your app wants to access on the removable devices.
The app can only enumerate, create, or change files that have the file
types declared in the app manifest. For more info, see Handle file
activation.
According to your question, you have handled the first prerequisite, but you also need to satisfy the second - which is specifying the file types your app works with. This can be done in the Package.appxmanifest
Declarations tab. There you select File Type Associations in the drop down and fill out the required fields.
The reason access to removable storage is limited to only the file types you specify is an additional security measure, so that the user can rest assured that the app does not do anything harmful. If you need full access to a file system location, you will need to use the built-in FolderPicker
or use the broadFilesystemAccess
capability (which is however a restricted capability and it is verified during Microsoft Store certification, whether the app has actually a good reason to declare it).
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
As the documentation states, there are two prerequisites for using the KnownFolders.RemovableDevices
folder:
To access the removable devices folder, you must:
- In the app manifest, specify the Removable Storage capability.
- In the app manifest, register at least one File Type Association declaration. This declaration explicitly indicates the file types
(extensions) that your app wants to access on the removable devices.
The app can only enumerate, create, or change files that have the file
types declared in the app manifest. For more info, see Handle file
activation.
According to your question, you have handled the first prerequisite, but you also need to satisfy the second - which is specifying the file types your app works with. This can be done in the Package.appxmanifest
Declarations tab. There you select File Type Associations in the drop down and fill out the required fields.
The reason access to removable storage is limited to only the file types you specify is an additional security measure, so that the user can rest assured that the app does not do anything harmful. If you need full access to a file system location, you will need to use the built-in FolderPicker
or use the broadFilesystemAccess
capability (which is however a restricted capability and it is verified during Microsoft Store certification, whether the app has actually a good reason to declare it).
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
add a comment |
up vote
1
down vote
accepted
As the documentation states, there are two prerequisites for using the KnownFolders.RemovableDevices
folder:
To access the removable devices folder, you must:
- In the app manifest, specify the Removable Storage capability.
- In the app manifest, register at least one File Type Association declaration. This declaration explicitly indicates the file types
(extensions) that your app wants to access on the removable devices.
The app can only enumerate, create, or change files that have the file
types declared in the app manifest. For more info, see Handle file
activation.
According to your question, you have handled the first prerequisite, but you also need to satisfy the second - which is specifying the file types your app works with. This can be done in the Package.appxmanifest
Declarations tab. There you select File Type Associations in the drop down and fill out the required fields.
The reason access to removable storage is limited to only the file types you specify is an additional security measure, so that the user can rest assured that the app does not do anything harmful. If you need full access to a file system location, you will need to use the built-in FolderPicker
or use the broadFilesystemAccess
capability (which is however a restricted capability and it is verified during Microsoft Store certification, whether the app has actually a good reason to declare it).
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
As the documentation states, there are two prerequisites for using the KnownFolders.RemovableDevices
folder:
To access the removable devices folder, you must:
- In the app manifest, specify the Removable Storage capability.
- In the app manifest, register at least one File Type Association declaration. This declaration explicitly indicates the file types
(extensions) that your app wants to access on the removable devices.
The app can only enumerate, create, or change files that have the file
types declared in the app manifest. For more info, see Handle file
activation.
According to your question, you have handled the first prerequisite, but you also need to satisfy the second - which is specifying the file types your app works with. This can be done in the Package.appxmanifest
Declarations tab. There you select File Type Associations in the drop down and fill out the required fields.
The reason access to removable storage is limited to only the file types you specify is an additional security measure, so that the user can rest assured that the app does not do anything harmful. If you need full access to a file system location, you will need to use the built-in FolderPicker
or use the broadFilesystemAccess
capability (which is however a restricted capability and it is verified during Microsoft Store certification, whether the app has actually a good reason to declare it).
As the documentation states, there are two prerequisites for using the KnownFolders.RemovableDevices
folder:
To access the removable devices folder, you must:
- In the app manifest, specify the Removable Storage capability.
- In the app manifest, register at least one File Type Association declaration. This declaration explicitly indicates the file types
(extensions) that your app wants to access on the removable devices.
The app can only enumerate, create, or change files that have the file
types declared in the app manifest. For more info, see Handle file
activation.
According to your question, you have handled the first prerequisite, but you also need to satisfy the second - which is specifying the file types your app works with. This can be done in the Package.appxmanifest
Declarations tab. There you select File Type Associations in the drop down and fill out the required fields.
The reason access to removable storage is limited to only the file types you specify is an additional security measure, so that the user can rest assured that the app does not do anything harmful. If you need full access to a file system location, you will need to use the built-in FolderPicker
or use the broadFilesystemAccess
capability (which is however a restricted capability and it is verified during Microsoft Store certification, whether the app has actually a good reason to declare it).
answered Nov 12 at 9:43
Martin Zikmund
22.3k33058
22.3k33058
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
add a comment |
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
Thanks a lot. I found the File Type Associations in the Declarations tab, but I can't find any tutorial or guide of MSDN. Is there any tutorial can recommend? Thank you.
– 102425074
Nov 12 at 12:10
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
To properly fill out the declaration try following the docs here - docs.microsoft.com/en-us/windows/uwp/launch-resume/…
– Martin Zikmund
Nov 12 at 12:21
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Thank you, let me try first.
– 102425074
Nov 12 at 12:23
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Well, I tried and it works, never report an error yet. Thank you!
– 102425074
Nov 13 at 3:09
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
Great, happy coding :-) !
– Martin Zikmund
Nov 13 at 6:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247966%2fwhy-storagefile-getfilesasync-crash-in-dll%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You may need to declare file type association and handle the specific file types you declare.
– kennyzx
Nov 11 at 12:38
@kennyzx I want to make a custom FileOpenPicker to read the txt file in removable devices, and the FileOpenPicker is not a control so that I can't overwrite it. I can only write a usercontrol to do this. When I try to read the files name in the directory, it occurs this error.
– 102425074
Nov 12 at 0:23
@kennyzx What's more,I found a article maybe about what you said the file type association in grogansoft.com/blog/?p=1197 . I think that is much more different from my situation.
– 102425074
Nov 12 at 0:25