Thread: Configuration Issue in C#


Permlink Replies: 9 - Pages: 1 - Last Post: Aug 30, 2007 3:12 PM Last Post By: Guest
Guest
Configuration Issue in C#
Posted: Aug 22, 2007 6:42 AM
Click to report abuse...   Click to reply to this thread Reply
Hi,

When I try to connect to Tangosol via C# windows application(exe), its working fine.
But when I try to connect to Tangosol via C# Class Library(dll), I am not able to connect to Tangosol it is giving the following error message

Message:

Failed to load configuration file: coherence-cache-config.xml

StackTrace:

at Tangosol.Net.DefaultConfigurableCacheFactory.LoadConfig(String path) in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\DefaultConfigurableCacheFactory.cs:line 1096
at Tangosol.Net.DefaultConfigurableCacheFactory..ctor(XmlNode xmlConfig) in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\DefaultConfigurableCacheFactory.cs:line 183
at Tangosol.Net.DefaultConfigurableCacheFactory..ctor() in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\DefaultConfigurableCacheFactory.cs:line 154
at Tangosol.Net.CacheFactory.get_ConfigurableCacheFactory() in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\CacheFactory.cs:line 152
at Tangosol.Net.CacheFactory.GetCache(String name) in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\CacheFactory.cs:line 428
at ClassLibrary1.Class1.testTangosol() in C:\Satish\Satish\1.1\ClassLibrary1\Class1.cs:line 13

InnerException Message:

Could not find file 'C:\Satish\Satish\1.1\WindowsApplication1\bin\Debug\coherence-cache-config.xml'.

InnerException StackTrace:

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Tangosol.IO.Resources.FileResource.get_InputStream() in c:\dev\release.net\coherence-net-v3.3\src\Coherence\IO\Resources\FileResource.cs:line 108
at Tangosol.Util.XmlUtils.LoadXml(String path) in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Util\XmlUtils.cs:line 799
at Tangosol.Net.DefaultConfigurableCacheFactory.LoadConfig(String path) in c:\dev\release.net\coherence-net-v3.3\src\Coherence\Net\DefaultConfigurableCacheFactory.cs:line 1092

and also find the attached config files and attached class files which implements IPortable object for your reference.
I am using .Net framework 2.0 and VS 2005

Message was edited by: badisat

Attachment:
App.config
(*To use this attachment you will need to rename 608.bin to App.config after the download is complete.)

Attachment:
cache-config.xml
(*To use this attachment you will need to rename 609.bin to cache-config.xml after the download is complete.)

Attachment:
coherence.xml
(*To use this attachment you will need to rename 610.bin to coherence.xml after the download is complete.)

Attachment:
pof-config.xml
(*To use this attachment you will need to rename 611.bin to pof-config.xml after the download is complete.)

Attachment:
MaxVersionFilter.zip
(*To use this attachment you will need to rename 613.bin to MaxVersionFilter.zip after the download is complete.)

Guest
Re: Configuration Issue in C#
Posted: Aug 22, 2007 12:00 PM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Satish,

.NET configuration subsystem always uses a single configuration file per AppDomain, and it is very much .exe centric.

What this means is that even though you created separate config file for your library assembly, it will never be picked up -- .NET config subsystem will always look at your .exe configuration file for settings.

What you should do is simply put all your configuration options, including Coherence configuration, into your main application's App.config and remove library configuration file from your solution, as it will never be used.

If you really need to have separate configuration file for the library and want to specify Coherence configuration options there (and there are very few reasons why you would want to do that), you will need to load your class library into a separate AppDomain and specify the config file to use. Take a look at MSDN documentation for AppDomainSetup.ConfigurationFile property for an example on how to do that, but again, that's probably not what you want to do.

Regards,

Aleks
Guest
Re: Configuration Issue in C#
Posted: Aug 23, 2007 2:51 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Aleks,

I am using only one configuration file(App.config), When I build the application, in debug folder the app.config file is getting created as "FrontOffice3DGDLL.dll.config".
What I tried is as per your suggestion I have created new appdomain and I set the ConfigurationFile to the FrontOffice3DGDLL.dll.config, but still no use.
See the below sample code which I am tried

public object testTangosol()
{
try
{

string dllLoaction = GetType().Assembly.Location;
string dllFolder = dllLoaction.Substring(0, dllLoaction.LastIndexOf(@"\"));

AppDomainSetup domainInfo = new AppDomainSetup();
domainInfo.ApplicationBase = dllFolder;
domainInfo.ConfigurationFile = "FrontOffice3DGDLL.dll.config";
System.Windows.Forms.MessageBox.Show(domainInfo.ConfigurationFile.ToString());
System.AppDomain newDomain = AppDomain.CreateDomain("FrontOffice3DGDLL", null, domainInfo);

Tangosol.Net.INamedCache cache = Tangosol.Net.CacheFactory.GetCache("TRADECAPTURE");
System.Windows.Forms.MessageBox.Show(cache.Count.ToString());
return 0;
}
catch (Exception ex)
{
return "Error: " + ex.Message;// +"\n InnerException: " + ex.InnerException.Message;
}
}

Please find the attached config file for your reference.

Attachment:
FrontOffice3DGDLL.dll.config
(*To use this attachment you will need to rename 614.bin to FrontOffice3DGDLL.dll.config after the download is complete.)

Guest
Re: Configuration Issue in C#
Posted: Aug 23, 2007 3:25 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Satish,

Is there any particular reason why you are trying to configure Coherence client using library configuration file?

From the stacktrace you submitted earlier, it looks like you are using a standard Windows application (.exe) to load your library. Why don't you just simply create a config file for the application instead?

As I said earlier, configuring new app domain and loading your library in it just so you can use library config file is rarely a good solution. It would significantly complicate how you work with the types within that library from the default app domain. Basically, in order to access any type from the library in a child app domain you would have to use .NET Remoting to marshal things between the two app domains. Is there a good reason you want to do that?

In the last example you submitted, you create a new app domain and specify config file for it, but you do not load your library into it. The call to CacheFactory.GetCache still executes within the default app domain, which means that it will still look for .exe config file and completely ignore empty app domain you just created and the config file you specified. In order for your library configuration to kick in you would have to load the library into it and execute the call to CacheFactory.GetCache within new app domain.

Regards,

Aleks
Guest
Re: Configuration Issue in C#
Posted: Aug 23, 2007 4:37 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Aleks,

Basically our application is Excel addin(COM Addin).
Initially I tried with sample windows application to make sure that I am able to connect tangosol server from C# sucessfully. Once I done that. I started implementing in my original applcation, Thats where I am getting "Failed to load configuration file: coherence-cache-config.xml".
I tried to send the whole project but forum is not allowing me to attach more than 1MB size.
I am totally confused with this.

Regards,
Satish.
Guest
Re: Configuration Issue in C#
Posted: Aug 23, 2007 9:31 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi,

I have modified my test function with appdomain, and I am calling the function inside the the new appdomain. In the new appdomain i have specified the ConfigurationFile path, eventhough it is looking into the different path, I dont understand why. I am getting the error message as

Exception Message:

"Failed to load configuration file: Config
coherence.xml"

StackTrace
" at Tangosol.Net.CacheFactory.LoadConfiguration() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 262\r\n at Tangosol.Net.CacheFactory.get_Config() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 80\r\n at Tangosol.Net.CacheFactory.get_ConfigurableCacheFactoryConfig() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 187\r\n at Tangosol.Net.CacheFactory.get_ConfigurableCacheFactory() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 128\r\n at Tangosol.Net.CacheFactory.GetCache(String name) in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 428\r\n at FrontOffice3DGDLL.TestClass.Initilise() in C:\\Satish\\Projects\\CVSCode\\FO3DG_Addin
TestClass.cs:line 21"

InnerException:

"file cannot be resolved to local file path - resource does not use 'file:' protocol."

InnerException StackTrace:

" at Tangosol.IO.Resources.FileResource.get_InputStream() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\IO\\Resources
FileResource.cs:line 115\r\n at Tangosol.Util.XmlUtils.LoadXml(String path) in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Util
XmlUtils.cs:line 799\r\n at Tangosol.Net.CacheFactory.LoadConfiguration() in c:\\dev\\release.net\\coherence-net-v3.3\\src\\Coherence\\Net
CacheFactory.cs:line 258"

Please find the below code for your referecne:

public object testTangosol()
{
try
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
{
string requestedName = args.Name;
foreach (Assembly loadedAssembly in AppDomain.CurrentDomain.GetAssemblies())
{
string foundName = loadedAssembly.FullName;
if (requestedName.Equals(foundName))
{
return loadedAssembly;
}
}
return null;
});

string dllLoaction = GetType().Assembly.Location;
string dllFolder = dllLoaction.Substring(0, dllLoaction.LastIndexOf(@"\"));

AppDomainSetup domainInfo = new AppDomainSetup();
domainInfo.ApplicationBase = dllFolder;
domainInfo.ConfigurationFile = "FrontOffice3DGDLL.dll.config";
AppDomain newDomain = AppDomain.CreateDomain("FrontOffice3DGDLL", null, domainInfo);

object objTemp = newDomain.InitializeLifetimeService();
TestClass tangosol = (TestClass)newDomain.CreateInstanceAndUnwrap(Path.GetFileNameWithoutExtension(GetType().Assembly.Location), typeof(TestClass).FullName);
tangosol.Initilise();

return 0;
}
catch (Exception ex)
{
return "Error: " + ex.Message;
}
}


and the TestClass is

class TestClass : MarshalByRefObject
{
public void Initilise()
{
try
{
Tangosol.Net.INamedCache cache = Tangosol.Net.CacheFactory.GetCache("TRADECAPTURE");
System.Windows.Forms.MessageBox.Show(cache.Count.ToString());
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
}
}
}

Guest
Re: Configuration Issue in C#
Posted: Aug 23, 2007 10:06 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Ok, now I have a better understanding of what you are trying to do.

What you really need is a way to specify Coherence client configuration files programmatically, so you can completely avoid having to deal with the .NET configuration files. Unfortunately, while this is one of the outstanding issues, the fix for it won't be in the upcoming 3.3.1 release.

Based on your last message it looks like you were able to load .NET configuration file using separate app domain, so now we have to resolve the issue of not being able to find the Coherence configuration files specified in it.

Your .NET config file uses relative paths such as Config\xyz.xml to specify Coherence config file locations, but considering the fact that the code executes within Excel, I'm not sure what base path it will reolve them against. It could be Excel installation directory, or it could be the directory spreadsheet you open is in. It could possibly be different things based on whether you opened an existing or created a new file, so it's really hard to specify configuration files using relative paths. Absolute paths would work, but then you would have to make sure that path is the same for each user, possibly by placing configuration files in a shared network folder.

Probably better solution is to embed configuration files into your add-in assembly (mark them as embedded resources in VS.NET), and specify assembly resource names in the library config file.

For example, assuming that you assembly is called FrontOffice3DGDLL, and that you embed coherence.xml, cache-config.xml and pof-config.xml as resources within FrontOffice3DGDLL.Config namespace, you could modify your library configuration file like this:

<configuration>
  <configSections>
    <section name="tangosol-coherence" type="Tangosol.Config.CoherenceConfigHandler, Coherence"/>
  </configSections>
  <tangosol-coherence>
    <cache-factory-config>
      assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/coherence.xml
    </cache-factory-config>
    <cache-config>
      assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/cache-config.xml
    </cache-config>
    <pof-config>
      assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/pof-config.xml
    </pof-config>	
  </tangosol-coherence>
</configuration>


If you are not sure about the syntax, first part of the name is the name of the assembly, second the namespace the resource is in, and third the name of the resource itself.

That way you won't have to worry about the working directory or network shares, as configuration files will be embedded within the add-in you distribute to client machines.

However, I still don't like the fact that you have to deal with separate app domains in order to do this. If you can email me your whole solution directly I will take a look at it and try to find the way to avoid this.

Regards,

Aleks

Message was edited by: aseovic
Guest
Re: Configuration Issue in C#
Posted: Aug 29, 2007 9:46 AM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Aleks,

I have modified the app.config file as per your advice, eventhough it is not working I am getting the error message as

Failed to load configuration file: coherence-cache-config.xml
In my scenario, the assembly name is FrontOffice3DGDLL and Namespace is also FrontOffice3DGDLL
Please find the attached config file. I sent you the source code after that I didn't recieve any information from your side.

Attachment:
App.config
(*To use this attachment you will need to rename 617.bin to App.config after the download is complete.)
Guest
Re: Configuration Issue in C#
Posted: Aug 30, 2007 1:12 PM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi Satish,

I looked deeper into your issue and I believe I have a possible workaround that will allow you to access Coherence caches from your dll without having to use .NET config file.

1. You should modify cache-config.xml to explicitly include serializer element for your remote scheme name:

    <remote-cache-scheme>
      <scheme-name>TRADECAPTURE-NEAR</scheme-name>
      <service-name>ExtendTcpCacheService</service-name>
      <initiator-config>
        <tcp-initiator>
          <remote-addresses>
            <socket-address>
              <address>10.140.113.104</address>
              <port>8899</port>
            </socket-address>
          </remote-addresses>
        </tcp-initiator>
        <outgoing-message-handler>
          <request-timeout>30s</request-timeout>
        </outgoing-message-handler>
        <serializer>
          <class-name>Tangosol.IO.Pof.ConfigurablePofContext, Coherence</class-name>
          <init-params>
            <init-param>
              <param-type>string</param-type>
              <param-value>assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/pof-config.xml</param-value>
            </init-param>
          </init-params>
        </serializer>
      </initiator-config>
    </remote-cache-scheme>


2. Instead of using CacheFactory static class, create an instance of DefaultConfigurableCacheFactory and call EnsureCache method on it:

    string cacheConfig = "assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/cache-config.xml";
    IConfigurableCacheFactory cacheFactory = new DefaultConfigurableCacheFactory(cacheConfig);
    INamedCache cache = cacheFactory.EnsureCache("TRADECAPTURE");
    System.Windows.Forms.MessageBox.Show(cache.Count.ToString());


3. Make sure that all three files within Config directory of your dll are embedded resources (set their Build Action in the Properties pane to "Embedded Resource". This was not done in the sample solution you sent me.

4. Notice that the namespace name for the embedded resources in C# project is the combination of the default namespace and the path resource file is in. In your case, this means that the namespace will actually be FrontOffice3DGDLL.Config, which is reflected in both code snippets above.

Finally, there is an important limitation to this workaround -- you will not be able to specify main coherence.xml this way, which means that you won't be able to change logger, etc. However, I hope that this will allow you to connect to your caches and access data from your add-in until we fully implement programmatic configuration in Coherence for .NET.

Regards,

Aleks
Guest
Re: Configuration Issue in C#
Posted: Aug 30, 2007 3:06 PM   in response to: Guest in response to: Guest
Click to report abuse...   Click to reply to this thread Reply
Hi again Satish,

You might actually want to change the code in item 2 to following:

string cacheConfig = "assembly://FrontOffice3DGDLL/FrontOffice3DGDLL.Config/cache-config.xml";
    IConfigurableCacheFactory cacheFactory = new DefaultConfigurableCacheFactory(cacheConfig);
    CacheFactory.ConfigurableCacheFactory = cacheFactory;
    INamedCache cache = CacheFactory.GetCache("TRADECAPTURE");
    System.Windows.Forms.MessageBox.Show(cache.Count.ToString());


This will properly set up the local member, edition, etc. on the supplied IConfigurableCacheFactory.

- Aleks
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums