Fail fast on .NET Full Framework and log exceptions in hostfxr utility (#533)

This commit is contained in:
Justin Kotalik 2018-02-04 20:54:12 -08:00 committed by GitHub
parent 462c1c042a
commit e035d0ed96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 290 additions and 99 deletions

View File

@ -3,33 +3,33 @@
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="Package Versions"> <PropertyGroup Label="Package Versions">
<InternalAspNetCoreSdkPackageVersion>2.1.0-preview1-15677</InternalAspNetCoreSdkPackageVersion> <InternalAspNetCoreSdkPackageVersion>2.1.0-preview2-15693</InternalAspNetCoreSdkPackageVersion>
<MicrosoftAspNetCoreAllPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreAllPackageVersion> <MicrosoftAspNetCoreAllPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreAllPackageVersion>
<MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreAuthenticationCorePackageVersion> <MicrosoftAspNetCoreAuthenticationCorePackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreAuthenticationCorePackageVersion>
<MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHostingAbstractionsPackageVersion> <MicrosoftAspNetCoreHostingAbstractionsPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHostingAbstractionsPackageVersion>
<MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHostingPackageVersion> <MicrosoftAspNetCoreHostingPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHostingPackageVersion>
<MicrosoftAspNetCoreHttpExtensionsPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHttpExtensionsPackageVersion> <MicrosoftAspNetCoreHttpExtensionsPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHttpExtensionsPackageVersion>
<MicrosoftAspNetCoreHttpOverridesPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHttpOverridesPackageVersion> <MicrosoftAspNetCoreHttpOverridesPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHttpOverridesPackageVersion>
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHttpPackageVersion> <MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHttpPackageVersion>
<MicrosoftAspNetCoreHttpSysSourcesPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreHttpSysSourcesPackageVersion> <MicrosoftAspNetCoreHttpSysSourcesPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreHttpSysSourcesPackageVersion>
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-28214</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion> <MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-30015</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreServerKestrelPackageVersion> <MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreServerKestrelPackageVersion>
<MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreTestHostPackageVersion> <MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreTestHostPackageVersion>
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreTestingPackageVersion> <MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreTestingPackageVersion>
<MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview2-28214</MicrosoftAspNetCoreWebUtilitiesPackageVersion> <MicrosoftAspNetCoreWebUtilitiesPackageVersion>2.1.0-preview2-30015</MicrosoftAspNetCoreWebUtilitiesPackageVersion>
<MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion> <MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion>
<MicrosoftExtensionsConfigurationJsonPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsConfigurationJsonPackageVersion> <MicrosoftExtensionsConfigurationJsonPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsConfigurationJsonPackageVersion>
<MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsLoggingAbstractionsPackageVersion> <MicrosoftExtensionsLoggingAbstractionsPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsLoggingAbstractionsPackageVersion>
<MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsLoggingConsolePackageVersion> <MicrosoftExtensionsLoggingConsolePackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsLoggingConsolePackageVersion>
<MicrosoftExtensionsLoggingDebugPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsLoggingDebugPackageVersion> <MicrosoftExtensionsLoggingDebugPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsLoggingDebugPackageVersion>
<MicrosoftExtensionsLoggingPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsLoggingPackageVersion> <MicrosoftExtensionsLoggingPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsLoggingPackageVersion>
<MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsLoggingTestingPackageVersion> <MicrosoftExtensionsLoggingTestingPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsLoggingTestingPackageVersion>
<MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsOptionsPackageVersion> <MicrosoftExtensionsOptionsPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsOptionsPackageVersion>
<MicrosoftExtensionsPlatformAbstractionsPackageVersion>1.1.0</MicrosoftExtensionsPlatformAbstractionsPackageVersion> <MicrosoftExtensionsPlatformAbstractionsPackageVersion>1.1.0</MicrosoftExtensionsPlatformAbstractionsPackageVersion>
<MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview2-28214</MicrosoftExtensionsSecurityHelperSourcesPackageVersion> <MicrosoftExtensionsSecurityHelperSourcesPackageVersion>2.1.0-preview2-30015</MicrosoftExtensionsSecurityHelperSourcesPackageVersion>
<MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion> <MicrosoftNETCoreApp20PackageVersion>2.0.0</MicrosoftNETCoreApp20PackageVersion>
<MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion> <MicrosoftNETCoreApp21PackageVersion>2.1.0-preview2-26130-04</MicrosoftNETCoreApp21PackageVersion>
<MicrosoftNetHttpHeadersPackageVersion>2.1.0-preview2-28214</MicrosoftNetHttpHeadersPackageVersion> <MicrosoftNetHttpHeadersPackageVersion>2.1.0-preview2-30015</MicrosoftNetHttpHeadersPackageVersion>
<MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion> <MicrosoftNETTestSdkPackageVersion>15.3.0</MicrosoftNETTestSdkPackageVersion>
<MicrosoftWebAdministrationPackageVersion>7.0.0</MicrosoftWebAdministrationPackageVersion> <MicrosoftWebAdministrationPackageVersion>7.0.0</MicrosoftWebAdministrationPackageVersion>
<SystemBuffersPackageVersion>4.5.0-preview2-26130-01</SystemBuffersPackageVersion> <SystemBuffersPackageVersion>4.5.0-preview2-26130-01</SystemBuffersPackageVersion>

View File

@ -1,2 +1,2 @@
version:2.1.0-preview1-15677 version:2.1.0-preview2-15693
commithash:76ac40e0d67a4cc253cb4ecf35dda18c90a272ac commithash:bbc5ba7e5acafd36dcdcf865d528660892b6418a

View File

@ -161,7 +161,9 @@ APPLICATION_INFO::EnsureApplicationCreated()
BOOL fLocked = FALSE; BOOL fLocked = FALSE;
APPLICATION* pApplication = NULL; APPLICATION* pApplication = NULL;
STACK_STRU(struFileName, 300); // >MAX_PATH STACK_STRU(struFileName, 300); // >MAX_PATH
STRU hostFxrDllLocation; STRU struHostFxrDllLocation;
PWSTR* pwzArgv;
DWORD dwArgCount;
if (m_pApplication != NULL) if (m_pApplication != NULL)
{ {
@ -170,10 +172,24 @@ APPLICATION_INFO::EnsureApplicationCreated()
if ( m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS ) if ( m_pConfiguration->QueryHostingModel() == APP_HOSTING_MODEL::HOSTING_IN_PROCESS )
{ {
if ( FAILED( hr = HOSTFXR_UTILITY::GetHostFxrParameters( m_pConfiguration ) ) ) if (FAILED(hr = HOSTFXR_UTILITY::GetHostFxrParameters(
g_hEventLog,
m_pConfiguration->QueryProcessPath()->QueryStr(),
m_pConfiguration->QueryApplicationPhysicalPath()->QueryStr(),
m_pConfiguration->QueryArguments()->QueryStr(),
&struHostFxrDllLocation,
&dwArgCount,
&pwzArgv)))
{ {
goto Finished; goto Finished;
} }
if (FAILED(hr = m_pConfiguration->SetHostFxrFullPath(struHostFxrDllLocation.QueryStr())))
{
goto Finished;
}
m_pConfiguration->SetHostFxrArguments(dwArgCount, pwzArgv);
} }
hr = FindRequestHandlerAssembly(); hr = FindRequestHandlerAssembly();

View File

@ -56,4 +56,4 @@ ASPNET_CORE_GLOBAL_MODULE::OnGlobalApplicationStop(
// Return processing to the pipeline. // Return processing to the pipeline.
return GL_NOTIFICATION_CONTINUE; return GL_NOTIFICATION_CONTINUE;
} }

View File

@ -110,6 +110,43 @@ Language=English
%1 %1
. .
Messageid=1014
SymbolicName=ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP
Language=English
%1
.
Messageid=1015
SymbolicName=ASPNETCORE_EVENT_PORTABLE_APP_DOTNET_MISSING
Language=English
%1
.
Messageid=1016
SymbolicName=ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND
Language=English
%1
.
Messageid=1017
SymbolicName=ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND
Language=English
%1
.
Messageid=1018
SymbolicName=ASPNETCORE_EVENT_INPROCESS_THREAD_EXCEPTION
Language=English
%1
.
Messageid=1019
SymbolicName=ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND
Language=English
%1
.
; ;
;#endif // _ASPNETCORE_MODULE_MSG_H_ ;#endif // _ASPNETCORE_MODULE_MSG_H_
; ;

View File

@ -525,4 +525,4 @@ Finished:
} }
return hr; return hr;
} }

View File

@ -253,7 +253,7 @@ public:
VOID VOID
SetHostFxrArguments( SetHostFxrArguments(
DWORD dwArgc, DWORD dwArgc,
PCWSTR* ppStrArguments PWSTR* ppStrArguments
) )
{ {
if (m_ppStrArguments != NULL) if (m_ppStrArguments != NULL)
@ -319,6 +319,6 @@ private:
APP_HOSTING_MODEL m_hostingModel; APP_HOSTING_MODEL m_hostingModel;
ENVIRONMENT_VAR_HASH* m_pEnvironmentVariables; ENVIRONMENT_VAR_HASH* m_pEnvironmentVariables;
STRU m_struHostFxrLocation; STRU m_struHostFxrLocation;
PCWSTR* m_ppStrArguments; PWSTR* m_ppStrArguments;
DWORD m_dwArgc; DWORD m_dwArgc;
}; };

View File

@ -25,36 +25,98 @@ HOSTFXR_UTILITY::~HOSTFXR_UTILITY()
// //
HRESULT HRESULT
HOSTFXR_UTILITY::GetStandaloneHostfxrParameters( HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
PCWSTR pwzExePath, PCWSTR pwzExeAbsolutePath, // includes .exe file extension.
ASPNETCORE_CONFIG *pConfig PCWSTR pcwzApplicationPhysicalPath,
PCWSTR pcwzArguments,
HANDLE hEventLog,
_Inout_ STRU* struHostFxrDllLocation,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
STRU struDllPath; STRU struDllPath;
STRU struArguments; STRU struArguments;
STRU struHostFxrPath;
STRU struRuntimeConfigLocation;
STRU strEventMsg;
DWORD dwPosition; DWORD dwPosition;
if (FAILED(hr)) // Obtain the app name from the processPath section.
if ( FAILED( hr = struDllPath.Copy( pwzExeAbsolutePath ) ) )
{ {
goto Finished; goto Finished;
} }
if (FAILED(hr = struDllPath.Copy(pwzExePath))) dwPosition = struDllPath.LastIndexOf( L'.', 0 );
{ if ( dwPosition == -1 )
goto Finished;
}
dwPosition = struDllPath.LastIndexOf(L'.', 0);
if (dwPosition == -1)
{ {
hr = E_FAIL; hr = E_FAIL;
goto Finished; goto Finished;
} }
struDllPath.QueryStr()[dwPosition] = L'\0'; hr = UTILITY::ConvertPathToFullPath( L".\\hostfxr.dll", pcwzApplicationPhysicalPath, &struHostFxrPath );
if ( FAILED( hr ) )
{
goto Finished;
}
if (FAILED(hr = struDllPath.SyncWithBuffer()) || struDllPath.QueryStr()[dwPosition] = L'\0';
FAILED(hr = struDllPath.Append(L".dll"))) if (FAILED(hr = struDllPath.SyncWithBuffer()))
{
goto Finished;
}
if ( !UTILITY::CheckIfFileExists( struHostFxrPath.QueryStr() ) )
{
// Most likely a full framework app.
// Check that the runtime config file doesn't exist in the folder as another heuristic.
if (FAILED(hr = struRuntimeConfigLocation.Copy(struDllPath)) ||
FAILED(hr = struRuntimeConfigLocation.Append( L".runtimeconfig.json" )))
{
goto Finished;
}
if (!UTILITY::CheckIfFileExists(struRuntimeConfigLocation.QueryStr()))
{
hr = E_APPLICATION_ACTIVATION_EXEC_FAILURE;
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG,
pcwzApplicationPhysicalPath,
hr)))
{
UTILITY::LogEvent( hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP,
strEventMsg.QueryStr() );
}
}
else
{
// If a runtime config file does exist, report a file not found on the app.exe
hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
if (SUCCEEDED(strEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG,
pcwzApplicationPhysicalPath,
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND,
strEventMsg.QueryStr());
}
}
goto Finished;
}
if (FAILED(hr = struHostFxrDllLocation->Copy(struHostFxrPath)))
{
goto Finished;
}
if (FAILED(hr = struDllPath.Append(L".dll")))
{ {
goto Finished; goto Finished;
} }
@ -62,18 +124,28 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
if (!UTILITY::CheckIfFileExists(struDllPath.QueryStr())) if (!UTILITY::CheckIfFileExists(struDllPath.QueryStr()))
{ {
// Treat access issue as File not found // Treat access issue as File not found
hr = ERROR_FILE_NOT_FOUND; hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
goto Finished; goto Finished;
} }
if (FAILED(hr = struArguments.Copy(struDllPath)) || if (FAILED(hr = struArguments.Copy(struDllPath)) ||
FAILED(hr = struArguments.Append(L" ")) || FAILED(hr = struArguments.Append(L" ")) ||
FAILED(hr = struArguments.Append(pConfig->QueryArguments()))) FAILED(hr = struArguments.Append(pcwzArguments)))
{ {
goto Finished; goto Finished;
} }
if (FAILED(hr = SetHostFxrArguments(struArguments.QueryStr(), pwzExePath, pConfig))) if (FAILED(hr = ParseHostfxrArguments(
struArguments.QueryStr(),
pwzExeAbsolutePath,
pcwzApplicationPhysicalPath,
hEventLog,
pdwArgCount,
ppwzArgv)))
{
goto Finished;
}
if (FAILED(hr = struHostFxrDllLocation->Copy(struDllPath)))
{ {
goto Finished; goto Finished;
} }
@ -85,7 +157,13 @@ Finished:
HRESULT HRESULT
HOSTFXR_UTILITY::GetHostFxrParameters( HOSTFXR_UTILITY::GetHostFxrParameters(
ASPNETCORE_CONFIG *pConfig HANDLE hEventLog,
PCWSTR pcwzProcessPath,
PCWSTR pcwzApplicationPhysicalPath,
PCWSTR pcwzArguments,
_Inout_ STRU* struHostFxrDllLocation,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
) )
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
@ -94,13 +172,14 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
STRU struExeLocation; STRU struExeLocation;
STRU struHostFxrSearchExpression; STRU struHostFxrSearchExpression;
STRU struHighestDotnetVersion; STRU struHighestDotnetVersion;
STRU struEventMsg;
std::vector<std::wstring> vVersionFolders; std::vector<std::wstring> vVersionFolders;
DWORD dwPosition; DWORD dwPosition;
// Convert the process path an absolute path. // Convert the process path an absolute path.
hr = UTILITY::ConvertPathToFullPath( hr = UTILITY::ConvertPathToFullPath(
pConfig->QueryProcessPath()->QueryStr(), pcwzProcessPath,
pConfig->QueryApplicationPhysicalPath()->QueryStr(), pcwzApplicationPhysicalPath,
&struExeLocation &struExeLocation
); );
@ -113,30 +192,22 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
{ {
// Check if hostfxr is in this folder, if it is, we are a standalone application, // Check if hostfxr is in this folder, if it is, we are a standalone application,
// else we assume we received an absolute path to dotnet.exe // else we assume we received an absolute path to dotnet.exe
hr = UTILITY::ConvertPathToFullPath(L".\\hostfxr.dll", pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struHostFxrPath); hr = GetStandaloneHostfxrParameters(
if (FAILED(hr)) struExeLocation.QueryStr(),
{ pcwzApplicationPhysicalPath,
goto Finished; pcwzArguments,
} hEventLog,
struHostFxrDllLocation,
if (UTILITY::CheckIfFileExists(struHostFxrPath.QueryStr())) pdwArgCount,
{ ppwzArgv);
// Standalone application goto Finished;
if (FAILED(hr = pConfig->SetHostFxrFullPath(struHostFxrPath.QueryStr())))
{
goto Finished;
}
hr = GetStandaloneHostfxrParameters(struExeLocation.QueryStr(), pConfig);
goto Finished;
}
} }
else else
{ {
if (FAILED(hr = HOSTFXR_UTILITY::FindDotnetExePath(&struExeLocation))) { if (FAILED(hr = HOSTFXR_UTILITY::FindDotnetExePath(&struExeLocation)))
{
goto Finished; goto Finished;
} }
} }
if (FAILED(hr = struExeLocation.SyncWithBuffer()) || if (FAILED(hr = struExeLocation.SyncWithBuffer()) ||
@ -168,8 +239,17 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
if (!UTILITY::DirectoryExists(&struHostFxrPath)) if (!UTILITY::DirectoryExists(&struHostFxrPath))
{ {
// error, not found in folder
hr = ERROR_BAD_ENVIRONMENT; hr = ERROR_BAD_ENVIRONMENT;
if (SUCCEEDED(struEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -192,8 +272,17 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
if (vVersionFolders.size() == 0) if (vVersionFolders.size() == 0)
{ {
// no core framework was found hr = HRESULT_FROM_WIN32(ERROR_BAD_ENVIRONMENT);
hr = ERROR_BAD_ENVIRONMENT; if (SUCCEEDED(struEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
@ -212,16 +301,33 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
if (!UTILITY::CheckIfFileExists(struHostFxrPath.QueryStr())) if (!UTILITY::CheckIfFileExists(struHostFxrPath.QueryStr()))
{ {
hr = ERROR_FILE_INVALID; // ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG
hr = HRESULT_FROM_WIN32(ERROR_FILE_INVALID);
if (SUCCEEDED(struEventMsg.SafeSnwprintf(
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG,
struHostFxrPath.QueryStr(),
hr)))
{
UTILITY::LogEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND,
struEventMsg.QueryStr());
}
goto Finished; goto Finished;
} }
if (FAILED(hr = SetHostFxrArguments(pConfig->QueryArguments()->QueryStr(), struExeLocation.QueryStr(), pConfig))) if (FAILED(hr = ParseHostfxrArguments(
pcwzArguments,
struExeLocation.QueryStr(),
pcwzApplicationPhysicalPath,
hEventLog,
pdwArgCount,
ppwzArgv)))
{ {
goto Finished; goto Finished;
} }
if (FAILED(hr = pConfig->SetHostFxrFullPath(struHostFxrPath.QueryStr()))) if (FAILED(hr = struHostFxrDllLocation->Copy(struHostFxrPath)))
{ {
goto Finished; goto Finished;
} }
@ -240,15 +346,23 @@ Finished:
// argv[2] = absolute path to dll. // argv[2] = absolute path to dll.
// //
HRESULT HRESULT
HOSTFXR_UTILITY::SetHostFxrArguments( HOSTFXR_UTILITY::ParseHostfxrArguments(
PCWSTR pwzArgumentsFromConfig, PCWSTR pwzArgumentsFromConfig,
PCWSTR pwzExePath, PCWSTR pwzExePath,
ASPNETCORE_CONFIG* pConfig PCWSTR pcwzApplicationPhysicalPath,
HANDLE hEventLog,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
) )
{ {
UNREFERENCED_PARAMETER( hEventLog ); // TODO use event log to set errors.
DBG_ASSERT(dwArgCount != NULL);
DBG_ASSERT(pwzArgv != NULL);
HRESULT hr = S_OK; HRESULT hr = S_OK;
INT argc = 0; INT argc = 0;
PCWSTR* argv = NULL; PWSTR* argv = NULL;
LPWSTR* pwzArgs = NULL; LPWSTR* pwzArgs = NULL;
STRU struTempPath; STRU struTempPath;
DWORD dwArgsProcessed = 0; DWORD dwArgsProcessed = 0;
@ -268,7 +382,7 @@ HOSTFXR_UTILITY::SetHostFxrArguments(
goto Failure; goto Failure;
} }
argv = new PCWSTR[argc + 2]; argv = new PWSTR[argc + 2];
if (argv == NULL) if (argv == NULL)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;
@ -294,7 +408,7 @@ HOSTFXR_UTILITY::SetHostFxrArguments(
// Try to convert the application dll from a relative to an absolute path // Try to convert the application dll from a relative to an absolute path
// Don't record this failure as pwzArgs[0] may already be an absolute path to the dll. // Don't record this failure as pwzArgs[0] may already be an absolute path to the dll.
if (SUCCEEDED(UTILITY::ConvertPathToFullPath(pwzArgs[0], pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struTempPath))) if (SUCCEEDED(UTILITY::ConvertPathToFullPath(pwzArgs[0], pcwzApplicationPhysicalPath, &struTempPath)))
{ {
argv[2] = SysAllocString(struTempPath.QueryStr()); argv[2] = SysAllocString(struTempPath.QueryStr());
} }
@ -320,7 +434,9 @@ HOSTFXR_UTILITY::SetHostFxrArguments(
dwArgsProcessed++; dwArgsProcessed++;
} }
pConfig->SetHostFxrArguments(argc + 2, argv); *ppwzArgv = argv;
*pdwArgCount = dwArgsProcessed;
goto Finished; goto Finished;
Failure: Failure:

View File

@ -14,33 +14,47 @@ public:
HOSTFXR_UTILITY(); HOSTFXR_UTILITY();
~HOSTFXR_UTILITY(); ~HOSTFXR_UTILITY();
static static
HRESULT HRESULT
GetHostFxrParameters( GetHostFxrParameters(
ASPNETCORE_CONFIG *pConfig HANDLE hEventLog,
); PCWSTR pcwzProcessPath,
PCWSTR pcwzApplicationPhysicalPath,
PCWSTR pcwzArguments,
_Inout_ STRU* struHostFxrDllLocation,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
);
private: private:
static static
HRESULT HRESULT
GetStandaloneHostfxrParameters( GetStandaloneHostfxrParameters(
PCWSTR pStruExePath, PCWSTR pwzExeAbsolutePath, // includes .exe file extension.
ASPNETCORE_CONFIG *pConfig PCWSTR pcwzApplicationPhysicalPath,
PCWSTR pcwzArguments,
HANDLE hEventLog,
_Inout_ STRU* struHostFxrDllLocation,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
); );
static static
HRESULT HRESULT
SetHostFxrArguments( ParseHostfxrArguments(
PCWSTR struArguments, PCWSTR pwzArgumentsFromConfig,
PCWSTR pStruExePath, PCWSTR pwzExePath,
ASPNETCORE_CONFIG *pConfig PCWSTR pcwzApplicationPhysicalPath,
HANDLE hEventLog,
_Out_ DWORD* pdwArgCount,
_Out_ PWSTR** ppwzArgv
); );
static static
HRESULT HRESULT
FindDotnetExePath( FindDotnetExePath(
STRU * struDotnetLocation STRU* struDotnetLocation
); );
}; };

View File

@ -16,14 +16,20 @@
#define ASPNETCORE_EVENT_PROCESS_START_POSTCREATE_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s'but failed to get its status, ErrorCode = '0x%x', retryCounter '%d'." #define ASPNETCORE_EVENT_PROCESS_START_POSTCREATE_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s'but failed to get its status, ErrorCode = '0x%x', retryCounter '%d'."
#define ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG L"Application '%s' with physical root '%s' failed to start process with commandline '%s', ErrorCode = '0x%x', retryCounter '%d'." #define ASPNETCORE_EVENT_PROCESS_START_ERROR_MSG L"Application '%s' with physical root '%s' failed to start process with commandline '%s', ErrorCode = '0x%x', retryCounter '%d'."
#define ASPNETCORE_EVENT_PROCESS_START_WRONGPORT_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s' but failed to listen on the given port '%d'" #define ASPNETCORE_EVENT_PROCESS_START_WRONGPORT_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s' but failed to listen on the given port '%d'"
#define ASPNETCORE_EVENT_PROCESS_START_NOTREADY_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s' but either crashed or did not response or did not listen on the given port '%d', ErrorCode = '0x%x'" #define ASPNETCORE_EVENT_PROCESS_START_NOTREADY_ERROR_MSG L"Application '%s' with physical root '%s' created process with commandline '%s' but either crashed or did not respond or did not listen on the given port '%d', ErrorCode = '0x%x'"
#define ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG L"Warning: Could not create stdoutLogFile %s, ErrorCode = %d." #define ASPNETCORE_EVENT_INVALID_STDOUT_LOG_FILE_MSG L"Warning: Could not create stdoutLogFile %s, ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG L"Failed to gracefully shutdown process '%d'." #define ASPNETCORE_EVENT_GRACEFUL_SHUTDOWN_FAILURE_MSG L"Failed to gracefully shutdown process '%d'."
#define ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG L"Sent shutdown HTTP message to process '%d' and received http status '%d'." #define ASPNETCORE_EVENT_SENT_SHUTDOWN_HTTP_REQUEST_MSG L"Sent shutdown HTTP message to process '%d' and received http status '%d'."
#define ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG L"Application '%s' with physical root '%s' failed to load clr and managed application, ErrorCode = '0x%x." #define ASPNETCORE_EVENT_LOAD_CLR_FALIURE_MSG L"Application '%s' with physical root '%s' failed to load clr and managed application, ErrorCode = '0x%x."
#define ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG L"Only one inprocess application is allowed per IIS application pool. Please assign the application '%s' to a different IIS application pool." #define ASPNETCORE_EVENT_DUPLICATED_INPROCESS_APP_MSG L"Only one inprocess application is allowed per IIS application pool. Please assign the application '%s' to a different IIS application pool."
#define ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG L"Mixed hosting model is not supported. Application '%s' configured with different hostingModel value '%d' other than the one of running application(s)." #define ASPNETCORE_EVENT_MIXED_HOSTING_MODEL_ERROR_MSG L"Mixed hosting model is not supported. Application '%s' configured with different hostingModel value '%d' other than the one of running application(s)."
#define ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG L"Failed to start application '%s', ErrorCode '0x%x'." #define ASPNETCORE_EVENT_ADD_APPLICATION_ERROR_MSG L"Failed to start application '%s', ErrorCode '0x%x'."
#define ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG L"Application '%s' with physical root '%s' hit unexpected managed background thread exit, ErrorCode = '0x%x." #define ASPNETCORE_EVENT_INPROCESS_THREAD_EXIT_MSG L"Application '%s' with physical root '%s' hit unexpected managed background thread exit, ErrorCode = '0x%x. Please check the stderr logs for more information."
#define ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG L"Application '%s' is recycled due to app_offline file was detected." #define ASPNETCORE_EVENT_RECYCLE_APPOFFLINE_MSG L"Application '%s' is recycled due to app_offline file was detected."
#define ASPNETCORE_EVENT_MODULE_DISABLED_MSG L"AspNetCore Module is disabled" #define ASPNETCORE_EVENT_MODULE_DISABLED_MSG L"AspNetCore Module is disabled"
#define ASPNETCORE_EVENT_INPROCESS_FULL_FRAMEWORK_APP_MSG L"Application '%s' was compiled for .NET Framework. Please compile for .NET core to run the inprocess application or change the process mode to out of process. ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_PORTABLE_APP_DOTNET_MISSING_MSG L"Could not find dotnet.exe on the system PATH environment variable for portable application '%s'. Check that a valid path to dotnet is on the PATH and the bitness of dotnet matches the bitness of the IIS worker process. ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_HOSTFXR_DIRECTORY_NOT_FOUND_MSG L"Could not find the hostfxr directory '%s' in the dotnet directory. ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_HOSTFXR_DLL_NOT_FOUND_MSG L"Could not find hostfxr.dll in '%s'. ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_APPLICATION_EXE_NOT_FOUND_MSG L"Could not find application executable in '%s'. ErrorCode = '0x%x'."
#define ASPNETCORE_EVENT_INPROCESS_THREAD_EXCEPTION_MSG L"Application '%s' with physical root '%s' hit unexpected managed exception, ErrorCode = '0x%x. Please check the stderr logs for more information."

View File

@ -28,3 +28,5 @@
#include "requesthandler.h" #include "requesthandler.h"
#include "fx_ver.h" #include "fx_ver.h"
#include "hostfxr_utility.h" #include "hostfxr_utility.h"
#include "resources.h"
#include "aspnetcore_msg.h"