We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can't download/saveas files anymore since upgrading to Blazor Preview 9

Thread ID:

Created:

Updated:

Platform:

Replies:

147476 Sep 11,2019 11:44 PM UTC Sep 16,2019 04:59 AM UTC Blazor 5
loading
Tags: File Manager
Eric
Asked On September 11, 2019 11:45 PM UTC

When using the same old: 

public static class FileUtils
    {
        public static Task SaveAs(this IJSRuntime js, string filename, byte[] data)
        => js.InvokeAsync<object>(
           "saveAsFile",
           filename,
           Convert.ToBase64String(data));
    }

which was working great on preview 8, I can start to debug, but when I try to download the file, I get the error:

blazor.webassembly.js:1 WASM: Unhandled exception rendering component:
d.printErr @ blazor.webassembly.js:1
blazor.webassembly.js:1 WASM: System.MissingMethodException: Method not found: System.Threading.Tasks.Task`1 Microsoft.JSInterop.IJSRuntime.InvokeAsync(string,object[])

If I try to change the FileUtils to:

public static class FileUtils
    {
        public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
        => js.InvokeAsync<object>(
           "saveAsFile",
           filename,
           Convert.ToBase64String(data));
    }
I get a straight error message that says: 
Cannot implicitly convert type 'System.Threading.Tasks.Task<object> to 'System.Threading.Tasks.ValueTask<object>'
Any help would be greatly appreciated.

Prem Kumar Madhan Raj [Syncfusion]
Replied On September 12, 2019 12:57 PM UTC

Hi Eric, 
 
Greeting from Syncfusion. 
 
We have checked with your query that you can’t download the files. Since the result of the method is a Task, we need to use the await for the task to get completed henceforth the method must be a declared as an asynchronous. So, kindly make the method as async as shown in the below code snippet to resolve the issue at your end. 
 
public static class FileUtils 
    { 
        public async static ValueTask SaveAs(this IJSRuntime js, string filename, byte[] data) 
       => js.InvokeAsync<object>( 
          "saveAsFile", 
          filename, 
          Convert.ToBase64String(data)); 
    } 
 
 
Regards, 
 
Prem Kumar M 


Eric
Replied On September 12, 2019 02:09 PM UTC

Hi Eric, 
 
Greeting from Syncfusion. 
 
We have checked with your query that you can’t download the files. Since the result of the method is a Task, we need to use the await for the task to get completed henceforth the method must be a declared as an asynchronous. So, kindly make the method as async as shown in the below code snippet to resolve the issue at your end. 
 
public static class FileUtils 
    { 
        public async static ValueTask SaveAs(this IJSRuntime js, string filename, byte[] data) 
       => js.InvokeAsync<object>( 
          "saveAsFile", 
          filename, 
          Convert.ToBase64String(data)); 
    } 
 
 
Regards, 
 
Prem Kumar M 


Hi Prem,

Thanks a lot for this. 

While using async helped, as I am not getting any compiling errors with:

 public static class FileUtils
    {
        public async static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
       => await js.InvokeAsync<object>(
          "saveAsFile",
          filename,
          Convert.ToBase64String(data));
    }


These are the errors I am getting:

Failed to load resource: the server responded with a status of 404 (Not Found)
blazor.webassembly.js:1 WASM: Unhandled exception rendering component:
blazor.webassembly.js:1 WASM: System.MissingMethodException: Method not found: System.Threading.Tasks.Task`1<!!0> Microsoft.JSInterop.IJSRuntime.InvokeAsync<!0>(string,object[])
blazor.webassembly.js:1 WASM:   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) <0x4851930 + 0x00038> in <d9c16b0fee7344919775df5988c885d0>:0 
blazor.webassembly.js:1 WASM:   at System.Runtime.CompilerServices.AsyncValueTaskMethodBuilder`1[TResult].Start[TStateMachine] (TStateMachine& stateMachine) <0x4851350 + 0x0000c> in <d9c16b0fee7344919775df5988c885d0>:0 
blazor.webassembly.js:1 WASM:   at SchamToolsApp.Shared.Models.FileUtils.SaveAs (Microsoft.JSInterop.IJSRuntime js, System.String filename, System.Byte[] data) [0x00021] in <623038d1c8c04d199688b8aa77410cab>:0 
blazor.webassembly.js:1 WASM:   at SchamToolsApp.Client.Pages.SiteCompanies.Companies.CreatePowerPoint (SchamToolsApp.Shared.Models.Company company) [0x00d28] in C:\Users\erics\source\repos\SchamToolsApp\SchamToolsApp\Client\Pages\SiteCompanies\Companies.razor:475 
blazor.webassembly.js:1 WASM:   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x48480d0 + 0x00118> in <cc81133ac6304aada69282c517e2b811>:0 
blazor.webassembly.js:1 WASM:   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask (System.Threading.Tasks.Task taskToHandle) <0x34c1890 + 0x000f4> in <cc81133ac6304aada69282c517e2b811>:0 


Like I said before, it was working great on Preview 8.


Prem Kumar Madhan Raj [Syncfusion]
Replied On September 13, 2019 01:17 PM UTC

Hi Eric, 

Thanks for contacting Syncfusion support. 
 
  
The error log which was shared from your end is run time error. From the provided error-log, we can’t predict in exact use case or what you have tried in your application. Since the error was originated your application-level method(createPowerPoint). So, can you please share the below details will be more helpful to provide a proper solution for your requirement. 
 
  1. Share the code blocks of the application.
  2. If possible share the application
 
Regards, 
Prem Kumar M 


Eric
Replied On September 13, 2019 01:42 PM UTC

Hi Eric, 

Thanks for contacting Syncfusion support. 
 
  
The error log which was shared from your end is run time error. From the provided error-log, we can’t predict in exact use case or what you have tried in your application. Since the error was originated your application-level method(createPowerPoint). So, can you please share the below details will be more helpful to provide a proper solution for your requirement. 
 
  1. Share the code blocks of the application.
  2. If possible share the application
 
Regards, 
Prem Kumar M 


Hi Prem,

I was able to fix it. Before Blazor preview 9, having FileUtils with the models in the Shared project worked fine. It seems now it has to be in the client side. I created a new folder there and referenced it. Now all working fine. Thank you!

Prem Kumar Madhan Raj [Syncfusion]
Replied On September 16, 2019 04:59 AM UTC

Hi Eric, 
 
Thanks for the update. 
 
We are happy to hear that the issue has been resolved at your end. Please let us know if you need any further assistance, we will be happy to assist you. 
 
Regards, 
 
Prem Kumar M 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon