EvAlex / ef-db-diagrams

Visualize model created with EntityFramework Core
https://db-diagrams.firebaseapp.com/
MIT License
62 stars 26 forks source link

`System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' #44

Open redwards510 opened 7 years ago

redwards510 commented 7 years ago

I can't see any diagram. When I go to /db-diagram I get the following exception. It seems to have something to do with Json serialization within the project. My model seems ok, and I tried adding this configuration option to ConfigureServices() on Startup.cs

services.AddMvc()
    .AddJsonOptions(opts => {
        // Force Camel Case to JSON
        opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        // this is key to preventing cyclical infinite loops with your entities and navigation properties. 
        opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
    });

Maybe my model is somehow incorrect, but i can't figure out what the offending Entity Is. Any ideas? The exception is thrown in the Static Files middleware.

System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetCallbackMethodsForType(Type type, List`1& onSerializing, List`1& onSerialized, List`1& onDeserializing, List`1& onDeserialized, List`1& onError)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveCallbackMethods(JsonContract contract, Type t)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteStartArray(JsonWriter writer, Object values, JsonArrayContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Microsoft.Extensions.DependencyInjection.EfDiagramsMiddleware.<GetModel>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Extensions.DependencyInjection.EfDiagramsMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
mpartipilo commented 6 years ago

I ran into the same problem. Did you figure it out?

mpartipilo commented 6 years ago

I'm guessing this is related to the library not supporting .net standard 2.0.

mpartipilo commented 6 years ago

I had to build my own version of the package to get rid of this one. I couldn't sit and wait for @EvAlex to fix it for me :smile:

redwards510 commented 6 years ago

@mpartipilo you built a .net standard verison? care to share it? i couldnt get it to work!

mpartipilo commented 6 years ago

Yes. Got it working and fixed a bug in the process.

Will share in about 30 minutes.

Michelangelo P.

On 5 Jan 2018, at 18:35, Ryan E notifications@github.com wrote:

@mpartipilo you built a .net standard verison? care to share it? i couldnt get it to work!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mpartipilo commented 6 years ago

@redwards510 Here it is: https://github.com/mpartipilo/ef-db-diagrams

Let me know if it works out.

JaronrH commented 6 years ago

@mpartipilo Thanks - worked great for me!

greygreg87 commented 5 years ago

Hi,

When I launch db-diagrams url I got:

Failed to load database model. Response with status: 500 Internal Server Error for URL: http://localhost:64244/db-diagrams/model

When I launch db-diagrams/model url I got:

TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' from assembly 'Microsoft.EntityFrameworkCore, Version=2.1.4.0, Culture=neutral, PublicKeyToken=

I also created application in dotnet core 2.0 and there is the same error:

TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' from assembly 'Microsoft.EntityFrameworkCore, Version=2.0.0.0, Culture=neutral, PublicKeyToken=

These are my packages (in dotnet core 2.0 app):

 <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.Diagrams" Version="0.4.2" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.0.0" />
  </ItemGroup>

Does anyone know what I'm doing wrong?

MuhAssar commented 5 years ago

@redwards510 Here it is: https://github.com/mpartipilo/ef-db-diagrams

Let me know if it works out.

is there a prebuilt nuget package using this source?

A-Justice commented 5 years ago

Hello .. How do i replace this with the one i downloaded from nugget