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.

enter image description here


What's wrong with it? Would you please tell me how to solve this? Thank you.










share|improve this question























  • 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














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.

enter image description here


What's wrong with it? Would you please tell me how to solve this? Thank you.










share|improve this question























  • 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












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.

enter image description here


What's wrong with it? Would you please tell me how to solve this? Thank you.










share|improve this question















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.

enter image description here


What's wrong with it? Would you please tell me how to solve this? Thank you.







uwp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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).






share|improve this answer




















  • 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










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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

























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).






share|improve this answer




















  • 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














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).






share|improve this answer




















  • 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












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).






share|improve this answer












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).







share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto