Import .ten problem.Could not load type'Project1.MyFunction'

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Import .ten problem.Could not load type'Project1.MyFunction'

Post by glikoz » Mon Jul 04, 2005 7:43 am

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.

David Berneda
Site Admin
Site Admin
Posts: 83
Joined: Wed Nov 12, 2003 5:00 am
Location: Girona, Catalonia
Contact:

Post by David Berneda » Mon Jul 04, 2005 9:28 am

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;
}

glikoz
Newbie
Newbie
Posts: 34
Joined: Mon May 05, 2003 4:00 am

Post by glikoz » Mon Jul 04, 2005 2:55 pm

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?

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Post by Marc » Tue Jul 05, 2005 11:13 am

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
Steema Support

Post Reply