473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Some Problem With Dynamic Loading and Custom Config Section

Hi! It's my first discussion on this forum.
First I have a exe like this below (the object can invoke by console)
public class DynamicLoad
{
public Type AssemblyType = null;
public Assembly TestAssembly1 = null;
public DynamicLoad ()
{
string load_path = "..\OuterAssembly1\OuterAssembly1.dll";
TestAssembly1 = Assembly.LoadFrom(load_path);
AssemblyType = TestAssembly1.GetType
("OuterAssembly1.ThisAssembly");
}
public void InvokeOuterAssembly()
{
OuterAdapter target=(OuterAdapter)
AssemblyType.Assembly.CreateInstance(AssemblyType. FullName);
string response = target.GetConfigValue();
}
}

As you can see it has a "OuterAdapter" (in a seperate dll that referece by exe and "OuterAssembly1.dll" ) that is a base class and a bridge between exe and "OuterAssembly1.ThisAssembly"
"OuterAssembly1.ThisAssembly" is below:

public class ThisAssembly : OuterAdapter
{
private CustomSection ConfigObject;
public override string GetConfigValue()
{
string response = "";
try
{
string AssemblyPath = this.GetType().Assembly.Location;
Configuration ThisConfig =
(ConfigurationManager.OpenExeConfiguration(Assembl yPath));
ConfigObject = new CustomSection();
ConfigObject=(CustomSection)(ThisConfig.GetSection
("TestSection"));
response += ConfigObject.Settings["testkey"].Value + "\r\n";
}
catch (Exception ex)
{
response += ex.ToString() + "\r\n";
}
return response;
}
}
The "ThisAssembly" is under the namespace "OuterAssembly1" that is also assembly name. So I have a dll.config :
<configuration>
<configSections>
<section name="TestSection"
type="OuterAssembly1.CustomSection,OuterAssembly1"/>
</configSections>
<TestSection>
<add key="testkey" value="This is AssemblyOne"/>
</TestSection>
</configuration>
Of cource I have a "OuterAssembly1.CustomSection" as a config read handler
to get "testkey".
But Before i can read the dll.config, I got the Exception from ~~~~~
~~~ ConfigObject=(CustomSection)(ThisConfig.GetSection ("TestSection"));
and it's not exception from my read handler which i test else where ok, however
it seems Configuration object can resolve the "OuterAssembly1" to get my handler for configsection.
The Exception is :

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for TestSection: Could not load file or assembly 'OuterAssembly1' or one of its dependencies. The system cannot find the file specified. (D:\TestAssemblyLoading\AssemblyLoadingTest\OuterA ssembly1\OuterAssembly1.dll.config line 4) ---> System.IO.FileNotFoundException: Could not load file or assembly 'OuterAssembly1' or one of its dependencies. The system cannot find the file specified.
File name: 'OuterAssembly1'
at System.Configuration.TypeUtil.GetTypeWithReflectio nPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)
at System.Configuration.MgmtConfigurationRecord.Creat eSectionFactory(FactoryRecord factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindA ndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

--- End of inner exception stack trace ---
at System.Configuration.BaseConfigurationRecord.FindA ndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSe ctionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSe ction(String configKey, Boolean getLkg, Boolean checkPermission)
at System.Configuration.Configuration.GetSection(Stri ng sectionName)
at OuterAssembly1.ThisAssembly.GetConfigValue() in D:\TestAssemblyLoading\AssemblyLoadingTest\OuterAs sembly1\ThisAssembly.cs:line 36


OuterAssembly1 doesn't have any other reference dll except OuterAdapter

As you can see I am imitating a Web ApplicationServer which can load extention dynamiclly and use their own config at runtime then the server.exe that can complete this mission only need to know the assembly path and a name of class which implement an adapter that predefined and know by exe , both extention.
Does any one know that somthing interfere with my ought?
By the way the OuterAssembly1 and its dll.config is outside the exe directory.
And even I add OuterAdapter to GAC it still doesn't work.
Thanks!
Jun 15 '07 #1
0 1569

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Celebrate | last post by:
My application works fine when I run it locally but when I transfer it to our NEW Windows 2003 Web Edition server, I get a strange error. I've isolated the problem to when I issue a...
3
by: gaugust | last post by:
I am running Visual Studio .Net 2003 with Windows XP Pro and SP2. I am tying to run an ASP .Net application in debug mode. In Web.Config file I have set debug="true" but I am getting an error:...
3
by: rdcpro | last post by:
Hi all, I've been building a nifty deserializing configuration handler that I use in conjunction with my web.config in an ASP.NET web app. This is working quite well, but I'm planning on...
6
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection"...
2
by: Luke Dalessandro | last post by:
I have an application with the following layout /root/ /root/Default.aspx /root/web.config /root/child/ /root/child/web.config web.config has a custom configuration section "testSection"...
3
by: Sami Marzouki | last post by:
Hi, What I'm trying to do is: - To write a Web.config with custom sections. (Done) - To write a xsd schema for this custom sections.(Done) - Tell the Web.config to take the two schemas. When...
10
by: David Thole | last post by:
Hey all, I'm still very new at all this, but am going through the ASP.net 2.0 unleashed book, first chapter and trying to program my own little form emailer for fun. I tried following the code...
5
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler...
0
by: Paul Buckley | last post by:
Hi, I'm trying to gain access to a configuration section from within an assembly that has been loaded using Assemly.Load(byte). There is one main exe (lets say myApp.exe) and one config file...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.