Resolved Migrating to .Net Standard 2.1

Scottintexas

Well-known member
Joined
Jun 21, 2018
Messages
47
Location
Texas
Programming Experience
5-10
I have migrated a .Net 4.5 to .Net Standard 2.1 and I am now working through errors. I am missing some references or Nuget packages. But I cannot find them. For example (and there are several), The App.g.cs file that is automatically created by VS has several references that say "The type or namespace ... does not exist in the System.Windows namespace. As in all of these. But I cannot get a reference to System.Windows.
C#:
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;

Another is;
C#:
[assembly: ThemeInfo(
    ResourceDictionaryLocation.None,
    ResourceDictionaryLocation.SourceAssembly
)]

Where ThemeInfo is not an attribute class and ]ResourceDictionaryLocation does not exist in the current context.

And, what I consider the worst, is a partial class derived from UserControl can't compile because the type or namespace UserControl cannot be found. The solution here is to include a reference to PresentationFramework. But I cannot find it.

My csproj file includes
C#:
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

Finally, none of my views are visible, just the XAML. So something didn't get created when I made the changes to .Net Standard. Can anyone tell me what I need to do to get the missing references?
 
Last edited by a moderator:
Solution
Part of the issue here is that this code you are trying to migrated shouldn't be going from .NET Framework 4.5 to .NET Standard 2.1. It should be going from .NET Framework 4.5 to .NET 6.0 (or .NET Core 3.1). .NET Standard is supposed to be cross platform. There is no WPF in the other platforms. Choosing .NET 6.0 lets you pick a target platform. Hopefully the target platform you pick supports WPF.
Yes. You just type a Using statement to import a namespace. But as shown above, it does not work because "The type or namespace name 'name' does not exist in the namespace 'namespace' (are you missing an assembly reference?)" When looking for an assembly reference there is nothing to reference. Just the assemblies I had with the .Net 4.5 Framework. Suppose I select System.dll just to see what happens. I get a dialog box that says it is invalid or unsupported. If I hover over the error on "MessageBox.Show" I see that MessageBox does not exist in the current context. The fix is to fully qualify the object so I would have to add System.Windows.Forms.MessageBox, or I could just add a using statement. As shown above, anything beyond System.Windows generates an error, like System.Windows.Data. Where Data is the offending word.

It looks like most of the errors have to do with Views and auto generated files like "myView.g.i.cs." I am looking at one that has 27 errors and 16 of those are due to System.Windows namespace as shown in the OP.

One little thing is going to fix this whole mess. I just don't know what that thing is.
 
Part of the issue here is that this code you are trying to migrated shouldn't be going from .NET Framework 4.5 to .NET Standard 2.1. It should be going from .NET Framework 4.5 to .NET 6.0 (or .NET Core 3.1). .NET Standard is supposed to be cross platform. There is no WPF in the other platforms. Choosing .NET 6.0 lets you pick a target platform. Hopefully the target platform you pick supports WPF.
 
Solution
Back
Top Bottom