起步只有3個文件:CoreRun.exe, coreclr.dll, mscorlib.dll, HelloWorld.exe
運行命令:CoreRun HelloWorld.exe
出錯:
Assert failure(PID 9672 [0x000025c8], Thread: 16280 [0x3f98]): 0 ! + 0x0 (0x00000000`00000000) File: e:\dev\github\dotnet\coreclr\src\utilcode\ccomprc.cpp, Line: 814 Image : E:\Dev\GitHub\DotNet\CoreClrHelloWorld\runtime_windows\CoreRun.exe **** MessageBox invoked, title 'CoreRun.exe - Assert Failure (PID 9672, Thread 1 6280/3f98) ' **** 0 ! + 0x0 (0x00000000`00000000) e:\dev\github\dotnet\coreclr\src\utilcode\ccomprc.cpp, Line: 814
啟動Visual Studio進行調試,發現是因為少了mscorrc.debug.dll這個文件。
this 0x000007fdccd146b0 {coreclr.dll!CCompRC CCompRC::m_DefaultResourceDll} {m_Primary={m_LangId=0x000007fdccd146b0 L"en-US" ...} ...} CCompRC * m_Primary {m_LangId=0x000007fdccd146b0 L"en-US" m_hInst=0x0000000000000000 m_fMissing=1 } CCulturedHInstance m_pHash 0x0000000000000000 CCulturedHInstance * m_nHashSize 0 int m_csMap 0x000000a31a9cb933 void * m_pResourceFile 0x000007fdcc9cd200 L"mscorrc.debug.dll" const wchar_t * m_fpGetThreadUICultureId 0x000007fdcbde5ac8 {coreclr.dll!GetThreadUICultureId(wchar_t[85] *)} int (wchar_t[85] *) * m_fpGetThreadUICultureNames 0x000007fdcbde5d68 {coreclr.dll!GetThreadUICultureNames(StringArrayList *)} HRESULT (StringArrayList *) *
將mscorrc.debug.dll復制過來,繼續運行,出現下面的錯誤:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass embly 'System.Console, Version=999.999.999.0, Culture=neutral, PublicKeyToken=b0 3f5f7f11d50a3a' or one of its dependencies. The system cannot find the file spec ified. at Program.Main(String[] args)
需要System.Console程序集,將之從corefx編譯出來的程序集中復制過來。
繼續運行,又出錯,這次是需要System.Runtime.dll,從corefx的packages文件夾(nuget packages)中復制過來(注:lib\net45子文件夾)
接下來又需要System.IO.dll,也是從corefx的packages文件夾中復制。
再接下來還需要從corefx的packages文件夾中復制3個程序集:System.Threading.dll, System.IO.FileSystem.Primitives.dll, System.Diagnostics.Debug.dll。
這時,當前文件夾一共有11個文件:
coreclr.dll CoreRun.exe HelloWorld.exe mscorlib.dll mscorrc.debug.dll System.Console.dll System.Diagnostics.Debug.dll System.IO.dll System.IO.FileSystem.Primitives.dll System.Runtime.dll System.Threading.dll
繼續運行,出現新的錯誤:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or ass embly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ' or one of its dependencies. The system cannot find the file specified. at System.ConsolePal.WindowsConsoleStream..ctor(IntPtr handle, FileAccess acc ess) at System.ConsolePal.GetStandardFile(IntPtr handle, FileAccess access) at System.ConsolePal.OpenStandardOutput() at System.Console.OpenStandardOutput() at System.Console.<>c__DisplayClass3.<get_Out>b__4() at System.Console.EnsureInitialized[T](T& field, Func`1 initializer) at System.Console.get_Out() at System.Console.WriteLine(String value) at Program.DrawWindows() at Program.Main(String[] args)
System程序集就是mscorlib.dll,明明有這個文件,卻說找不到。
后來換成corefx中packages\Microsoft.DotNet.CoreCLR.1.0.3-prerelease\lib\aspnetcore50中的mscrolib.dll,就不錯這個錯誤了。
但是運行CoreRun HelloWorld.exe卻無任何輸出,換成CoreRun -v HelloWorld.exe出現下面的錯誤:
HOSTLOG: Finding GetCLRRuntimeHost(...) HOSTLOG: Calling GetCLRRuntimeHost(...) HOSTLOG: Setting ICLRRuntimeHost2 startup flags HOSTLOG: Starting ICLRRuntimeHost2 HOSTLOG: Failed to start CoreCLR. ERRORCODE: 0x80004005/E_FAIL HOSTLOG: Execution failed
一步一步就到這里,暫時沒找到解決方法。