
Hello,
I have a C# project who's suppose to write customers and orders in a retail database, using the commerce runtime SDK.
The project is in 2 parts :
- One console application (for now, will be a windows Service later)
- One library application who is used by the console application above
The really important point is that 99% of the code is in the library, all the requires DLL must be in it, also than the connection with the commerce runtime.
To make it very simple, here's my console app code :
my_dll.Program.test();
And my library code :
namespace mydll
{
public class Program
{
private const string _connectionString = "[...]";
private const long _channelId = 5637146827;
public static void test()
{
var dllConfigPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "my_dll.config");
var configFileMap = new ExeConfigurationFileMap()
{
ExeConfigFilename = dllConfigPath
};
var appConfigFile = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
// configuration is successfully loaded at this point
var configSection = (CommerceRuntimeSection)appConfigFile.GetSection("commerceRuntime");
// an exception is throw here
var commerceRuntimeConfiguration = new CommerceRuntimeConfiguration(configSection, _connectionString, true);
var commercePrincipal = new CommercePrincipal(new CommerceIdentity(_channelId, Enumerable.Empty<string>()));
var runtime = CommerceRuntime.Create(commerceRuntimeConfiguration, commercePrincipal);
ChannelManager channelManager = ChannelManager.Create(runtime);
}
}
As you can see, the library contains an "my_dll.config" file who contains the following :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="commerceRuntime" type="Microsoft.Dynamics.Commerce.Runtime.Configuration.CommerceRuntimeSection, Microsoft.Dynamics.Commerce.Runtime.ConfigurationProviders, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</configSections>
<commerceRuntime>
<storage defaultOperatingUnitNumber=""/>
<query defaultPageSize="250" maxPageSize="5000"/>
<cache disableCaching="false" disableCacheUpdates="false" forceCacheLookupHostile="false" forceCacheLookupMiss="false" forceCacheLookupHit="false"/>
<composition>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Services.Desktop, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.TransactionService, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Workflow, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataServices.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.DataAccess.SqlServer, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
<add source="assembly" value="Microsoft.Dynamics.Commerce.Runtime.Cache.MemoryCache, Version=6.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
</composition>
</commerceRuntime>
</configuration>
All the DLLs listed in the file are properly includes in the library project.
Nevertheless, I have the exception "Unable to load the assemble or file "Microsoft.Dynamics.Commerce.Runtime.Services"
The only solution I have found, which is not acceptable from my point of view, is to :
- copy the .config on the console application
- add all the dlls in the console application references. But I still need it in the library application (without, the code in the library doesn't compile) : so basically, I have to references twice all the DLLs... no way I'm gonna to do this.
How can I make this application architecture works ?
Thanks in advance,
Charles
*This post is locked for comments
I have the same question (0)>- copy the .config on the console application
You don't actually have to copy the config, instead you just need to make sure that config exists in the host application, in your case it seems like the console is the host application which means that it should be available for that client app.
>- add all the dlls in the console application references. But I still need it in the library application (without, the code in the library doesn't compile) : so basically, I have to references twice all the DLLs... no way I'm gonna to do this.
Please note the difference between:
a) referencing DLLs at compile time
b) making sure DLLs are available at runtime
In your case it is enough to do (b), so you don't have to do (a). (a) worked for you just because the referenced dlls were automatically copied to the output folder for you but that is not ideal solution, instead you should just have (post) deployment step which will copy required dlls to the output folder, but, again, you don't have to reference the dlls if your application doesn't require then at compilation time.