Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Friday, 7 June 2013

SGEN: Mixed mode assembly is built against version 'v2.0.50727'…

I found while building an VB application in Visual Studio 2012, in release mode for the first time, that I was confronted with cryptic build error;
SGEN: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After trawling through some Google results, I found the following post by Microsoft;

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

And also a couple of forums;

http://stackoverflow.com/questions/3749368/team-build-sgen-mixed-mode-assembly
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

Which suggests adding (or creating if it it doesn’t exist already) the following XML to the sgen.exe.config file;
<?xml version ="1.0"?>

<configuration>

    <startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>   

</configuration>
For .Net 4.0 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools  (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools (for x64 systems)
For .Net 4.5 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x64 systems)
Edit - 03-06-14:

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x64 systems)
Once I’d added the xml, the application built just fine.

The other alternative was to disable the option to Generate Serialization Assemblies in the offending project;

  • Project Settings for the offending Project
  • Compile Tab
  • Advance Compile Options Button
  • Set “Generate Serialization Assemblies” from “Auto” to “Off”

However, I recommend that you go with the XML option as suggested by Microsoft.

Thursday, 24 January 2013

WPF MVVM ComboBox Binding to XML Data.

Once again, while browsing StackOverflow.com, I came across a question from a user who needed to fix their ComboBox Binding. The user in question was Binding XML data in Key/Value pairs to the combo box, displaying the Key and wanted to retrieve the Value.

This was achieved using the following example;

My XML Test Data was saved as XMLFile1.xml;

<?xml version="1.0" encoding="utf-8"?>
<Colours>
  <Colour ID="1" Name="None" />
  <Colour ID="2" Name="Red" />
  <Colour ID="3" Name="White" />
</Colours>


My XAML was;






<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="74" Width="150">
    <Window.Resources>
        <XmlDataProvider x:Key="ColourData" Source="/XMLFile1.xml" XPath="Colours" />
    </Window.Resources>
    <Grid>
        <ComboBox x:Name="cmbColour" HorizontalAlignment="Left" Margin="10,10,0,0" 
                  VerticalAlignment="Top" Width="120" DisplayMemberPath="@ID" 
                  ItemsSource="{Binding Source={StaticResource ColourData}, XPath=./Colour}" 
                  SelectedValuePath="@Name"
                  SelectedValue="{Binding SelectedColourValue}"
                  />
    </Grid>
</Window>


And finally my ViewModel was;






Imports System.ComponentModel
Imports System.Xml
 
Class MainWindow : Implements INotifyPropertyChanged
 
    Private _SelectedColourValue As String
    Public Property SelectedColourValue As String
        Get
            Return _SelectedColourValue
 
        End Get
        Set(value As String)
 
            If value.Equals(_SelectedColourValue) = False Then
 
                _SelectedColourValue = value
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("SelectedColourValue"))
 
            End If
 
        End Set

End Property


    Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
 
    Public Sub New()
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        me.DataContext = Me
 
    End Sub
End Class


This successfully displayed the ID property in the ComboBox, and when selected the “SelectedColourValue” Property held the Value.