自己的TypeConverter - 仅在重新启动Visual Studio后才能工作 [英] Own TypeConverter - Only works after restart of Visual Studio

查看:61
本文介绍了自己的TypeConverter - 仅在重新启动Visual Studio后才能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

问题似乎很复杂,并且在网络控件的所有开发中

使用自己的TypeConverter。

For这里我有一个简单的问题演示程序:


控制代码:一个类MyString,它是一个类似于

的类string

[TypeConverter(typeof(MyStringTypeConverter))]

public class MyString

{

string str;

public MyString(string str){this.str = str; } $ / $

公共覆盖字符串ToString(){return str; }


公共字符串Str

{

get {return str; }

set {str = value;}

}

}


使用的typeconverter:


class MyStringTypeConverter:TypeConverter

{

public override bool CanConvertFrom(ITypeDescriptorContext context,

Type sourceType)

{

if(sourceType == typeof(string))

{return true;}

return base.CanConvertFrom(context,sourceType);

}

public override bool CanConvertTo(ITypeDescriptorContext context,

Type destinationType)

{

if(destinationType == typeof(string))

{return true;}


else if (destinationType == typeof(InstanceDescriptor))

{

返回true;

}


return base.CanConvertTo(context,destinationType);

}

公共覆盖对象ConvertFrom(ITypeDescriptorContext context,

System.Globalization.CultureInfo culture,对象价值)

{

if(value is string)

{

返回新的MyString((字符串)值);

}

返回base.ConvertFrom(context,culture,value);

}

公共覆盖对象ConvertTo(ITypeDescriptorContext context,

System.Globalization.CultureInfo文化,对象值,类型

destinationType)

{

if(destinationType == typeof) (字符串))

{

MyString cls =(MyString)value;

返回cls.ToString();

}

else if(destinationType == typeof(InstanceDescriptor))

{

ConstructorInfo ci = typeof(MyString).GetConstructor(new

键入[] {typeof(string)});

MyString cls =(MyString)value;

返回新的InstanceDescriptor(ci,new object [] {

cls.ToString()});

}

返回base.ConvertTo(context,culture,value,destinationType) ;

}

}


控制级:

[DefaultProperty(" Text")]

[ToolboxData("< {0}:TestCtrl02 runat = server>< / {0}:TestCtrl02>" )]

公共类TestCtrl02:控制

{

[Bindable(true),Category(" Appearance)),Localizable(true) ]

public MyString Text

{

get {

MyString s =(MyString)ViewState [" Text" ;];

返回((s == null)? new MyString(""):s); }


set

{ViewState [" Text"] = value; }

}


protected override void Render(HtmlTextWriter writer)

............


}


在页面中使用:

............ 。

< cc1:TestCtrl02 ID =" testCtrl" RUNAT = QUOT;服务器"文字=我的文字 >

< / cc1:TestCtrl02>

...................

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx


ok似乎很多代码,但是最短的时间才能看到问题。


问题:

该程序已编译,我们现在

启动Visual Studio。

现在,如果我们进入页面的html视图,我们会看到:

< cc1:TestCtrl02 ID =" testCtrl" RUNAT = QUOT;服务器"文字=我的文字 >

< / cc1:TestCtrl02>

现在我们更改为设计视图:

属性文本现在在属性视图下属性文本''我的文字''。

如果我们更改属性中的文本并转到html-view,一切都很好。

所以,一切正常。

现在:我们重新构建项目。没有更多。

现在我们在html-view中打开页面文件。一切都很好。

现在我们改为设计视图:错误创建控件''我的文字''不能

设置属性文本。

如果我们现在关闭Visual Studio并重新启动它,一切正常。

如果我们现在删除文本,并进行重新构建,那么我们有

< cc1:TestCtrl02 ID =" testCtrl" RUNAT = QUOT;服务器" >

< / cc1:TestCtrl02>

我们可以毫无问题地去设计视图。

如果我们现在输入文字 - property:my text我们收到错误:

属性值无效:MyString无法转换为MyString类型。

我们现在关闭Visual Studio并再次启动它同样的。

现在它工作正常。


所以当我使用TypeConverter时我知道这样的问题我觉得

以下:

重建后,从视觉工作室看不到自己的类型转换器

环境。


那么也许原因,可以解决什么问题。

使用typconverters开发网页控件并在

之后启动Visual Studio,每次重建都是不可能的。


抱歉这是很多文字,但问题是根本的,对我来说非常重要。

感谢您的帮助。

Rolf Welskes


解方案
嗨罗尔夫,


我能够重现you''ve遇到的问题。我目前正在咨询我们的产品团队,以确定这是否是一个已知问题,并且无论是否有解决方法,都需要
。感谢您的耐心和

的理解。


我发现只有在TypeConverter和客户

控制时才会出现此问题在解决方案中的另一个类库中;如果他们在

网站的App_Code目录中(当

注册客户控制时使用__ code作为程序集名称),它在重建之后正常工作

解决方案。


我会尽快回复你,谢谢你的反馈。


此致,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。如果您使用的是Outlook Express,请确保清除

复选框工具/选项/读取:一次获取300个标题及时看到你的回复




注意:MSDN托管新闻组支持服务是针对非紧急问题

其中来自社区或Microsoft支持的初步响应

工程师可在1个工作日内完成。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,也没有授予任何权利。


您好,

感谢您的回复。

我不使用Visual Web Designer,但使用Web Projects。

这意味着,我没有App_Code目录。

所以无论如何我都有错误,显然Control和TypeConvert在一个额外的控制库中是



工作一轮是非常重要的。

再次感谢你。

Rolf Welskes


" Walter Wang [MSFT]" < wa **** @ online.microsoft.comschrieb im Newsbeitrag

新闻:pm **************** @ TK2MSFTNGXA01.phx.gbl .. 。


您好Rolf,


我能够重现您遇到的问题。我目前正在咨询我们的产品团队,以确定这是否是一个已知问题,并且无论是否有解决方法,都需要
。感谢您的耐心



理解。


我发现此问题仅在TypeConverter和客户<时存在br />
控件在解决方案中的另一个类库中;如果他们在

网站的App_Code目录中(当

注册客户控制时使用__ code作为程序集名称),它在重建之后正常工作

解决方案。


我会尽快回复你,谢谢你的反馈。


此致,

Walter Wang(wa****@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。如果您使用的是Outlook Express,请确保清除

复选框工具/选项/读取:一次获取300个标题看到你的

回复

及时。


注意:MSDN管理新闻组支持服务是针对非紧急问题的/>
,可以在1个工作日内收到社区或Microsoft支持工程师的初步回复。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,也没有赋予

权利。



嗨罗尔夫,

很抱歉回复很晚。


您使用的是哪个Visual Studio版本?


我已经确认这是一个Visual Studio 2005的问题;我已经向我们的产品团队报告了这个问题。我们也鼓励您提交

反馈
http://connect.microsoft.com/Main/co...ContentID=2220 。你可以使用这个帖子作为参考。


对不起,在同一个解决方案中使用单独的类库,有

现在不知道解决方法。唯一的解决方法是使用App_Code和

__ code在同一个Web项目中使用TypeConverter

和自定义服务器控件。作为注册控件时的程序集名称。


如果您使用的是VS2005的Web应用程序项目附加组件,您还可以使用

App_Code功能。只需右键单击您的Web项目并添加添加

ASP.NET文件夹/ App_Code。


如果您使用的是Visual Studio 2003,我我已经验证了这个问题在Visual Studio 2003 SP1中不存在



非常感谢您对此问题的反馈。请告诉我

我还有什么可以帮助的。


问候,

Walter Wang(wa * ***@online.microsoft.com,删除''在线。'')

Microsoft在线社区支持


======== ==========================================

在回复帖子时,请回复群组通过你的新闻阅读器

其他人可以从你的问题中学习并从中受益。

==================== ==============================

此帖子提供按现状 ;没有保证,也没有授予任何权利。


Hello,
the problem seems to be complex and is in all developments of web-controls
which uses own TypeConverter.
For this I have here a simple demo-program of the problem:

The Control-code: A class MyString which is a class which is similar to a
string
[TypeConverter(typeof(MyStringTypeConverter))]
public class MyString
{
string str;
public MyString(string str) { this.str = str; }

public override string ToString() { return str; }

public string Str
{
get{ return str; }
set { str = value;}
}
}

the typeconverter used:

class MyStringTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{ return true;}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
if (destinationType == typeof(string))
{return true;}

else if (destinationType == typeof(InstanceDescriptor))
{
return true;
}

return base.CanConvertTo(context, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
return new MyString((string)value);
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
if (destinationType == typeof(string))
{
MyString cls = (MyString)value;
return cls.ToString();
}
else if (destinationType == typeof(InstanceDescriptor))
{
ConstructorInfo ci = typeof(MyString).GetConstructor(new
Type[] { typeof(string) });
MyString cls = (MyString)value;
return new InstanceDescriptor(ci, new object[] {
cls.ToString() });
}
return base.ConvertTo(context, culture, value, destinationType);
}
}

the control-class:
[DefaultProperty("Text")]
[ToolboxData("<{0}:TestCtrl02 runat=server></{0}:TestCtrl02>")]
public class TestCtrl02 : Control
{
[Bindable(true), Category("Appearance"),Localizable(true)]
public MyString Text
{
get{
MyString s = (MyString)ViewState["Text"];
return ((s == null) ? new MyString("") : s); }

set
{ ViewState["Text"] = value; }
}

protected override void Render(HtmlTextWriter writer)
............

}

using in a page:
.............
<cc1:TestCtrl02 ID="testCtrl" runat="server" Text="my text" >
</cc1:TestCtrl02>
...................
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx

ok seems many code, but is the shortest possible to see the problem.

The problem:
The program is compiled, we now
start Visual Studio.
Now if we go in the html-view of the page we see:
<cc1:TestCtrl02 ID="testCtrl" runat="server" Text="my text" >
</cc1:TestCtrl02>
Now we change to the design view:
the property Text now has in property view under property Text ''my text''.
If we change the text in the property and go to the html-view all is fine.
So, all works fine.
NOW: We make a RE-build of the project. Nothing more.
Now we open the page-file in html-view. All is fine.
Now we change to the design view: Error Creating Control ''my text'' cannot be
set on property Text.
If we now close Visual Studio and start it again, All works fine.
If we now delete the text, and make a RE-build, so we have
<cc1:TestCtrl02 ID="testCtrl" runat="server" >
</cc1:TestCtrl02>
we can go to design view without problems.
If we now enter in the Text-property : my text we get an error:
Property value is not valid: MyString cannot be converted to type MyString.
We now close Visual Studio and start it again and do the same.
Now it works fine.

So I know such problem allway are there when I use TypeConverter I think the
following:
After a rebuild the own type converters are not seen from the visual studio
environment.

So what maybe the reason, what can be a solution.
Developing web-controls with typconverters and to start Visual Studio after
each rebuild is impossible.

sorry it''s much text, but the problem is fundamental and very important for
me.
Thank you for any help.
Rolf Welskes


解决方案

Hi Rolf,

I was able to reproduce the issue you''ve experiencing. I''m currently
consulting with our product team to see if this is a known issue and
whether or not there would be a workaround. Thank you for your patience and
understanding.

I do find that this issue only exists when the TypeConverter and customer
control are in another class library in the solution; if they''re in
website''s App_Code directory (use "__code" as the assembly name when
registering customer control), it works correctly after rebuiding the
solution.

I will get back to you as soon as possible, thank you for your feedback.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Hello,
thank you for your response.
I do not work with Visual Web Designer, but with Web Projects.
This means, I do not have a App_Code directory.
So in any case I have the error, clearly the Control and the TypeConvert are
in an extra control-library.
It would be very important to have a work a round.
Thank you again.
Rolf Welskes

"Walter Wang [MSFT]" <wa****@online.microsoft.comschrieb im Newsbeitrag
news:pm****************@TK2MSFTNGXA01.phx.gbl...

Hi Rolf,

I was able to reproduce the issue you''ve experiencing. I''m currently
consulting with our product team to see if this is a known issue and
whether or not there would be a workaround. Thank you for your patience
and
understanding.

I do find that this issue only exists when the TypeConverter and customer
control are in another class library in the solution; if they''re in
website''s App_Code directory (use "__code" as the assembly name when
registering customer control), it works correctly after rebuiding the
solution.

I will get back to you as soon as possible, thank you for your feedback.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.



Hi Rolf,

Sorry for reply late.

Which Visual Studio version are you using?

I''ve confirmed this is an issue of Visual Studio 2005; I have reported this
problem to our product team. You are also encouraged to submit your
feedback at
http://connect.microsoft.com/Main/co...ContentID=2220. You
can use this thread as a reference.

I''m sorry that using a separate class library in the same solution, there''s
no knowing workaround now. The only workaround is to use the TypeConverter
and custom server control inside the same web project using App_Code and
"__code" as the assembly name when registering the control.

If you are using Web Application Project add-on of VS2005, you can also use
the App_Code feature. Just right-click on your Web Project and add "Add
ASP.NET folder/App_Code".

If you are using Visual Studio 2003, I''ve verified that this issue doesn''t
exist in Visual Studio 2003 SP1.

Thank you very much for your feedback on this issue. Please let me know if
there''s anything I can further help.

Regards,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于自己的TypeConverter - 仅在重新启动Visual Studio后才能工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆