小编too*_*ive的帖子

在构建版本时,C#中的Debug.WriteLine输出到哪里?

我在我的代码中放了很多Debug.WriteLine用于调试目的.当我准备构建发布时,这些Debug.Write会影响发布版本,它们输出到哪里?

c# debugging

22
推荐指数
4
解决办法
4412
查看次数

如何在WPF中调试绑定

我有一个VS2008,C#WPF,Excel AddIn; 在某些情况下,我的插件会抛出异常

A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
A first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll
Run Code Online (Sandbox Code Playgroud)

但我找不到异常的来源.我知道这是b/c数据绑定.但无法找出原因.每次我介入时,VS都会跟踪一个执行w/o错误的方法,然后抛出异常,但不知道哪行代码.

我这几天一直在苦苦挣扎,无法取得一些进展.请帮忙.谢谢

编辑,它太长,不适合评论.所以我把xaml文件放在这里.抛出异常的@xmal文件.这是DataGridComboBoxColumn抛出异常

<UserControl x:Class="View.BasketView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" >
    <UserControl.Resources>
        <sharedC:FunctionToHiddenVisibility x:Key="enumSRToVis"/>
        <sharedC:FunctionToHiddenVisibility x:Key="enumCSToVis"/>
        <Style x:Key="DataGridRowStyle"  TargetType="{x:Type dg:DataGridRow}">
            <Style.Triggers>
                <Trigger Property="AlternationIndex" Value="1" >
                    <Setter Property="Background" Value="Beige" />
                </Trigger>
            </Style.Triggers>
            <Setter Property="AllowDrop" Value="True" />
            <Setter Property="Margin" Value="0 2 0 2" />            
        </Style>
        <Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}">
            <Setter Property="AlternationCount" Value="2" />
            <Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" />
        </Style> …
Run Code Online (Sandbox Code Playgroud)

c# debugging wpf excel add-in

21
推荐指数
2
解决办法
2万
查看次数

使用VBA和ActiveX插件时出现Excel错误406.

我的Excel插件(XLL AddIn,称之为MyAddIn)是使用C#,ExcelDNA,NetOffice,VS2010构建的.客户端有另一个插件(我们称之为B),我想它是用VBA编写的.客户说B没有工作正常MyAddIn.一旦MyAddIn安装,B失败并出现错误:

错误代码:406错误消息:无法从ActiveX DLL,ActiveX控件或属性页在此主机应用程序中显示非模态窗体.

我确实看到了这个Microsoft资源,但我不想告诉客户端Baddin需要改变.我想做点什么来避免这种情况发生在我身边.

以下是报告此问题的步骤:

  1. 安装B addin时,它不会为Microsoft创建任何注册表项Excel.
  2. MyAddin安装时,它使微软的一个注册表项Excel.
  3. 这里的注册表项基本上告诉addin应该在启动时打开Excel,所以Baddin没有启动,Excel工作正常,MyAddIn工作正常.
  4. 现在,当Baddin启动时,它会显示上面显示的406错误.
  5. 我们可以忽略错误并继续使用B插件; 禁用MyAddIn是解决方法.
  6. Baddin启动时,我们看到MyAddInBaddin 之前首先加载,然后得到406错误.
  7. 卸载时MyAddIn,不再遇到此错误,一切正常.
  8. 要删除此错误,我们尝试更改注册表顺序以使Baddin始终打开MyAddin.
    • 这是有效的,但这对微软Excel来说是一个全球变化,这意味着B即使我们只推出,插件也会一直打开Excel.这是B不可取的,因为addin然后不能让用户使用静态数据,因为Baddin保持实时刷新.这就是Baddin不在注册表设置中输入的原因.因此,注册表更改不是一种选择. …

c# vba excel-vba activex-exe excel-addins

12
推荐指数
1
解决办法
607
查看次数

C#lock(mylocker)不起作用

我有很多web服务调用(asychronous),在回调中,我将结果绘制到Excel.我想同步绘图方法.所以我使用以下内容,但是,从我在Visual Studio中跟踪,每次锁定(locker)成功,并且有许多线程运行clearcommentIfany,plot.我无法弄清楚为什么这不能按预期工作!谢谢

private readonly object locker = new object();

void ProcessPlot()
{
    lock (locker)
    {
        Debug.WriteLine("currentThreadID: " + Thread.CurrentThread.ManagedThreadId);
        //Helper.Dispatcher.Invoke(new AddClearCommentDelegate(ClearCommentIfAny));
        ClearCommentIfAny();

        if (Response.status != Status.COMPLETE)
        {
            ErrorMessage = ManipulateStatusMsg(Response);
            //Helper.Dispatcher.Invoke(new AddClearCommentDelegate(AddCommentToCell));
            AddCommentToCell();
        }
        else // COMPLETE
        {
            // TODO: Convert this into factory pattern
            Debug.WriteLine("ReportBuilder.Dispatcher's address " + Helper.GetAddress(Helper.Dispatcher));
            //Helper.Dispatcher.Invoke(new PlotDelegate(Plot), Response);
            Plot(Response);
        }               
    } 
}

public void DataRequestJobFinished(DataRequestResponse response)
{
    try
    {
        if (Request.IsRequestCancelled)
        {
            Request.FormulaCell.Dispose();
            return;
        }

        Response = response;

        //if (response.status != Status.COMPLETE)
        //{
        //    ErrorMessage …
Run Code Online (Sandbox Code Playgroud)

c# multithreading locking visual-studio-2010

9
推荐指数
1
解决办法
8866
查看次数

.NET框架兼容性:3.5 SP1和4.0客户端配置文件

我的插件需要.NET 3.5 SP1,客户端有.NET 4客户端配置文件,这还够吗?我试图找到一个图片或图表,显示.NET框架版本之间的关系.谢谢

另一种说法是,.NET 4客户端配置文件是.NET framework 35 SP1(不是.NET framework 35客户端配置文件)的超集吗?谢谢

.net frameworks

8
推荐指数
1
解决办法
3061
查看次数

更改xml序列化的输出

Web服务响应传回一个xml文件,一个元素是Date类型,其格式有时区信息,例如

12-30-2010T10:00:00+1:00

我的类有一个字段(DateTime)来接收值,但是,它只是将日期更改为本地时间.

12-30-2010T10:00:00+1:00

将被转换为

12-30-2010T02:00:00 (我当地时间是CST).

因此原始时区信息丢失了.我想要的只是忽略时区信息的时间

12-30-2010T10:00:00

或者以某种方式我可以在响应中提取时区信息,因此我可以在转换前将转换时间调整回原始时间.

任何人都知道如何在C#中做到这一点?

谢谢

c# xml serialization controls

5
推荐指数
1
解决办法
1196
查看次数

WPF 窗口在启动时抛出 TypeInitializationException

我有一个带有多个功能区的 Excel 插件,一个功能区是设置窗口。单击它时,将显示一个自定义窗口。但是,单击时没有任何显示。我在日志文件中看到以下异常。是什么原因导致这种情况以及如何解决?多谢

2012-04-09 09:59:50,161 [1] 错误助手 [(null)] - Name:TypeInitializationException
消息:“System.Windows.Window”的类型初始值设定项引发异常。
目标:Void .ctor()
堆栈:在 System.Windows.Window..ctor()
   在 MyShared.View.ConnectionSetup..ctor()
   在 MyAddIn.Connect.GetSettings()
   在 MyAddIn.Connect.BtnClick(IRibbonControl 控件)

名称:类型初始化异常
消息:“System.Windows.FrameworkElement”的类型初始值设定项引发异常。
目标:Void .cctor()
堆栈:在 System.Windows.Window..cctor()

名称:类型初始化异常
消息:“System.Windows.Documents.TextElement”的类型初始值设定项引发异常。
目标:Void .cctor()
堆栈:在 System.Windows.FrameworkElement..cctor()

名称:类型初始化异常
消息:“MS.Internal.FontCache.Util”的类型初始值设定项引发异常。
目标:Int32 get_Dpi()
堆栈:在 MS.Internal.FontCache.Util.get_Dpi()
   在 System.Windows.SystemFonts.ConvertFontHeight(Int32 高度)
   在 System.Windows.Documents.TextElement..cctor()

名称:UriFormatException
消息:无效的 URI:无法确定 URI 的格式。
目标:Void CreateThis(System.String, Boolean, System.UriKind)
堆栈:在 System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   在 System.Uri..ctor(String uriString, UriKind uriKind)
   在 MS.Internal.FontCache.Util..cctor()

编辑,这里是xaml代码

<Window x:Class="MyShared.View.ConnectionSetup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:Converter="clr-namespace:MIMICShared.Converter" 
    WindowStartupLocation="CenterOwner"
    Title="Settings" Width="446" Height="650"  Closing="WindowClosing" …
Run Code Online (Sandbox Code Playgroud)

c# wpf window visual-studio-2010 excel-addins

5
推荐指数
1
解决办法
6596
查看次数

如何为DataView设置RowFilter不区分大小写

我有一个datagrid,它的数据源是一个数据视图.有一个文本框,用户可以使用该文本框键入过滤器文本.我想使过滤器不区分大小写.比方说,输入的文字是"Tg"

我试过这个

Mydataview.RowFilter = "UPPER(COL) LIKE '%TG%'"
Run Code Online (Sandbox Code Playgroud)

但是这给了我一个无效的操作异常

然后我改成了

Mydataview.RowFilter = "COL LIKE '%tg%' or COL LIKE '%TG%'"
Run Code Online (Sandbox Code Playgroud)

这有效,但并不涵盖所有情况.例如,如果一行是"Tg",则将其过滤掉,这是不可取的.我想要的是,当用户键入"Tg"时,它将匹配任何数据与tg,Tg,TG,tG,所有组合

谢谢

c# sql dataview case-insensitive rowfilter

5
推荐指数
1
解决办法
9455
查看次数

无法在异常处理程序中捕获 JsonMappingException

我有一个用Java(Spring Boot)编写的rest api,我的请求从请求标头中获取一个json字符串(不要问为什么这样:),例如{flowerId: 123} 在我的控制器中,我将字符串映射到对象。所以当用户传入垃圾数据,例如{flowerId: abc},就会抛出JsonMappingException。我想在异常处理程序中处理异常,但无法在处理程序中捕获它。我错过了什么?谢谢

请参阅下面的我的代码。

   @RestController
    public class FlowerController  {
       @GetMapping
        @ResponseStatus(HttpStatus.OK)
        public GetFlowerResponse getFlowers(@RequestHeader(name = Constants.myHeader) String flowerIdString) throws IOException {
            GetFlowerRequest getFlowerRequest = new ObjectMapper().readValue(flowerIdString, GetFlowerRequest.class);
            //get Flower info with request ...
        }
    }


    @RestControllerAdvice
    public class ApplicationExceptionHandler {
        @ExceptionHandler(value = {JsonMappingException.class})
        @ResponseStatus(HttpStatus.BAD_REQUEST)
        public GetFlowerResponse processServletRequestBindingException(HttpServletRequest req, ServletRequestBindingException e) {
            return buildExceptionResponse(e, ErrorMessages.INVALID_REQUEST.getCode(), e.getMessage());
        }

        @ExceptionHandler(value = Exception.class)
        @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
        public GetFlowerResponse processUnhandledExceptions(HttpServletRequest req, Exception e) {
            return buildExceptionResponse(e, ErrorMessages.SERVICE_UNAVAILABLE.getCode(), ErrorMessages.SERVICE_UNAVAILABLE.getDescription());
        }
    }   

    public class GetFlowerRequest { …
Run Code Online (Sandbox Code Playgroud)

java api rest spring exceptionhandler

5
推荐指数
1
解决办法
2286
查看次数

序列化包含Dictionary的对象,使得Dictionary键/值作为包含对象的一部分呈现

我有一个课程如下:

public class Usage
{
    public string app { get; set; }

    public Dictionary<string, string> KVPs { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

当我使用这段代码时:

var json = new JavaScriptSerializer().Serialize(usage);
Run Code Online (Sandbox Code Playgroud)

它给了我这个JSON:

{"app":"myapp", "KVPs":{"k1":"v1", "k2":"v2"}}
Run Code Online (Sandbox Code Playgroud)

我想要它返回这样的东西:

{"app":"myapp", "k1":"v1", "k2":"v2"}
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点?我目前正在使用JavaScriptSerializer.如果有办法使用JSON.Net做到这一点,我愿意切换到那个.

c# serialization json dictionary json.net

4
推荐指数
1
解决办法
1万
查看次数