I have a MyFunction class that derives from Function class...I could save tchart instance (including MyFunction) correctly but when i tried to import it i got an exception like that :
{"Could not load type 'Project1.MyFunction' from assembly 'TeeChart, Version=2.0.1938.29194, Culture=neutral, PublicKeyToken=9c8126276c77bdb7'.":"Project1.MyFunction"}
I could understand import functions (like LoadFileDilaog) use Reflection NameSpace ..But i couldnt find any information to add mynamespace to LoadFileDialog's target ..Can I use standard Import-Export library with my custom Functions or I have to write my custom import-export functions.
Import .ten problem.Could not load type'Project1.MyFunction'
-
- Site Admin
- Posts: 83
- Joined: Wed Nov 12, 2003 5:00 am
- Location: Girona, Catalonia
- Contact:
I guess the deserialization of the .ten file is not locating your "MyFunction" class.
Our internal "find type" method looks all around trying to find the class (see below the source code of our "find type"), but it seems it might not be enough.
Are you using TeeChart.Net v2 ? In v2 we have introduced a new interface to allow customization of serialization and deserialization of custom classes:
namespace Steema.TeeChart.Export
{
...
public sealed class TemplateExport : ExportFormat
{
public interface ICustomSerialization
{
void Serialize(SerializationInfo info);
void DeSerialize(SerializationInfo info);
}
...
}
...
}
If you add "ICustomSerialization" to your "MyFunction" class, then you can override the DeSerialize method and do your custom deserialization, something like:
foreach (SerializationEntry e in info) {
if (e.value.tostring="MyFunction") { ...add a new function... }
}
-----------
regards
david
private Type FindType(string typeName)
{
Type result=InternalFindType(typeName,GetType().Assembly);
if (result==null)
result=InternalFindType(typeName,Assembly.GetExecutingAssembly());
if (result==null)
result=InternalFindType(typeName,Assembly.GetEntryAssembly());
if (result==null)
{
foreach (AssemblyName a in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
Type result2=InternalFindType(typeName,Assembly.Load(a));
if (result2!=null)
return result2;
}
return null;
}
else return result;
}
Our internal "find type" method looks all around trying to find the class (see below the source code of our "find type"), but it seems it might not be enough.
Are you using TeeChart.Net v2 ? In v2 we have introduced a new interface to allow customization of serialization and deserialization of custom classes:
namespace Steema.TeeChart.Export
{
...
public sealed class TemplateExport : ExportFormat
{
public interface ICustomSerialization
{
void Serialize(SerializationInfo info);
void DeSerialize(SerializationInfo info);
}
...
}
...
}
If you add "ICustomSerialization" to your "MyFunction" class, then you can override the DeSerialize method and do your custom deserialization, something like:
foreach (SerializationEntry e in info) {
if (e.value.tostring="MyFunction") { ...add a new function... }
}
-----------
regards
david
private Type FindType(string typeName)
{
Type result=InternalFindType(typeName,GetType().Assembly);
if (result==null)
result=InternalFindType(typeName,Assembly.GetExecutingAssembly());
if (result==null)
result=InternalFindType(typeName,Assembly.GetEntryAssembly());
if (result==null)
{
foreach (AssemblyName a in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
{
Type result2=InternalFindType(typeName,Assembly.Load(a));
if (result2!=null)
return result2;
}
return null;
}
else return result;
}
Yes ,Im using TeeChart v2..
TChart instance is imported by tChart1.Import.Template.LoadFileDialog() ..
I used ICustomSerialization as you said :
public class MyFunction : Function, TemplateExport.ICustomSerialization
{
#region ICustomSerialization Members
public void DeSerialize(SerializationInfo info)
{
foreach (SerializationEntry e in info)
{
if (e.Value.ToString() == "MyFunction") { int a = 2; }
// BREAKPOINT
}
}
public void Serialize(SerializationInfo info)
{
foreach (SerializationEntry e in info)
{
}
}
#endregion
}
But i couldnt reach Breakpoint line ..I got Error message :
{"Exception has been thrown by the target of an invocation."}
{"Could not load type 'Program1.MyFunction' from assembly 'TeeChart, Version=2.0.1938.29194, Culture=neutral, PublicKeyToken=9c8126276c77bdb7'.":"Program1.MyFunction"}
Is there any key point i missed?
TChart instance is imported by tChart1.Import.Template.LoadFileDialog() ..
I used ICustomSerialization as you said :
public class MyFunction : Function, TemplateExport.ICustomSerialization
{
#region ICustomSerialization Members
public void DeSerialize(SerializationInfo info)
{
foreach (SerializationEntry e in info)
{
if (e.Value.ToString() == "MyFunction") { int a = 2; }
// BREAKPOINT
}
}
public void Serialize(SerializationInfo info)
{
foreach (SerializationEntry e in info)
{
}
}
#endregion
}
But i couldnt reach Breakpoint line ..I got Error message :
{"Exception has been thrown by the target of an invocation."}
{"Could not load type 'Program1.MyFunction' from assembly 'TeeChart, Version=2.0.1938.29194, Culture=neutral, PublicKeyToken=9c8126276c77bdb7'.":"Program1.MyFunction"}
Is there any key point i missed?
Hello,
I've just tried to reproduce the steps you describe. There is a bug here. The issue appears to be 'Function' ancestry specific due to the way TeeChart internally tries to resolve the type 'Function', however we'll work the case through for a fuller look.
Apologies for the inconvenience and thanks for letting us know. We'll process a fix as soon as possible to be included in the next maintenance release.
Regards,
Marc Meumann
I've just tried to reproduce the steps you describe. There is a bug here. The issue appears to be 'Function' ancestry specific due to the way TeeChart internally tries to resolve the type 'Function', however we'll work the case through for a fuller look.
Apologies for the inconvenience and thanks for letting us know. We'll process a fix as soon as possible to be included in the next maintenance release.
Regards,
Marc Meumann
Steema Support