MSDN > フォーラム ホーム > ADO.NET Entity Framework and LINQ to Entities > Exception in constructor of object context
質問する質問する
 

質問Exception in constructor of object context

  • 2008年12月18日 22:07Sergey Barskiy ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    I setup an object context, but when I instantiate it, I get an execption.

    Here is when the error occurs (in auto-generated code):

    public MySilverEntities(string connectionString) :

    base(connectionString, "MySilverEntities")

    {

    this.OnContextCreated();

    }
    Here is the exception
    System.NotSupportedException occurred
      Message="The invoked member is not supported in a dynamic assembly."
      Source="mscorlib"
      StackTrace:
           at System.Reflection.Emit.AssemblyBuilder.GetManifestResourceNames()
      InnerException:
    However, after the excpetion normal execute occurs, meaning that the exception is caught in the base class.

    Any suggestions?

    Thank you

    Sergey.


    Sergey

すべての返信

  • 2009年7月3日 16:16Bobby Fu ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Sergey, have you solved the problem or find a workaround solution?  I've seen the same exception occurring in my generated code.  I'm looking for a workaround....

    Thanks
    Bobby
  • 2009年7月4日 7:23Daniel Simmons - MSFT所有者ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Can you give a stack trace?
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • 2009年7月6日 12:21Ash Eldritch ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Edit: This error is ONLY thrown if you've explicitly told your debugger to break on CLR exceptions.

    I just started getting this error, after starting to pass a modified connection string to the constructor. The weird thing is I'm now still getting the error even after rolling everything back to the previous code.

    The error is thrown at any of the generated constructors:
    public MyEntities(string connectionString) : base(connectionString, "MyEntities")
    ...or...
    public MyEntities(global::System.Data.EntityClient.EntityConnection connection) : base(connectionString, "MyEntities")
    ...or...
    public MyEntities() : base("name=MyEntities", "MyEntities")

    The Stack Trace in its entirety is: at System.Reflection.Emit.AssemblyBuilder.GetManifestResourceNames()

    Even after throwing the error, execution continues and everything works fine as long as you're not debugging.


    The description for GetManifestResourceNames is illuminating:

    public override string[] GetManifestResourceNames()
        Member of System.Reflection.Emit.AssemblyBuilder

    Summary:
    Loads the specified manifest resource from this assembly.

    Returns:
    An array of type String containing the names of all the resources.

    Exceptions:
    System.NotSupportedException: This method is not supported on a dynamic assembly. To get the manifest resource names, use System.Reflection.Assembly .GetManifestResourceNames().
    System.Security.SecurityException: The caller does not have the required permission.


    Ash
  • 2009年7月7日 7:02Srikanth Mandadi - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    By default the Entity Framework metadata artifacts are included as assembly resources and the connection string includes metadata path similar to "res://*/model.csdl;res://*/model.csdl;res://*/res.msl" when you build an EF application through VS. The "res://*" tells the EF runtime that the metadata files are in one of the referenced assemblies as an embedded resource.  During runtime, EF tries to find the metadata resources by walking the referenced assemblies. But the above exception is hit if one of the assemblies in this list is a dynamic assembly. In this case, we catch the exception and continue since in .Net 3.5 we did not have a clean way to determine if an Assembly is Dynamic. But in .Net 4.0( VS 2010), a property has been added on Assembly class which can be used to determine if an assembly is a dynamic one. So this issue has been fixed in VS 2010 Beta 1 by checking if an assembly is dynamic before calling the GetManifestResourceNames method.
    One way to work around the problem in VS 2008 is to change the metadata paths in the connection string to point to a specific assembly rather than *.
    ex:
    Metadata=res://AdventureWorks, 1.0.0.0, neutral, a14f3033def15840/model.csdl| 
    res://AdventureWorks, 1.0.0.0, neutral, a14f3033def15840/model.ssdl| 
    res://AdventureWorks, 1.0.0.0, neutral, a14f3033def15840/model.msl
    Thanks
    Srikanth
    This posting is provided "AS IS" with no warranties, and confers no rights.