Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private ClientConfigPaths(string exePath, bool includeUserConfig)
_includesUserConfig = includeUserConfig;

Assembly exeAssembly = null;
bool isSingleFile = false;

if (exePath != null)
{
Expand All @@ -48,7 +49,14 @@ private ClientConfigPaths(string exePath, bool includeUserConfig)
// Exe path wasn't specified, get it from the entry assembly
exeAssembly = Assembly.GetEntryAssembly();

if (exeAssembly != null)
// in case of SingleFile deployment, Assembly.Location is empty.
if (exeAssembly?.Location.Length == 0)
{
isSingleFile = true;
Comment thread
am11 marked this conversation as resolved.
HasEntryAssembly = true;
Comment thread
jkotas marked this conversation as resolved.
Outdated
}

if (exeAssembly != null && !isSingleFile)
{
HasEntryAssembly = true;
Comment thread
am11 marked this conversation as resolved.
Outdated

Expand Down Expand Up @@ -83,7 +91,16 @@ private ClientConfigPaths(string exePath, bool includeUserConfig)

if (!string.IsNullOrEmpty(ApplicationUri))
{
ApplicationConfigUri = ApplicationUri + ConfigExtension;
string applicationPath = ApplicationUri;
if (isSingleFile)
{
// on Unix, we want to first append '.dll' extension and on Windows change '.exe' to '.dll'
// eventually, in ApplicationConfigUri we will get '{applicationName}.dll.config'
applicationPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
Path.ChangeExtension(ApplicationUri, ".dll") : ApplicationUri + ".dll";
}

ApplicationConfigUri = applicationPath + ConfigExtension;
}

// In the case when exePath was explicitly supplied, we will not be able to
Expand All @@ -109,7 +126,7 @@ private ClientConfigPaths(string exePath, bool includeUserConfig)
string applicationUriLower = !string.IsNullOrEmpty(ApplicationUri)
? ApplicationUri.ToLowerInvariant()
: null;
string hashSuffix = GetTypeAndHashSuffix(applicationUriLower);
string hashSuffix = GetTypeAndHashSuffix(applicationUriLower, isSingleFile);
string part2 = !string.IsNullOrEmpty(namePrefix) && !string.IsNullOrEmpty(hashSuffix)
? namePrefix + hashSuffix
: null;
Expand Down Expand Up @@ -202,15 +219,15 @@ private static string CombineIfValid(string path1, string path2)
// The evidence we use, in priority order, is Strong Name, Url and Exe Path. If one of
// these is found, we compute a SHA1 hash of it and return a suffix based on that.
// If none is found, we return null.
private static string GetTypeAndHashSuffix(string exePath)
private static string GetTypeAndHashSuffix(string exePath, bool isSingleFile)
{
Assembly assembly = Assembly.GetEntryAssembly();

string suffix = null;
string typeName = null;
string hash = null;

if (assembly != null)
if (assembly != null && !isSingleFile)
{
AssemblyName assemblyName = assembly.GetName();
Uri codeBase = new Uri(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assembly.ManifestModule.Name));
Expand Down