Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向pObject添加类时发生反射类型加载异常 我现在开发了一个C WWPF应用程序,它运行良好,直到我把VHDC++封装器类添加到我的项目,女巫是PRITTY大,所以我不张贴在这里,它本身工作良好。在我的项目中,当添加类文件并运行我的程序时,我在EntityFramework的这一行中得到一个错误 CDEnteties.Services.Add(service);_C#_Entity Framework_System.reflection - Fatal编程技术网

C# 向pObject添加类时发生反射类型加载异常 我现在开发了一个C WWPF应用程序,它运行良好,直到我把VHDC++封装器类添加到我的项目,女巫是PRITTY大,所以我不张贴在这里,它本身工作良好。在我的项目中,当添加类文件并运行我的程序时,我在EntityFramework的这一行中得到一个错误 CDEnteties.Services.Add(service);

C# 向pObject添加类时发生反射类型加载异常 我现在开发了一个C WWPF应用程序,它运行良好,直到我把VHDC++封装器类添加到我的项目,女巫是PRITTY大,所以我不张贴在这里,它本身工作良好。在我的项目中,当添加类文件并运行我的程序时,我在EntityFramework的这一行中得到一个错误 CDEnteties.Services.Add(service);,c#,entity-framework,system.reflection,C#,Entity Framework,System.reflection,我收到一个错误{“无法从程序集'cloud opeaner,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'加载类型'STORAGE\u DEPENDENCY\u INFO\u Union',因为它包含偏移量为0的对象字段,该字段未正确对齐或与非对象字段重叠。”:“STORAGE\u DEPENDENCY\u INFO\u Union”}我不知道这两件事有什么关系,为什么会发生 编辑: 堆栈跟踪 at System.Reflection.R

我收到一个错误{“无法从程序集'cloud opeaner,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'加载类型'STORAGE\u DEPENDENCY\u INFO\u Union',因为它包含偏移量为0的对象字段,该字段未正确对齐或与非对象字段重叠。”:“STORAGE\u DEPENDENCY\u INFO\u Union”}我不知道这两件事有什么关系,为什么会发生

编辑: 堆栈跟踪

at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.Data.EntityUtil.GetTypesSpecial(Assembly assembly)
at System.Data.Metadata.Edm.ObjectItemConventionAssemblyLoader.LoadTypesFromAssembly()
at System.Data.Metadata.Edm.ObjectItemAssemblyLoader.Load()
at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, ObjectItemLoadingSessionData loadingData)
at System.Data.Metadata.Edm.AssemblyCache.LoadAssembly(Assembly assembly, Boolean loadReferencedAssemblies, KnownAssembliesSet knownAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage, Object& loaderCookie, Dictionary`2& typesInLoading, List`1& errors)
at System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
at System.Data.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly, Action`1 logLoadMessage)
at System.Data.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly)
at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
at System.Data.Entity.DbSet`1.Add(TEntity entity)
at cloud_opeaner.OAtuhStorage.storeService(Service& service) in e:\pytons\projects c#\vs12 test\cloud opeaner\cloud opeaner\OAuthStorage.cs:line 105
at cloud_opeaner.SkyDrive..ctor() in e:\pytons\projects c#\vs12 test\cloud opeaner\cloud opeaner\SkyDrive.cs:line 51
at cloud_opeaner.MainWindow.Button_Click_1(Object sender, RoutedEventArgs e) in e:\pytons\projects c#\vs12 test\cloud opeaner\cloud opeaner\MainWindow.xaml.cs:line 87
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at cloud_opeaner.App.Main() in e:\pytons\projects c#\vs12 test\cloud opeaner\cloud opeaner\App.xaml.cs:line 24
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

看起来这与EF本身无关。您的程序集中似乎有一个无效的类型,EF只是接触它,因此它会爆炸。如果尝试手动加载此类型(例如,
Console.WriteLine(typeof('STORAGE\u DEPENDENCY\u INFO\u Union').FullName);
),即使项目中没有EF,也会看到相同的异常。如果不使用该类型,则需要修复或删除该类型(以及依赖该类型的代码)。

Show the stack trace.EF正在尝试加载与模型匹配的类型。其方法是从程序集中探测所有类型。尝试将类型放入单独的程序集中。顺便说一句,如果无法加载类型,你的包装器类在.NET项目中应该如何工作?我不确定你在问什么,我找到了一个小样本应用程序,可以在framework 4.5下编译,运行良好。当我将代码添加到我的应用程序时,我得到了错误,代码在这里我只是更改了名称空间和类名,我在问您是否能够使用导入的代码-尤其是GetStorageDependencyInformation方法?它们的类型对齐有问题(这样做是为了匹配本机结构/联合)。我相信'STORAGE\u DEPENDENCY\u INFO\u Union'类型有问题,但由于您没有使用它,CLR不会尝试加载它,您也看不到问题。要确认-在使用EF(或创建没有EF的测试应用程序)之前,请在应用程序中放入
Console.WriteLine(typeof('STORAGE\u DEPENDENCY\u INFO\u Union')。全名)您是否看到相同的异常?抱歉,等待,我在类
控制台.WriteLine(typeof(NativeMethods.STORAGE\u DEPENDENCY\u INFO\u Union.FullName)中添加了代码行然后调用它。获取异常{“无法从程序集'cloud opeaner take1,版本=1.0.0.0,区域性=neutral,PublicKeyToken=null'加载类型'STORAGE\u DEPENDENCY\u INFO\u Union',因为它包含偏移量为0的对象字段,该字段未正确对齐或与非对象字段重叠。”:“STORAGE\u DEPENDENCY\u INFO\u Union”}。那么,这种结构是问题的根源吗?