dsuryd / dotNetify-react-template

Real-time React SPA template using dotNetify.
https://dotnetify.net/react
Apache License 2.0
203 stars 57 forks source link

ViewModel not getting loaded even after registering assembly with all viewmodels #21

Closed sachin27sharma closed 6 years ago

sachin27sharma commented 6 years ago

i had a view model derived from BaseVM which is working fine (without adding any additional RegisterAssembly), Now when i added another viewmodel derived from BaseVM, am getting below error - "ERROR: 'UserVm' is not a known view model! Its assembly must be registered through VMController.RegisterAssembly."

I tried with registering assembly using both by config and RegisterAssembly still same error. NOTE - was using 2.3.0-pre version, even after upgrading to 3.0.0-pre (for both nuget and client library).

app.UseDotNetify(config => { config.RegisterAssembly(GetType().Assembly); // Middleware to do authenticate token in incoming request headers. config.UseJwtBearerAuthentication(new TokenValidationParameters { IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(AuthServer.SecretKey)), ValidateIssuerSigningKey = true, ValidateAudience = false, ValidateIssuer = false, ValidateLifetime = true, ClockSkew = TimeSpan.FromSeconds(0) });

    // Filter to check whether user has permission to access view models with [Authorize] attribute.
    config.UseFilter<AuthorizeFilter>();
 });

VMController.RegisterAssembly(GetType().Assembly);

Please clarify.

dsuryd commented 6 years ago

Assuming all your vms are on the same assembly, most time I saw the error was because the vm name set on the client didn't fully match the c# class name. Pls check that first.

sachin27sharma commented 6 years ago

Just checked, the name looks alright. Will try cleaning node_modules but i suspect that shouldn't be an issue.

dsuryd commented 6 years ago

Add this to the config so you can debug why the type wasn't found:

config.SetFactoryMethod((type, args) => {
   return Activator.CreateInstance(type, args);
}
dsuryd commented 6 years ago

Was this resolved?

sachin27sharma commented 6 years ago

Yes. create a new model separately and it worked. later found a bug in the viewmodel which wasn't loading. so all good. Thanks