I have recently converted my .NET Framework 4.8 WPF application to .NET5. When I compile the application, I am get below error
The name 'InitializeComponent' does not exist in the current context
I followed this link but couldn't helped me much.
I checked both *.xaml
and *.cs
file namespace.
<Window x:Class="Cl.Wpf.MessageWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent = "WidthAndHeight"
Title="MessageWindow" >
Also checked .cs
file
namespace Cl.Wpf
{
public partial class MessageWindow : Window
{
public MessageWindow()
{
InitializeComponent();
.....
}
My *.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>Cl.Wpf</RootNamespace>
<Deterministic>false</Deterministic>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.2.241603">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
I also tried deleting obj
folder and restarted visual studio 2019 but also did not help me out.
Also, tried adding some space in the XAML
file but that didn't help as well.
Build Action MessageWindow.xml