Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I know how to use the csc program for VS to create a dll file of a class that has no user interface:

 

csc /target:library /out:"D:\My Documents\C Sharp projects\ProgramAW.dll" "D:\My Documents\C Sharp projects\Andrew.cs"

 

But how would I create a dll if it needs to hold all the information about the Form so I can just put using MyDll at the top and call a method in the dll to show and run the form?

Edited by aewarnick
C#
Posted (edited)

Here is the error I get:

 

An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll

 

Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "xForm.resources" was correctly embedded or linked into assembly "x".

baseName: xForm locationInfo: x.xForm resource file name: xForm.resources assembly: x, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

 

Here is what I did:

 

csc /target:library /out:"D:\My Documents\C Sharp projects\x.dll" "D:\My Documents\C Sharp projects\xForm.cs"

 

I put using x at top

 

The call:

xForm p=new xForm();

p.Show();

Edited by aewarnick
C#
  • *Gurus*
Posted

When you have binary resources in your form (pictures, icons etc) the command line gets more difficult. You will need to manually convert the form's .resx file in to a .resources file using the .net framework classes ResXResourceReader and ResourceWriter.

 

Then you can use the /resource command line parameter to specify each resource file to embed in the file. The filename IS important - I think it should be the root (or default) namespace of your assembly plus the form name, separated by a period.

 

Or you could purchase a non-crippled version of VS.NET which does it all for you :)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted (edited)

When I use ResourceWriter to write the .resx file to the program from the contructor before initializeComponent (I guess that would be the best place), the resx file will not be on somone elses computer and it will be looking for it, right?

 

Maybe I don't understand how this works, but there was no good documentation in help. Nothing even remotely close to what I am doing.

 

I tried adding an existing item (the resx file) from the Solution Explorer but when I try to add it, nothing happens. I thought I could just make it an embedded recource but I could not.

 

Maybe I am trying to embed it in the wrong solution. Do I embed the resx file in the same solution it comes from (which is also the files I will create the dll from), or the solution that is going to show the form?

Edited by aewarnick
C#
  • *Gurus*
Posted
The resx file is *already* embedded in your solution. VS.NET converts it to a .resources file whenever it builds the project. This conversion isn't something you do in your program, it's something you'll want to make another program to do if you're trying to build the solution from the command line.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

I hate to ask this

Would you mind giving me an example of how to do this. . .All I could find on the internet was how to do it with the non-crippled version of VS. And I don't have the money right now to go out and but it.

C#
Posted

Good news! I may not even have to use the methods you suggested after all. MS made a program that uses them called Resgen. I used it to convert the resx file to a resources file and it worked great!

 

The problem I am having is embedding the resource in the dll. Here are some of the params I wrote in csc:

Note: The namespace of this dll is Preach, and the cs file is PreachForm.cs

 

csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs"

csc /resource:"D:\My Documents\C Sharp projects\PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll"

 

 

csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs"

csc /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll"

 

 

csc /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\PreachForm.cs"

csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs"

 

 

The dll compiles fine with all of them but when I copy the dll and paste it in the program solution that it is used in (could be any) I get the same error message I got before.

C#
Posted

It never makes the dll this way:

 

csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs" /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll"

 

I cannot see the error because it closes immediately. I used a batch file to run it. How do I pause the console window so I can see the errors.

C#
Posted

Divil, I think I will take you up on that offer. . .

 

I do not like using the command line for anything! I would like to make my own program to convert resx files to .resources files. I am having trouble figuring out how to first of all, bring a resx file into my program at runtime.

 

The other problem I am having is how to save it as a .resources file to disk from the program correctly. I can do it, but it does not create if the way that resgen does and consequently, does not work.

 

This will get the .resources file to save to disk but, like I said, it does not save right:

System.Resources.ResourceManager r = new System.Resources.ResourceManager(typeof(PreachForm));
object o= r.GetObject("Preach.PreachForm.resources");
ResourceWriter R=new ResourceWriter("Preach.PreachForm.resources");
R.Generate();

I have tried many other things including the ResXResourceReader. I don't see logically how using that class could solve my problem but I tried anyway.

 

Remember, I cannot figure out how to bring a .resx file into my program at runtime to convert it to a .resources file when saving to disk.

 

If you would, please help.

C#
  • *Gurus*
Posted

Here's some old vb.net code I have to do that, I'm sure you can convert it.

 

       Dim myResEnum As IDictionaryEnumerator
       Dim objResourceWriter As ResourceWriter, objResXResourceReader As ResXResourceReader

           'Open read and write resources
           objResXResourceReader = New ResXResourceReader("myfile.resx")
           objResourceWriter = New ResourceWriter("myfile.resources")

           'Loop through
           myResEnum = objResXResourceReader.GetEnumerator()
           Do While myResEnum.MoveNext
               objResourceWriter.AddResource(myResEnum.Key.ToString(), myResEnum.Value)
           Loop

           'Close up
           objResourceWriter.Generate()
           objResourceWriter.Close()
           objResXResourceReader.Close()

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...