ardalis / SmartEnum

A base class for quickly and easily creating strongly typed enum replacements in C#.
MIT License
2.16k stars 169 forks source link

The type 'SmartEnum<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Ardalis.SmartEnum, Version=1.0.8.0, Culture=neutral, PublicKeyToken=null'. BlazorApp1 112 Active #219

Open imprathamesh opened 2 years ago

imprathamesh commented 2 years ago

I created the razor class library project use Ardalis SmartEnum to create a blazor component. Smart Enum works fine in RCL Project and Also .razor component created fine with error. After I give reference to my Blazor WASM Project The show me error.

getting this error: The type 'SmartEnum<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Ardalis.SmartEnum,

I tried to add the Ardalis Smart Enum nuget package into my Blazor WASM but it show Exclamation icon on dependancy folder and it resolved. by cleaning the project or deleting the bin/obj folders. So whats the exact Issue?

both project developed in .Net6

` Index.Razor Componennt @using Ardalis.SmartEnum <div class="col-xxl-@Size.Name col-xl-@Size.Name col-lg-@Size.Name col-md-12 col-sm-12 col-xs-12 mb-2 h-100 @Class" @attributes="AdditionalAttributes"> @ChildContent

@code { [Parameter] public ColumnSize Size { get; set; } = ColumnSize.Three; [Parameter] public RenderFragment? ChildContent { get; set; } [Parameter] public string? Class { get; set; } [Parameter(CaptureUnmatchedValues = true)] public IReadOnlyDictionary<string, object>? AdditionalAttributes { get; set; } }

ColumnSize.cs using Ardalis.SmartEnum; namespace ProjectComponents.Enums; public sealed class ColumnSize : SmartEnum { public static readonly ColumnSize One = new("1", 1); public static readonly ColumnSize Two = new("2", 2); public static readonly ColumnSize Three = new("3", 3);

public ColumnSize(string name, int value) : base(name, value) { } }`

ardalis commented 2 years ago

Is this still an issue with version 2.1.0 ?

imprathamesh commented 2 years ago

Yes. Sometime. But it resolved only by installing the SmartEnum package before add reference of RCL Project. really don't why this is happened. Is it matters to install SmartEnum First into Blazor Client Project before RCL Project Ref?

scleaver commented 1 year ago

I am having this issue too. SmartEnum 2.1.0 is used in my SharedKernel which is .NetStandard 2.0 and I am adding the SharedKernel project to a .Net 4.8 class library and getting:

"ExceptionMessage": "Could not load file or assembly 'Ardalis.SmartEnum, Version=1.0.8.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.",
  "ExceptionType": "System.IO.FileNotFoundException",

I tried to overcome the issue by also adding SmartEnum to my 4.8 project and it didn't resolve the issue. The file specified is def there.

<Reference Include="Ardalis.SmartEnum, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL"> 
  <HintPath>..\packages\Ardalis.SmartEnum.2.1.0\lib\netstandard2.0\Ardalis.SmartEnum.dll</HintPath> 
</Reference> 

I also tried downgrading the version to 1.0.8 with no success.

Haven't solved it yet.

Kinda a bummer cause the SmartEnum solved my issue very nicely.