首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InsertOnSubmit()导致MissingMethodException

InsertOnSubmit()导致MissingMethodException
EN

Stack Overflow用户
提问于 2012-01-18 09:12:34
回答 2查看 852关注 0票数 1

我试图在一个WP7芒果项目中实现SQL,但是现在当我试图将一个对象插入/保存到我的DB时,我遇到了这个错误。

我的代码如下:

代码语言:javascript
复制
public static void Save(MyObject myobject)
    {
        using (DBDataContext dc = new DBDataContext(DBDataContext.ConnectionString))
        {
            dc.MyObject.InsertOnSubmit(myobject);
            dc.SubmitChanges();
        }
    }

当代码命中插入提交行时,它将中断

代码语言:javascript
复制
MissingMethodException was unhandled
MissingMethodException

这就是它告诉我的全部。

呼叫堆栈:

代码语言:javascript
复制
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绑定器、对象参数、System.Globalization.CultureInfo区域性、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绑定器,object[]参数,System.Globalization.CultureInfo区域性,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(object上下文)+ 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,+ 0x5e字节外部代码

我已经成功地插入了其他对象,使用了同样的方法,但是我不知道是什么使这个对象不同。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-19 07:41:01

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

最近,我的类必须有一个空的构造器,如果它们没有,错误就会出现。因此,向我的类中添加空构造函数可以解决这个问题。

票数 1
EN

Stack Overflow用户

发布于 2012-11-26 19:50:05

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8907621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档