Sharing Code

G

Guest

Hi,

I'm trying to share code between a WCE application and a W32 application.
I've created a Solution and created 4 projects (one Windows app, one Smart
Device App - Selected as an Windows App, two Smart Device App - Selected as
Class Library).

I've developed all the WCE app without problem, but when I tryed to develop
the W32 app, I have problems after compiling the first time. The forms do not
open, and the following error apear:

"An error occurred while loading the document. Fix the error, and try
loading the document again. The error message follows:

An exception occurred while trying to create an instance of
System.Windows.Forms.Form. The exception was 'Unable to load DLL (AGL)'".

I've read some stuff about sharing code, but any of them describes this
problem. Does anyone knows what is this error and how to solve it? Am I doing
something wrong?

Thanks in advance.
 
D

Daniel Moth

You can share code with compilation constants but that doesn't work well
with forms (because the code is autogenerated for you and the resource files
are incompatible). Personally, I have different forms for the two platforms
and share the rest of the non-UI code. For some cases where the UI is
identical, you can design it in the Smart Device Project but *do not* open
the form in the desktop project.

For your specific problem, "show all files" in solution explorer, and delete
the resx file under the problematic form.

For more on sharing code between platforms read this:
http://www.danielmoth.com/Blog/2004/09/share-code-if-fullframe_17.html

Cheers
Daniel
 
G

Guest

I'm not sure if you understand my problem. I've created 2 diferent form
projects, one smart device and one desktop, but they're in the same
Solution. In this solution are another 2 srmart device projects (class
library projects).

The 2 form projects have references to this class library projects. If I
select the smart device form project as start up project I have no problem,
but if I select the desktop project as startup project, after I build the
solution, the forms do not open anymore (the message I wrote before appears).
I've read the page you've said before I started, that's why I've created 2
diferent form projects.

I've tryed to create 2 diferent solutions (one all Smart Device and one with
desktop forms ans sharing the code), but when I add the files to the desktop
solution a copy of the files is created in the solution folder, and if I
change one of the files in the smart device solution the changes do not
appear in the desktop solution.

Am I doing something wrong?

Thans for your attention,

Rafael Sancho
 
D

Daniel Moth

You are right, I didn't understand your problem. I'll try again :)

I seem to recall a problem with mixed platform projects in the same solution
but cannot locate a reference to it right now... I also think it was
VB-specific... can't remember...

Regardless... I have two solutions/projects (one per platform) and only have
one of them open at the same time. This also works best with source control.
Is there any compelling reason for wanting to keep them both open?

Not sure I understand your comment:
"a copy of the files is created in the solution folder"

Add a new file to project A. Close the solution and open project B.
i) If you have followed the instructions on my blog, the file you want to
add to project B is in the same folder as the rest of the files already in
project B. Show all files in solution explorer. You can now see the file.
Right click on it and "Include in project"
ii) Alternatively, use the Add a an existing item dialog to browse to it,
but instead of clicking "Open", pull down the menu and chose "Link to file"
(this prevents copying)

Post back if you are still having trouble...

Cheers
Daniel
 
P

Peter Foot [MVP]

I have come across what I think is the same error when referencing a device
dll project from a desktop visual basic exe project (they weren't in the
same solution).
What I found would happen is that when the device dll was built visual
studio would copy a number of compact framework assemblies into the debug or
release folder along with the dll (usually Microsoft.WindowsCE.Forms.dll and
System.Windows.Forms.dll).
In the desktop project when you add a reference to the dll, it sees these
additional dlls and sets the path up as a default reference path for the
desktop project. This means your link to System.Windows.Forms.dll now
incorrectly points to the device version. This explains the reference to AGL
because this is a namespace within the compact framework
System.Windows.Forms assembly - which has a drastically different
architecture from the desktop version.
What cured it for me was to go into the project properties for the desktop
application, manually remove the reference path, and delete the
System.Windows.Forms.dll from the output folder of the device dll project.
However occasionally it still decides to automatically change it back for me
:-(

Peter
 

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