How to Find Logs on a Live Production Server Hosting AspNet 6 App

Views 153 Likes 1

Watch More
Cannot create a DbSet for "MyModal" because this t ..

Question: I have no idea what is going on with this error. Yes, the error is quite descriptive but finding exactly where the issue might be is challenging. See the error below:

"Cannot create a DbSet for "MyModal" because this type is not included in the model for the context. However, the model contains an entity type with the same name in a different namespace".

What am I missing?

Answer: This is most likely the Runtime Error, you don't see this error when Building or cleaning the Solution but when you attempt to run the application. This is called a Runtime Error.

From the description of the error, it sounds like you have a DbSet for your Modal in the Database Context C-sharp class but you haven't defined that Modal in the OnCreate Section of the Database Context.

See possible solution below:

1. Verify that you are not using the same namespace in two (which is supposed to be two different classes) the same name of the Modal class. If yes, rename the NameSpace in the other Model Class.
2. Make sure that the Model Class that is throwing an error is not trying to use the wrong NameSpace somewhere in your code.

     A case for this issue is when you have a UserProfile Model class that you copied from another NameSpace and try to use it in a new Project but somewhere in your new project, you are still referencing the Old NameSpace. This causes the conflict on Runtime and the Compiler doesn't know which Class from which NameSpace to register into the Assembly.



Views: 0
Category: .NET 6 Likes 0

How to Host an ASP.Net 6 Application In IIS Using AspNetCore Hosting Bundle

Views 514 Likes 0

Watch More
Microsoft.CSharp.RuntimeBinder.RuntimeBinderExcept ..

Question: How to you solve for "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The call is ambiguous between the following methods or properties" it goes on and say "System.Text.JsonSerializer.Deserialize<MyObject>(System.IO.Stream,System.Text.Json.JsonSerializerOptions)" and "System.Text.JsonSerializer.Deserialize<MyObject>(string,System.Text.Json.JsonSerializerOption)".

I mean, isn't the Compiler Intelligent enough to know what type of parameter I just passed in?


Answer: Take a deeper look at the parameter you are passing into the Deserialize function, the compiler is correct, it is not able to know the type of the object passed in the function right away or at least on RunTime. There is a chance you are passing in an object of type "dynamic" as you know passing in the object of type "dynamic" could not be evaluated until the object is actually available for evaluation at RunTime.

If possible stay away from passing in the Dynamic Type object into a function that gets its parameters evaluated at RunTime, this might cause errors in Production as the Type of the Object might change.

The best way to handle this scenario is by explicitly defining the Object type, yes I know some of you might be saying "Well, that means that I have to allocate memory on the Stack to store the object" but yes, that is correct.

If Memory allocation is your issue, you can not entirely run away from it, you could do something about it by using Shared ArrayPool and returning that Pool when you are done using it. Keep in mind that Array Pooling might have its own caveats, when borrowing the Array from the Pool, the Array shared might not be empty, however, you can handle this test case by checking every time you use a Shared Array from the Pool.

The error is most likely to occur if you have your code written as

MyObject obj = Json.JsonSerializer.Deserializer<MyObjectType>(_cache.getDynamicObjectFromCache);

The _cache.getDynamicObjectFromCache() returns a object of type "Dynamic" which is throwing an exception. Please leave a comment below illustrating how you solved this issue. You don't need to log in to post a comment.

 

 

Views: 0
Category: .NET 6 Likes 0

Salted Butterscotch

Views 1040 Likes 8

Watch More

Why Omaha Nebraska is the best place for vacation

Views 1373 Likes 8

Watch More

What is ErnesTech

Views 1164 Likes 13

Watch More

How to Get Rid of SQL Server Management Big Black Blinking Cursor

Views 1880 Likes 10

Watch More

A second operation started on this context before a previous operation completed

Views 1351 Likes 17

Watch More

Himalayan Salt Lamp for Sale

Views 1178 Likes 34

Watch More

Natural Wood Decor

Views 742 Likes 30

Watch More

How to draw in 3D with a pencil

Views 3470 Likes 45

Watch More
Loading...
Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy