【发布时间】:2020-02-13 19:33:23
【问题描述】:
我正在使用 Flurl 从 SharePoint 下载文件。 但是,它会导致“配置系统初始化失败”错误。
这是我的代码:
var url = "https://mysite.sharepoint.com"
.AppendPathSegment("/_api/web/Shared%20Documents/test.xlsx")
.SetQueryParams(new
{
api_key = ConfigurationManager.AppSettings["MYAPIKEY"],
max_results = 20,
q = "Don't worry, I'll get encoded!"
})
.SetFragment("after-hash");
//returns fullpath for App-specific storage, where inventory data is stored
string fullpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
var path = await "https://mysite.sharepoint.com/Shared%20Documents/test.xlsx"
.DownloadFileAsync(fullpath);
我添加的 API 密钥是在 Azure AD 上生成的。
我怀疑该错误是由我的 app.config 文件引起的,但是因为我使用的是 Xamarin.Forms,所以我最初没有 app.config 文件。 为了解决这个问题,我使用了PCLAppConfig 库,并按照链接中的说明进行操作。
我的问题是,我不确定应该在 app.config 文件中放入什么。配置文件的当前内容如下,我尝试了一些不同的东西,但我总是得到同样的错误。
<configuration>
<appSettings>
<add key="api_key" value="MYAPIKEY" />
</appSettings>
</configuration>
这是调用堆栈,以防万一:
> 0x3F in GraphTutorial.DownloadFile.Flurlcall at D:\Schule\Diplomarbeit\GraphTutorial\CalendarPage.xaml.cs:35,17 C#
0x33 in System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<GraphTutorial.DownloadFile.<Flurlcall>d__1> C#
0x38 in GraphTutorial.DownloadFile.Flurlcall C#
0x11 in Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked at D:\a\1\s\Xamarin.Forms.Core\Button.cs:177,47 C#
0x20 in Xamarin.Forms.ButtonElement.ElementClicked at D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61,5 C#
0x2 in Xamarin.Forms.Button.SendClicked at D:\a\1\s\Xamarin.Forms.Core\Button.cs:163,32 C#
0x4 in Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick at D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25,4 C#
0xD in Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick at D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:71,45 C#
0x13 in Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ C#
0x17 in Android.Runtime.DynamicMethodNameCounter.48 C#
【问题讨论】:
-
也许这会有所帮助:stackoverflow.com/questions/6436157/…。否则,请提供异常的完整堆栈跟踪。不确定我是否可以提供帮助,但我相当肯定这与 Flurl 无关。
-
我将堆栈跟踪添加到问题中。我尝试添加
但它也没有帮助。
标签: xamarin.forms app-config flurl