Announcements
Greetings!
When I'm trying to use Microsoft.Dynamics.Ax.Xpp.MetadataSupport class in my c# application I get an error:
System.BadImageFormatException was unhandled
FileName=aoskernel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
FusionLog==== Pre-bind state information ===
LOG: DisplayName = aoskernel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/SrvAxUtility/srvAx7SDK/srvAx7SDK.MDprocessingConsoleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.Dynamics.AX.Xpp.Support, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.MDprocessingConsoleApp\bin\Debug\srvAx7SDK.ConsoleApp.vshost.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: aoskernel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/SrvAxUtility/srvAx7SDK/srvAx7SDK.MDprocessingConsoleApp/bin/Debug/aoskernel.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
HResult=-2147024885
Message=Could not load file or assembly 'aoskernel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source=Microsoft.Dynamics.AX.Xpp.Support
StackTrace:
at Microsoft.Dynamics.Ax.Xpp.MetadataSupport.GetTableExtensionNames(String tableName)
at srvAx7SDK.D365MDProvider.AxMDMapperForDataEntity.ReadEntityExtensionFields() in C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.D365MDProvider\AxMDMapperForDataEntity.cs:line 51
at srvAx7SDK.D365MDProvider.AxMDMapperForDataEntity.DoMap() in C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.D365MDProvider\AxMDMapperForDataEntity.cs:line 39
at srvAx7SDK.D365MDProvider.AxMDService.GetDataEntityByName(String _entityName) in C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.D365MDProvider\AxMDService.cs:line 26
at srvAx7SDK.ConsoleInfrastructure.SrvEntityFieldsDescriptionOperation.PerformOperation() in C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.MDProcessingInfrastructure\SrvEntityFieldsDescriptionOperation.cs:line 33
at srvAx7SDK.ConsoleApp.Program.Main(String[] args) in C:\SrvAxUtility\srvAx7SDK\srvAx7SDK.MDprocessingConsoleApp\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I wanted to use that example but via c# AX7. Get information about table extension using Microsoft.Dynamics.Ax.Xpp.MetadataSupport
It is possible?
Oh my gosh) Of course I am using simple provider
var environment = Microsoft.Dynamics.ApplicationPlatform.Environment.EnvironmentFactory.GetApplicationEnvironment();
string MDAlternatePath = environment.Aos.PackageDirectory;
var runtimeProviderConfiguration = new AxMetadataStorage.Runtime.RuntimeProviderConfiguration(MDAlternatePath);
var metadataProviderFactory = new AxMetadataStorage.MetadataProviderFactory();
provider = metadataProviderFactory.CreateRuntimeProvider(runtimeProviderConfiguration);
Thanks a lot Martin. You saved my brain :)
I can't confirm your findings - I do see extensions combined with original objects (e.g. table fields from extensions included in AxTable.Fields). Are you sure you use CreateRuntimeProviderWithExtensions()?
Of course MetadataSupport class works perfectly from X++ - it's been designed for that.
Yeah, Martin you are definitely right. I know the using of MetadataSupport class leads to load a lots of referenced libraries. I have already used the way you are suggesting. It works fine except one thing. For example I want to read a EDT metadata with all applied extensions. In this case facade such as MetadataSupport is perfect. Metadata provider reads an artifacts (and its own properties) and an artifacts extensions separately. I other words, what I want to achieve, I want to pass artifact name and receive metadata information with all applied extensions.
P.S. Interesting thing... From x++ the MetadataSupport class features work perfectly.
I don't think I've ever used MetadataSupport class as such from C#, but I definitely did use the metadata API. MetadataSupport is just a simplified façade for the underlaying API anyway.
I suggest you avoid MetadataSupport class and the whole Microsoft.Dynamics,AX.Xpp.Support assembly with all its references you don't need (e.g. aoskernel) and use the metadata libraries directly.
For example, you can write code like this:
using Microsoft.Dynamics.AX.Metadata.MetaModel; using Microsoft.Dynamics.AX.Metadata.Providers; using Microsoft.Dynamics.AX.Metadata.Storage; using Microsoft.Dynamics.AX.Metadata.Storage.Runtime; string packagesDir = @"K:\AosService\PackagesLocalDirectory"; var runtimeConfiguration = new RuntimeProviderConfiguration(packagesDir ); var metadataProvider = new MetadataProviderFactory().CreateRuntimeProviderWithExtensions(runtimeConfiguration); AxForm form = metadataProvider.Forms.Read("CustTable");
According to my notes, you'll need references to Microsoft.Dynamics.AX.Metadata, Microsoft.Dynamics.AX.Metadata.Core and Microsoft.Dynamics.AX.Metadata.Storage.
It's interesting... Didn't anybody try to use MetadataSupport features from C# application?) I am back to this question once in a while. I realized this issue about difference in used target platform. When I change settings of my c# application to x64 target platform the exception doesn't throw but it still doesn't work. My app just doesn't response when I'm trying to call one of methods from MetadataSupport class. Looks like something is going wrong inside the dll.
André Arnaud de Cal...
293,998
Super User 2025 Season 1
Martin Dráb
232,850
Most Valuable Professional
nmaenpaa
101,158
Moderator