Blazor a Class Library reference in the WebAssembly client is failing to connect .NET 6

17 Views Asked by At

I have a folder called Services; it is in fact in program.cs and a simple GET localStorage operation works fine. Now I am adding another function in the same file (Cache). This function needs to Set the data for a type (public class AppUserDto) that is in a class library called SharedDTOs, because it can be referred to from client (where Cache is) and also from API (backend server).

using Blazored.LocalStorage;

namespace client.Services
{
    public class Cache
    {
        private readonly ILocalStorageService _localStorage;

        public Cache(ILocalStorageService localStorage)
        {
            _localStorage = localStorage;
        }

        /// <summary>
        /// User Specification
        /// </summary>
        public async Task<string> GetKnownAs()
        {
            return await _localStorage.GetItemAsStringAsync("knownAs") ?? string.Empty;
        }

        public async Task SetAppUser(AppUserDto dto)
        {
            await _localStorage.SetItemAsync<AppUserDto>("AppUser", dto);
        }
    }
}

The compiler can't find AppUserDto, which is like this:

using System;

namespace SharedDTOs {
    public class AppUserDto {
        public string Id { get; set; } = string.Empty;
        public string UserName { get; set; } = string.Empty;
....

I tried adding a using SharedDTOs but that didn't work. ?

0

There are 0 best solutions below