【问题标题】:InsertOnSubmit() causes MissingMethodExceptionInsertOnSubmit() 导致 MissingMethodException
【发布时间】:2012-01-18 09:12:34
【问题描述】:

我正在尝试在 WP7 Mango 项目中实现 SQL CE,但现在当我尝试将对象插入/保存到我的数据库时遇到此错误。

我的代码如下:

public static void Save(MyObject myobject)
    {
        using (DBDataContext dc = new DBDataContext(DBDataContext.ConnectionString))
        {
            dc.MyObject.InsertOnSubmit(myobject);
            dc.SubmitChanges();
        }
    }

当代码到达 insertonsubmit 行时,它会中断

MissingMethodException was unhandled
MissingMethodException

这就是它告诉我的全部内容。

调用栈:

mscorlib.dll!System.Activator.InternalCreateInstance(System.Type type, bool nonPublic, ref System.Threading.StackCrawlMark stackMark) + 0xe4 bytes  
mscorlib.dll!System.Activator.CreateInstance(System.Type type) + 0x2 bytes  
System.Data.Linq.dll!System.Data.Linq.WorkAround.ActivationHelper.CreateInstance(System.Type type)  
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackedObject.CreateDataCopy(object instance) + 0x12 bytes    
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.StandardTrackedObject.StartTracking() + 0x16 bytes    
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.OnPropertyChanging(object sender, System.ComponentModel.PropertyChangingEventArgs args) + 0x16 bytes  
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.Attach(object obj) + 0x1f bytes   
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.Track(System.Data.Linq.Mapping.MetaType mt, object obj, System.Collections.Generic.Dictionary<object,object> visited, bool recurse, int level) + 0x4e bytes   
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.Track(object obj, bool recurse) + 0x1d bytes  
System.Data.Linq.dll!System.Data.Linq.ChangeTracker.StandardChangeTracker.Track(object obj) + 0x3 bytes 
System.Data.Linq.dll!System.Data.Linq.Table<FotoDok.EkstraFeltMulighed>.InsertOnSubmit(FotoDok.EkstraFeltMulighed entity) + 0xac bytes  

FotoDok.dll!FotoDok.EkstraFeltMulighed.Gem(FotoDok.EkstraFeltMulighed ekstrafeltmulighed) 第 70 行 + 0xc 字节 C# FotoDok.dll!FotoDok.opdaterProjekter.behandlProjektJson(Newtonsoft.Json.Linq.JObject o) 第 202 行 + 0x7 字节 C# FotoDok.dll!FotoDok.opdaterProjekter.ReadCallbackValgteProjekter.AnonymousMethod__1(System.Windows.Controls.CheckBox delChk, Newtonsoft.Json.Linq.JObject delO) 第 141 行 + 0x7 字节 C# mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo rtmi, object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object parameters, System.Globalization.CultureInfoculture, bool isBinderDefault, System .Reflection.Assembly 调用者,bool verifyAccess,ref System.Threading.StackCrawlMark stackMark)
mscorlib.dll!System.Reflection.RuntimeMethodInfo.InternalInvoke(object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, object[] parameters, System.Globalization.CultureInfoculture, ref System.Threading.StackCrawlMark stackMark) + 0x168 字节 mscorlib.dll!System.Reflection.MethodBase.Invoke(object obj, object[] 参数) + 0xa 字节
mscorlib.dll!System.Delegate.DynamicInvokeOne(object[] args) + 0x98 字节
mscorlib.dll!System.MulticastDelegate.DynamicInvokeImpl(object[] args) + 0x8 字节
mscorlib.dll!System.Delegate.DynamicInvoke(object[] args) + 0x2 字节
System.Windows.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0xc 字节
System.Windows.dll!System.Windows.Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority 优先级) + 0x83 字节
System.Windows.dll!System.Windows.Threading.Dispatcher.OnInvoke(对象上下文)+ 0x8 字节 System.Windows.dll!System.Windows.Hosting.CallbackCookie.Invoke(object[] args) + 0x19 字节 System.Windows.dll!System.Windows.Hosting.DelegateWrapper.InternalInvoke(object[] args) + 0x2 字节 System.Windows.RuntimeHost.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam[] pParams, ref System.Windows.Hosting.NativeMethods.ScriptParam pResult ) + 0x5e 字节 [外部代码]

我已经设法插入其他对象,使用相同的方法就好了,但我不知道是什么让这个对象有任何不同。

【问题讨论】:

  • 您能否提供完整的异常以及调用堆栈?它可能会(也可能不会)有帮助。
  • 添加了调用堆栈。除了我写的内容之外,该异常不包含任何其他内容。
  • 你的类型是结构体吗?还是一堂课?

标签: sql windows-phone-7 missingmethodexception


【解决方案1】:

我自己解决了这个问题,在谷歌上搜索了更多(典型的,搜索了几个小时,然后在这里发帖后我偶然发现了一个答案..)

显然我的课程必须有一个空的构造函数,如果他们没有出现错误。 所以向我的类添加空构造函数解决了它。

【讨论】:

    【解决方案2】:

    我想补充一点,构造函数必须是公共的。我有同样的问题,但是在我的模型类中我有空的内部构造函数。

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 2011-03-31
      • 1970-01-01
      • 2023-03-11
      • 2011-01-27
      • 1970-01-01
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多