TypeLoadException

I

inaqui.medina

Hi,

I have a mobile application that I can run perfectly in the Pocket
PC 2003 emulator and on an iPaq (PPC 2002)... but when I run it on my
new iPaq (PPC 2003) I always get:

App.exe
TypeLoadException
Couldn't load System.Windows.Forms.Form of assembly
System.Windows.Forms, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=...

Menu::Main+0x0

Or something like that (my mobile windows is in Spanish).

I have tried reinstalling the .net compact framework SP1, SP2 and
SP3 and I always get the same result.

Any ideas?
 
D

Daniel Moth

PublicKeyToken=...
You left out the most important bit. If that number starts with a B rather
than a 9 then you are referencing a desktop assembly somewhere which just
doesn't work on NETCF. The reason it works in the emulator is because you
have not updated it with any service packs (there was a bug that was hiding
this behaviour in the RTM version).

Cheers
Daniel
 
I

inaqui.medina

Well it is B:

B77A5C561934E089

So you're saying that it works on my other PPC because it is a CF with
no service pack?

I didn't create a Pocket PC project but a Windows CE project since the
later is supposed to work in both and I will need it running on CE
devices later.

Obviously getting the old CF is not the right solution... how should I
proceed?

I have a project that reads the controls in my CE app forms and does
some generic stuff... that is just a C++ class library that includes
System.Windows.Forms to work with Forms and Controls (like
TextBoxes)... should I add a different Reference? Can I not do this in
a separate dll?

Thanks a lot,

Inaquimj
 
D

Daniel Moth

I am confused. What has C++ got to do with the Compact Framework?

Make a list of each one of your projects *including* the
projects/assemblies/dlls that each one reference/use.
Each item on the list must be built/compiled against the Compact Framework.
One of your items currently isn't (instead it is built against the desktop
framework - that is not supported).

Cheers
Daniel
 
I

inaqui.medina

Sorry, I meant C#.

So project 2 (dll) was referrencing a normal framework Forms dll. I
changed it (and it changed System and System.Data for me).

Now I get the TypeLoadException later in the run. It happens when
project 2 uses project 3 (which is a wrapper for the ResourcesManager
functionallity and resource files). But I can even compile project 3
with no reference (not even to System) and in Project 2 there are only
references to other projects and CF dlls.

And always get TypeLoadException and the path (no detailed information
this time).
 
I

inaqui.medina

So the list of projects is:

Project1 (class library) references:
Project2
Project4
System
System.Data
System.Windows.Forms
(all Systems found in c:\program files\microsoft visual studio .net
2003\compactframeworksdk\v1.0.5000\windows ce\x.dll)

Project2 (class library) references:
Project4
System
System.Data
(again compactframeworksdk)

Project3 (Windows CE app) references:
Project1
MSCorLib
Project4
System
System.Data
System.Drawing
System.Web.Services
System.Windows.Forms
System.XML
(obviously CFs, including MSCoreLib.dll)

Project 4 (class library, uses satellite assemblies)
System
System.Data
(again compactframeworksdk)

Why does it still not work?
 
I

inaqui.medina

BTW when I said Project 2 uses Project 3, if you follow the project's
listing it's really Project 1 using Project 4.
 
D

Daniel Moth

I am afraid I cannot inspect all your projects to see which one is the
culprit - at least one of them is. The typical scenario is where the dev has
created a class library for the full framework rather than the compact.

Have you tried debugging with breakpoints to see which line of code causes
the problem? That may lead you to the culprit...

Cheers
Daniel
 
I

inaqui.medina

It breaks in the line where Project 1 first uses Project 4.

All the references are right so you just made me look and there is a
CFResGen (I used the normal resgen to generate the .resxs in project
4).

So that must be the problem, but if I use CFResGen I cannot compile the
project anymore:

C:\Projects\Cellfusion\Client\Resources\Files\Translations.resx
Resource transformation for file 'Translations.resx' failed. Invalid
ResX input. Could not find valid "resheader" tags for the ResX reader
& writer type names.

The generated resx headers go:

resmimetype text/microsoft-resx
version 1.3
System.Windows.Forms.Design.CFResXResourceReader, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Windows.Forms.Design.CFResXResourceWriter, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Any ideas? Do I need another reference in my project? Should I start
another thread for this?

Thanks.
 
D

Daniel Moth

Yes resx files are incompatible on the two platforms. If you identified that
resx is your problem you could do the following:
1. Using resgen generate a txt file
2. Using cfresgen take the txt file into resx
3. Use the final CF resx in your project and rebuild

Cheers
Daniel
 
I

inaqui.medina

But that is more or less what I did. I already had a txt from which I
had generated the old resxs.

I deleted those (*.resx), used my manually generated txts with CRResGen
to generate new resxs, and then rebuild.

But when I include those on my project it doesn't compile:

Invalid ResX input. Could not find valid "resheader" tags for the ResX
reader
& writer type names.
 
D

Daniel Moth

If you put a valid txt file (simple key = value pairs) through cfresgen, it
will generate a resx file that can be used in a smart device project.

So either you are not using a txt file or you are not using cfresgen's
outputs or the project is not a netcf project. If you are positive that is
not the case, post the txt file and I'll try it over here.

Cheers
Daniel
 
I

inaqui.medina

First of all thanks for all your help.

I just truncated the txt file to:

Translations.txt:
TRID000001=No. of bins
TRID000002=No. of signals

CFResGen Translations.txt Translations.resx generates:
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns=""
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string"
minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string"
minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"
msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string"
msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string"
msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string"
minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string"
use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Windows.Forms.Design.CFResXResourceReader,
System.CF.Design, Version=7.0.5000.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
<resheader name="writer">
<value>System.Windows.Forms.Design.CFResXResourceWriter,
System.CF.Design, Version=7.0.5000.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
<data name="TRID000001">
<value>No. of bins</value>
</data>
<data name="TRID000002">
<value>No. of signals</value>
</data>
</root>

This seems right to me. I believe the problem is in the project that
holds the resxs. Since I created a Class Library in VS and there is not
such thing as a "Windows CE Class Library" I guess VS cannot find
CFResXResourceWriter and I have tried adding all kind of references
from compactframework.

Should I create the project again?
 
I

inaqui.medina

I don't know what happened with my reply! Here it goes again.

I re-created all projects as I should've (as the png shows) and then
added back the .CSs and the .RESX.

The only difference is that I didn't choose "Pocket PC" but "Windows
CE" (even though I'm testing it in PPC I'll later need it running in
CE).

Whit this, everything compiles, but I'm back at the TypeLoadException
in the same place (when using the resources project).

In the resources project, other than the resx, I have a class that does
something like:

Assembly asm = Assembly.GetExecutingAssembly();
rm = new ResourceManager(asm.GetName().Name + ".Files.Translations",
asm);

and then:

rm.GetString(name);
 
I

inaqui.medina

I fixed it!

You are not going to believe what the problem was! Even recreating the
project crashed because the name of Project 4 was actually "Resources"
and there seems to be a bug in the new CF that fails to load your
project if it's called that.

I created a new one called "Library", copied CSs and REXs and now it
works!.

1000 thanks for all your help Daniel.

For everyone else with these kind of problems... 2 leasons learned:

1. Create all your mobile class libraries via "Smart Device
Application"/"Class Library".
2. Don't call your project "Resources" (don't know what other names can
be "reserved").

For the .net guys at Microsoft:
1. There should be a common core between both .nets, maybe just the
type system so I can create some "c-structs-like" classes with some
simple methods that I can use in both kind of projects. Maybe the
solution is to create two projects that point to the exact same files.
Not nice but possible?.
2. Is Resources a reserved word? If so, we need clearer errors (at
least something saying it was trying to load System.Forms.Resources or
something) and if not then it's a bug!

Daniel thanks again for your time, I could've never figured it out
without your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top