嗨,我已經下載了一些源代碼,並且我在開箱時遇到了一些重大問題。我一直無法從開發人員那裏得到答案,我也沒有看到其他人提出這個問題,但我看了看,看了看,我不知道發生了什麼問題。未將對象引用設置爲對象的實例。 BitShuva
我不斷收到此錯誤:
Server Error in '/' Application.
Object reference not set to an instance of an object.
說明:
An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
異常詳細信息:
System.NullReferenceException: Object reference not set to an instance of an object.
源錯誤:
Line 157: // Expected ID is standard Raven ID: "songs/4321"
Line 158: const string expectedIdPrefix = "songs/";
Line 159: if (song.Id.StartsWith(expectedIdPrefix, StringComparison.OrdinalIgnoreCase))
Line 160: {
Line 161: throw new ArgumentException("ID wasn't in the expected format.");
Visual Studio強調了這一點代碼。 (用** **表示)
using (var session = Get.A<IDocumentStore>().OpenSession())
{
var songFiles = Directory
.EnumerateFiles(Server.MapPath("~/content/sample/music"), "*.mp3")
.Select(f => new
{
Song = new Song(Path.GetFileName(f)),
FilePath = f
})
.ToArray();
songFiles.ForEach(async f => **await f.Song.UploadMp3ToCdn(f.FilePath));**
if (!session.Query<Song>().Any())
{
songFiles.ForEach(s => session.Store(s));
session.SaveChanges();
}
}
是你的查詢var songFiles = ...正在返回一些東西。你是否驗證過songFiles不爲空? – Guanxi