DLL cannot find AppConfig file on remote location

2019-08-30 23:40发布

问题:

This question is derive from "Cannot initialize public static class when the DLL is placed in a remote server" As at first I wasn't able to get detail stack trace on Powershell, but later when I find out a way to do it, I realize the question may not be accurate and may be a new question.

I have a DLL in a network shared folder, and after I import it to PowerShell by using Import-Module, calling the DLL's methods shows this error:

The type initializer for Configuration.AppConfiguration threw an exception

TypeName : InsightDSL.DSLConfiguration.AppConfiguration

Message : The type initializer for 'InsightDSL.DSLConfiguration.AppConfiguration' threw an exception.

Data : {}

InnerException : System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: The parameter 'exePath' is invalid. Parameter name: exePath ---> System.ArgumentException: The parameter 'exePath' is invalid. Parameter name: exePath at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigurationHost.get_ConfigPaths() at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath) at System.Configuration.BaseConfigurationRecord.InitConfigFromFile() --- End of inner exception stack trace --- at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams) at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath) at InsightDSL.DSLConfiguration.AppConfiguration..cctor()

TargetSite : Int32 get_TimeoutValue()

StackTrace : at InsightDSL.DSLConfiguration.AppConfiguration.get_TimeoutValue() at InsightDSL.SetInsightConnection.SetEnvironment() at InsightDSL.SetInsightConnection.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord()

The exception is thrown for the class:

namespace Configuration
public static class AppConfiguration
{
    private static Configuration Configuration = ConfigurationManager.OpenExeConfiguration(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath);
    public static string name {...}
    public static int timeout {...}
}

If I copy the DLL to my local folder, the error will not happen and everything works correctly, however on that remote location, it just doesn't work.

标签: c# dll