Mission: FILES MASTER
Task: Upload a file using API
Please, describe your problem here.
Hi, I am trying to work through the mission to upload a file via the .NET API. I have created a simple console project, .Net Core, Visual Studio 2019. I have copied and pasted the sample code from the documentation on the site. My code looks like this (I have changed the API key and APP ID):
using System;
using System.Data;
using System.IO;
using BackendlessAPI;
using BackendlessAPI.Async;
namespace BackEndless
{
class Program
{
static void Main(string[] args)
{
const string appID = “???”;
const string apiKey = “???”;
Backendless.InitApp(appID, apiKey);
Console.WriteLine("Hello World!");
UploadFile();
}
static void UploadFile()
{
AsyncCallback<BackendlessAPI.File.BackendlessFile> callback = new AsyncCallback<BackendlessAPI.File.BackendlessFile>(
result =>
{
System.Console.WriteLine("File uploaded. URL - " + result.FileURL);
},
fault =>
{
System.Console.WriteLine("Error - " + fault);
});
FileStream fs = new FileStream(@"c:\projects\BackEndless\superfast.html", FileMode.Open, FileAccess.Read);
BackendlessAPI.Backendless.Files.Upload(fs, "mission", callback);
}
}
}
The exception that I receive is shown here:
System.TypeLoadException
HResult=0x80131522
Message=Could not load type ‘BackendlessAPI.Backendless’ from assembly ‘BackEndless, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.
Source=
StackTrace:
The output in the output console is shown here:
‘BackEndless.exe’ (CoreCLR: DefaultDomain): Loaded ‘C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.9\System.Private.CoreLib.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
‘BackEndless.exe’ (CoreCLR: clrhost): Loaded ‘C:\Projects\BackEndless\bin\Debug\netcoreapp3.1\BackEndless.dll’. Symbols loaded.
‘BackEndless.exe’ (CoreCLR: clrhost): Loaded ‘C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.9\System.Runtime.dll’. Skipped loading symbols. Module is optimized and the debugger option ‘Just My Code’ is enabled.
An unhandled exception of type ‘System.TypeLoadException’ occurred in Unknown Module.
Could not load type ‘BackendlessAPI.Backendless’ from assembly ‘BackEndless, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.
Any ideas what might be goiung wrong? I tsounds like something blew up in a constructor call, but the exception info doesn’t give much of a hint about the exact nature of the problem.
Thanks,
Aaron