using Forms in a DLL

G

Guest

I have a simple managed DLL that contains a basic cMap class. The root namespace is Map. Also in the DLL is a form for viewing it (frmViewMap), along with a toolbar, menu's and the like.

I've created a second project that will use this dll. I'm trying to inherit off of cMap (Basically adding stuff to it). I also created a new class for viewing, which inherits from frmViewMap. When I try to edit the form (to add additional buttons), I get the following error:
"An exception occured while trying to create an instance of Map.frmViewMap. The exception was "Could not find any resources appropriate for the specified culture in the given assemply. Make sure "frmViewMap.resources" was correctly enbedded or linked into assembly "Map"."

If I try to run my second project, it crashes (Unhandled exception) in InitializeComponent in frmViewMap (in the DLL), where it tries to create the image list for the toolbar:
this->ilMainToolb->ImageStream = (__try_cast<System::Windows::Forms::ImageListStreamer * >(resources->GetObject(S"ilMainToolb.ImageStream")));

If I use ildasm.exe on the DLL, and open up MANIFEST, there is a section that says: .mresource public Map.frmViewMap.resources{}. This tells me that it is being included in the DLL. There are no other classes or enums or anything being declared in the same file as frmViewMap or the class that is inheriting.

Where am I going wrong??? I've tried googling it, but I can't find my problem. I've tried several of the solutions, but so far, none of them have worked.

Thanks for any help or poiters..

GE
 
M

mphanke

Hi,

for me the problem was with the settings in Project->Properties->Managed
Resources->General->Resource File Name
The original value was
$(IntDir)/$(RootNamespace).$(SafeInputName).resources

After I changed it to
$(IntDir)/$(RootNamespace).$(InputName).resources

I had no further trouble with that.

The problem with $(SafeInputName) was it changed names like
"AppStrings.en" to "AppStringsen". This messed things up.

Hope that helps,
 
M

mphanke

Hi,

try this one:

System::Reflection::Assembly *asmP3D = this->GetType()->Assembly;
String *str[] = asmP3D->GetManifestResourceNames();

for(int i=0; i<str->Length; i++)
{
MessageBox::Show(str);
}

Check out what happens - this will show you all resource names inside
your dll. Have you tried to set the name of the resource to some fixed
value(like $(IntDir)/$(RootNamespace).Pics.resources)?

When I started with VC.NET I made the following mistake:
I named the resX-file something like myNS.Pics.resX (instead of
Pics.resX) this resulted in a name I wasn't able to load.

If this all doesn't help - my very last attempt was to create an empty
project and insert all the files again - and (for whatever reason) the
solution worked fine afterwards....


Hope this helps,

Martin Peter Hanke
 
G

Guest

Its there. But it looks like there ain't nothing in it (Which is probably why the image stream throws an exception when trying to make it).

I think I'm going to go a different route. Just don't know which one yet. This seams to me to be a rather simple problem, but either nobody else has tried doing things this way, or nobody knows the solution. Big pain in my side either way....

Thanks for your help. And good luck on your problem....

GE
 
G

Guest

I finally got mine to work (After amonth of fiddle with is). My project name was MAP, and the root namespace I was using was ROFMap (Important). So the form in question was ROFMap::frmViewMap. The second EXE (Which was inheriting from frmViewMap) was actually looking for RootNamespace.FormName.resources (ROFMAP.frmViewMap.resources). It couldn't find this, because the rootnamespace is taken from the projectname (MAP). So my second project was looking for MAP.frmViewMap.resources.

I went back and renamed my initial DLL project to ROFMap, and recompiled. Everything came up the first time (Well, after the thunderstorm messed with my puters).

For your project to work, your project name has to be TESTNS. I would change this to your project name and try again (or at least make sure the rootnamespace matches).

GE

PS> If you look in the dll, the manifest will not show exactly what resources are in it.
 
D

DotNetJunkies User

I know this thread is old but I had the same problem and I hit a bunch of boards to find the answer. I finally found the answer to my problem and thought I would share it.

Drum roll please.......The form class must be the first class defined in the form's .cs file. You can't have a helper class or enum defined before it.

More info at: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318603

Peter Thomas
 
D

DotNetJunkies User

If you think to go back and look at this, or for those of you who stumbled accros this before finding the real answer to this mysterious problem, try seeing if this article resolves your issue.

The short answer, don't put ANY time in front of your Form class in its own file. Full details in the referenced article.

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318603

Richard Grenfell
 

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