簡體   English   中英

Bot中的MS Bot c#自定義視覺預測端點錯誤“不支持給定路徑的格式。”

[英]MS Bot c# Custom Vision prediction endpoint error in Bot “The given path’s format is not supported.”

已創建了一個演示自定義視覺對象檢測的簡單項目。 一切都很好。 但是問題出在我通過Bot聊天附加圖片時,它引發了免責聲明

The given path’s format is not supported...
at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare

這是完整的代碼...

 public class Vision:IDialog<Object>
 {
     Guid ProjectId = Guid.Empty;

     const string PredictionKey = "<MY KEY>";

     public Task StartAsync(IDialogContext context)
     {
         context.Wait(MessageReceivedAsync);

         return Task.CompletedTask;
     }

     private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result)
     {
         await context.PostAsync("Hello there. Nice to meet you!");
         context.Wait(ResumeAfterOperationSelecting);

     }

     private async Task ResumeAfterOperationSelecting(IDialogContext context, IAwaitable<object> result)
     {
         PromptDialog.Attachment(
             context: context,
             prompt: "Upload Image to perform operation",
             resume: ResumeAfterRecievingAttachment
         );
     }

     private async Task ResumeAfterRecievingAttachment(IDialogContext context, IAwaitable<IEnumerable<Attachment>> result)
     {
         var images = await result;

         foreach (var image in images)
         {
             ProjectId = new Guid("<MY PROJECT ID>");

             PredictionEndpoint endpoint = new PredictionEndpoint() { ApiKey = PredictionKey };

             var results = endpoint.PredictImage(ProjectId, File.OpenRead(image.ContentUrl));

             foreach (var c in results.Predictions)
             {
                 await context.PostAsync($"{c.TagName}, {c.Probability}");
             }

         }
         await context.PostAsync("Hello there. Have done!");

         context.Wait(MessageReceivedAsync);
     }

}

所以錯誤發生在這條線上

var results = endpoint.PredictImage(ProjectId, File.OpenRead(image.ContentUrl));

這是完整的免稅信息

 The given path’s format is not supported.     
 at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String  fullPath)
 at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
 at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share)
 at SimpleEchoBot.Dialogs.Vision.<ResumeAfterRecievingAttachment>d__5.MoveNext()
 in C:\Users\AbdiHakim\Music\reres-src\Dialogs\Vision.cs:line 55
 — End of stack trace from previous location where exception was thrown —
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume1.<Rest>d__5.MoveNext()
 in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 164 --- End of stack trace from previous location where exception was thrown --- 
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
 at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext()
 in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\…

我應該用這條線做什么。 根據我的觀點,由於Microsoft Bot Framework可能不允許System.IO實現文件映像附件。 如果是這樣,我該如何實現它,以便預測點URL可以讀取機器人附件的圖像URL。

 NOTE: Prediction endpoint requires the method to have format like this.. 

endpoint.Prediction(,)

Json Bot Framework Emulator的輸出是這個

 "type": "message",
  "attachments": [
    {
      "contentType": "image/jpeg",
      "contentUrl": "blob:file:///a3f2d3e1-e295-46fe-b434-b05f3905301c",
      "name": "11.jpg"
    }
  ],

我也不知道您的URL也指向哪種文件(Azure Blob存儲?)。 消息很清楚-File.OpenRead不支持您嘗試訪問blob:file://的文件類型。

https://msdn.microsoft.com/en-us/library/system.io.file.openread(v=vs.110).aspx

這是來自MSDN的可接受路徑列表:

在接受路徑的成員中,該路徑可以引用文件或僅引用目錄。 指定的路徑還可以引用服務器和共享名的相對路徑或通用命名約定(UNC)路徑。 例如,以下所有都是可接受的路徑:

在C#中為“ c:\\ MyDir \\ MyFile.txt”,在Visual Basic中為“ c:\\ MyDir \\ MyFile.txt”。

在C#中為“ c:\\ MyDir”,在Visual Basic中為“ c:\\ MyDir”。

在C#中為“ MyDir \\ MySubdir”,在Visual Basic中為“ MyDir \\ MySubDir”。

在C#中為“ \\\\ MyServer \\ MyShare”,在Visual Basic中為“ \\ MyServer \\ MyShare”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM