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. Image for the cookie policy date

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

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.

5 Replies

PK Prem Kumar Madhan Raj Syncfusion Team 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 



ER Eric replied to Prem Kumar Madhan Raj 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.



PK Prem Kumar Madhan Raj Syncfusion Team 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 



ER Eric replied to Prem Kumar Madhan Raj 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!


PK Prem Kumar Madhan Raj Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon