小编Chr*_*tts的帖子

从Microsoft UWP上的异步方法返回Task <string>

我一直在尝试从异步方法返回Task,它在可移动设备上创建一个文件夹并将其保存以备将来在应用程序中使用.但是,我得到了可怕的WME1039,说我没有使用有效的Windows运行时类型.我在这里检查了有效的运行时类型: Windows运行时基本数据类型,字符串是一个有效的类型..我完全陷入困境,并不知道从哪里开始!我是否遗漏了async/await模式的基本内容?我现在的代码如下所示,请原谅我的粗糙,我只是简单地填写了这个概念!

来电代码:

await LoadExtDrive();
Run Code Online (Sandbox Code Playgroud)

方法:

public async Task<string> LoadExtDrive()
{
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    // Get the first child folder, which represents the SD card.
    IReadOnlyList<StorageFolder> tmp;
    try
    {
        tmp = await externalDevices.GetFoldersAsync();
    }
    catch (Exception ex)
    {
        throw;
    }
    StorageFolder sdCard = ( tmp).FirstOrDefault();
    if (sdCard != null)
    {
     // An Removable device is present..
     var dbdir = 
     await sdCard.CreateFolderAsync(APP_DB_DIR_NAME, CreationCollisionOption.OpenIfExists);
     var dirToken = 
     Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(dbdir);
     return dirToken;
    }
    else
    {
        // No SD card is present.
        return …
Run Code Online (Sandbox Code Playgroud)

.net c# asynchronous windows-10-iot-core uwp

5
推荐指数
1
解决办法
1813
查看次数

具有Dot net核心的自托管In Process Web API

我正在尝试调查3.0版已经发布到点网核心的可行性。我们的关键组件之一允许我们(私有)的nuget创建自己的WebAPI,向消费者提供事件和方法。这支持远程服务控制或远程服务配置之类的功能,从而允许api提供远程配置设置/检索等。

此功能是我们微服务架构当前工作方式的关键。

我正在尝试使用dotnet核心复制此内容,但是,我一直在努力寻找直接等效的教程/场景。我们基本上遵循此处详述的过程:

https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api

但是,在检查了nuget软件包的兼容性(并且一切看起来都很好..)之后,我现在在调用时仅获得空引用异常 WebApp.Start<Startup>(baseaddress);

空引用异常显然是由于nuget软件包与.net内核不兼容而调用的,请参见此处:

Owin在启动.Net Core 2.0上遇到过NullReferenceException-设置吗?

链接中提供的解决方案是一种方法,但是它使用了第三方应用程序-NancyFx。有什么方法可以以当前形式使用dotnet core实现相同的功能?以前有足够的有关自托管的文档,但是不幸的是,鉴于aspnet内核以其自己的进程运行,因此很难找到解决方案!

有人可以在这里指出正确的方向吗?

代码如下所示

//the external library would contain all this code. I.e. this could present the configuration endpoints as mentioned above.

public class Startup
{
    // This code configures Web API. The Startup class is specified as a type
    // parameter in the WebApp.Start method.
    public void Configuration(IAppBuilder appBuilder)
    {
        // Configure Web API for self-host. 
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { …
Run Code Online (Sandbox Code Playgroud)

c# self-hosting owin .net-core

5
推荐指数
1
解决办法
147
查看次数