我想写一个MS Message Queue的异常.当我尝试它时,我得到一个例外.所以我尝试使用仍然引发异常的XmlSerializer来简化它,但它给了我更多信息:
{"反映类型'System.Exception'时出错."}
与InnerException:
{"无法序列化System.Collections.IDictionary类型的成员System.Exception.Data,因为它实现了IDictionary."}
示例代码:
Exception e = new Exception("Hello, world!");
MemoryStream stream = new MemoryStream();
XmlSerializer x = new XmlSerializer(e.GetType()); // Exception raised on this line
x.Serialize(stream, e);
stream.Close();
Run Code Online (Sandbox Code Playgroud)
编辑:我尽量保持这个简单,但我可能已经过头了.我想要整个位,堆栈跟踪,消息,自定义异常类型和自定义异常属性.我甚至可能想再次抛出异常.
我已经使用2.0框架尝试了以下代码,我得到了一个属性,但是当我在紧凑框架上尝试这个时,它总是返回一个空数组.MSDN文档说它支持,我做错了吗?
Test x = new Test();
FieldInfo field_info = x.GetType().GetField("ArrayShorts");
object[] custom_attributes = field_info.GetCustomAttributes(typeof(MarshalAsAttribute), false);
[StructLayout(LayoutKind.Sequential)]
public struct Test
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ushort[] ArrayShorts;
}
Run Code Online (Sandbox Code Playgroud) c# attributes compact-framework marshalling getcustomattributes
我有一个移动应用程序.我的客户端有大量数据集~100,000条记录.它经常更新.我们同步时需要从一个数据库复制到另一个数据库.
我已将第二个数据库附加到main,并运行一个insert into table select * from sync.table.
这非常慢,我认为大约需要10分钟.我注意到日志文件逐步增加.
我怎样才能加快速度呢?
编辑1
我有索引,我有日记.运用
insert into table select * from sync.table
Run Code Online (Sandbox Code Playgroud)
它还需要10分钟.
编辑2
如果我运行像这样的查询
select id,invitem,invid,cost from inventory where itemtype = 1
order by invitem limit 50
Run Code Online (Sandbox Code Playgroud)
需要15-20秒.
表模式是:
CREATE TABLE inventory
('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
'serverid' INTEGER NOT NULL DEFAULT 0,
'itemtype' INTEGER NOT NULL DEFAULT 0,
'invitem' VARCHAR,
'instock' FLOAT NOT NULL DEFAULT 0,
'cost' FLOAT NOT NULL DEFAULT 0,
'invid' VARCHAR,
'categoryid' INTEGER DEFAULT …Run Code Online (Sandbox Code Playgroud) 背景:
我正在尝试创建一个实用程序,允许我们的客户直接在Windows Mobile 6设备(Intermec CK3)上轻松格式化SD卡(实际上是mini-SD).这将优于FlashFormat等第三方工具或必须向客户提供读卡器(这将要求他们取出电池,拔出由脆弱的金属外壳固定的mini-SD卡,然后通过文件管理控件运行Windows格式化实用程序).我们的大多数客户都不是非常精通技术,因此可以自动运行或通过几次点击运行的实用程序将是理想的选择.
到目前为止我已尝试过以下内容:
在做了一些搜索到这个线程(在paraGOD附近回答)和这个博客之后,我决定走下一条使用Store Manager API的新路径,它具有FindFirstStore,FindNextStore,OpenStore,DismountStore等功能. .
我正在尝试在C#中执行此操作,因此我创建了必要的支持结构来表示API中使用的typdef.这是一个样本:
using System.Runtime.InteropServices;
// Try to match the struct typedef exactly (all caps, exact type names).
using DWORD = System.UInt32;
using TCHAR = System.String;
namespace SDFormatter
{
// http://msdn.microsoft.com/en-us/library/ee490035(v=WinEmbedded.60).aspx
// STORAGEDEVICEINFO (Storage Manager)
[StructLayout(LayoutKind.Sequential)]
public struct …Run Code Online (Sandbox Code Playgroud) 这两个版本的.NET之间的兼容代码存在许多运行时差异.
这是目前为止的差异列表:
我们还有更多需要添加吗?
我有一个Pocket PC 2003解决方案,由三个项目组成,在Visual Studio 2005中创建.我在Visual Studio 2008中打开解决方案,其中两个项目由于以下错误而无法转换:
无法读取项目文件'PDA.vbproj'.D:\ PDA.vbproj(121,61):找不到导入的项目"C:\ WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.VisualBasic.targets".确认声明中的路径是否正确,以及该文件是否存在于磁盘上.
该文件存在于v2.0.50727目录中
C:\ WINDOWS\Microsoft.NET \框架\ V2.0.50727\Microsoft.CompactFramework.VisualBasic.targets
但不在v3.5目录中.我查看了另一台开发计算机,文件就在那里.我重新安装了.NET Framework和Compact Framework的v3.5,但是没有恢复该文件.它从何而来?
我正在尝试创建一个DataGridTableStyle对象,以便我可以控制DataGrid的列宽.我创建了一个绑定到List的BindingSource对象.实际上,它通过以下方式绑定到通过Linq创建的匿名类型列表(为了清楚我正在做的事情,变量名称已更改):
List<myType> myList = new List<myType>(someCapacity);
.
...populate the list with query from database...
.
var query = from i in myList
select new
{
i.FieldA,
i.FieldB,
i.FieldC
};
myBindingSource.DataSource = query;
myDataGrid.DataSource = myBindingSource;
Run Code Online (Sandbox Code Playgroud)
然后我创建一个DataGridTableStyle对象并将其添加到datagrid.但是,它永远不会应用我设置的表格样式属性,因为我似乎无法设置正确的myDataGridTableStyle.MappingName属性.
我在谷歌搜索了大约1/2个小时,并且在一堆不同的论坛中一直看到相同问题的链接(字面意思是相同的文字,就像有人刚刚复制并粘贴了问题......我讨厌那个......) .无论如何,没有一个建议有效,就像那个人在所有其他网站上说的那样.
那么有谁知道我需要设置MappingName属性,以使我的TableStyle实际上正常工作?我在哪里可以从中获取名称?(它不能为空......只适用于绑定到DataTable或SqlCeResultSet等的BindingSource).
我认为这可能是一个问题,我使用Linq创建一个匿名的,更专业的对象版本,只有我需要的字段.我应该尝试将BindingSource直接绑定到List对象吗?或者甚至可以将DataGrid直接绑定到List对象并完全跳过绑定源.
谢谢
PS - C#,Compact Framework v3.5
更新:
我在下面发布了一个解决了我的问题的答案.无论它是否是最好的方法,它确实有效.值得一看,如果你遇到同样的问题.
c# datagrid compact-framework bindingsource datagridtablestyle
我有一个界面:
interface IProfile { ... }
Run Code Online (Sandbox Code Playgroud)
......和一个班级:
[Serializable]
class Profile : IProfile
{
private Profile()
{ ... } //private to ensure only xmlserializer creates instances
}
Run Code Online (Sandbox Code Playgroud)
...和一个经理方法:
class ProfileManager
{
public T Load<T>(string profileName) where T : class, IProfile
{
using(var stream = new .......)
{
var ser = new XmlSerializer(typeof(T));
return (T)ser.Deserialize(stream);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这个方法可以像这样使用:
var profile = myManager.Load<Profile>("TestProfile"); // class implementing IProfile as T
Run Code Online (Sandbox Code Playgroud)
...并在此处抛出编译时错误:
var profile = myManager.Load<IProfile>("TestProfile"); // NO! IProfile interface entered!
Run Code Online (Sandbox Code Playgroud)
但是,所有内容都会编译,并且只会抛出运行时错误XmlSerializer. …
我正在从串口读取数据.数据来自规模.我现在正在使用Readline()并在删除后删除数据DiscardInBuffer().从串口读取数据的正确方法是什么?网上的例子很少,我觉得这就像是一些没有人想到的圣杯.
有什么帮助吗?
好像串口是一个反复无常的孩子.
C#,WinCE 5.0,HP瘦客户端,Compact framework 2.0
private void WeighSample()
{
this._processingDone = false;
this._workerThread = new Thread(CaptureWeight);
this._workerThread.IsBackground = true;
this._workerThread.Start();
} //end of WeighSample()
private void CaptureWeight()
{
globalCounter++;
string value = "";
while (!this._processingDone)
{
try
{
value = this._sp.ReadLine();
if (value != "")
{
if (value == "ES")
{
_sp.DiscardInBuffer();
value = "";
}
else
{
this.Invoke(this.OnDataAcquiredEvent, new object[] { value });
}
}
}
catch (TimeoutException)
{
//catch it but do …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×3
.net-3.5 ×1
attributes ×1
bulkinsert ×1
datagrid ×1
exception ×1
generics ×1
marshalling ×1
serial-port ×1
sqlite ×1
windows-ce ×1