Reputation: 11
Is it possible to load the Assembly Version in a pure XAML code? I've found this here:
But it always Returns 4.0.0
<TextBlock xmlns:ref="clr-namespace:System.Reflection;assembly=mscorlib">
<TextBlock.Text>
<Binding Path="Version">
<Binding.Source>
<ObjectDataProvider MethodName="GetName">
<ObjectDataProvider.ObjectInstance>
<ObjectDataProvider MethodName="GetExecutingAssembly"
ObjectType="{x:Type ref:Assembly}" />
</ObjectDataProvider.ObjectInstance>
</ObjectDataProvider>
</Binding.Source>
</Binding>
</TextBlock.Text>
</TextBlock>
Then i tried this here: (which works perfect if the App runs)
<TextBlock Grid.Row ="0" Grid.Column="0" xmlns:ref="clr-namespace:System.Reflection;assembly=mscorlib" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<TextBlock.Text>
<Binding Path="Version">
<Binding.Source>
<ObjectDataProvider MethodName="GetName">
<ObjectDataProvider.ObjectInstance>
<ObjectDataProvider MethodName="ReflectionOnlyLoadFrom"
ObjectType="{x:Type ref:Assembly}">
<ObjectDataProvider.MethodParameters>
<sys:String>.\Modules\Myassembly.dll</sys:String>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</ObjectDataProvider.ObjectInstance>
</ObjectDataProvider>
</Binding.Source>
</Binding>
</TextBlock.Text>
</TextBlock>
But now the Designer says (wants to find the Assembly in System32)
Could not load file or assembly 'file:///C:\Windows\system32\Modules\MyAssembly.dll' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
Upvotes: 0
Views: 1400
Reputation: 41
Try using GetEntryAssembly instead of GetExecutingAssembly with the first example. For me this shows up as 14.0.0.0 in the designer, but is correct when the application runs.
<ObjectDataProvider MethodName="GetName">
<ObjectDataProvider.ObjectInstance>
<ObjectDataProvider MethodName="GetEntryAssembly" ObjectType="{x:Type ref:Assembly}" />
</ObjectDataProvider.ObjectInstance>
</ObjectDataProvider>
Upvotes: 4