Kloudrazor Kloudrazor - 1 year ago 75
C# Question

Why is my ViewModel not found?

Why can't VS find my file? VS Error Image and Text:

Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'AudioFile' could not be found (are you missing a using directive or an assembly reference?) reOrder C:\Users\kloud\Documents\Visual Studio 2015\Projects\reOrder\reOrder\ReorderPage.xaml.cs 27 Active

I recreated the project to see if Visual Studio was doing something I couldn't see/understand and checked extensively with code that is working(correctly finds the item and binds) to see where the differences are. I couldn't find any clues though.

edit: I am using Visual Studio 2015 Community Edition on Windows 10 Anniversary Update. Also, in previous projects VS didn't have trouble finding and binding to a model.

Full code below.

Reorder Page


<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>

<ListView Grid.Row="1"
ItemsSource="{x:Bind AudioFiles}">
<DataTemplate x:DataType="viewModels:AudioItem">
<TextBlock Text="{x:Bind Name}"/>

AudioItem Model
(skipped usings)

namespace reOrder.Models
public class AudioItem
public string Path { get; set; }

public string Name { get; set; }

public int Duration { get; set; }

Answer Source

I had the same problem even after rebuilding the solution.One workaround i did was Go to your .csproj file in file explorer and now edit under itemgroup tag add this:

<Compile Include="ViewModels\AudioItemModel .cs">

Save it and close it and then rebuild it and now it will detect the viewmodel.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download