Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
redwards510 opened this issue Sep 13, 2017 · 10 comments

Comments

@redwards510
Copy link

redwards510 commented Sep 13, 2017

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()
@redwards510 redwards510 changed the title `System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' from assembly 'Microsoft.EntityFrameworkCore, `System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior' Sep 15, 2017
@mpartipilo
Copy link

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

@mpartipilo
Copy link

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

@mpartipilo
Copy link

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 😄

@redwards510
Copy link
Author

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

@mpartipilo
Copy link

mpartipilo commented Jan 5, 2018 via email

@mpartipilo
Copy link

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

Let me know if it works out.

@JaronrH
Copy link

JaronrH commented Aug 13, 2018

@mpartipilo Thanks - worked great for me!

@greygreg87
Copy link

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
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants