471,119 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

application won't start if needed assembly is missing...

Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the app
could tell me which assemblies are missing instead of not starting at all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck
Apr 4 '07 #1
18 2240
You can add an unhandled exception handling code block that logs this
information appropriately. Here is some background info:
http://www.eggheadcafe.com/articles/20051205.asp
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Rainer Queck" wrote:
Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the app
could tell me which assemblies are missing instead of not starting at all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck
Apr 4 '07 #2
You can subscribe to the static AssemblyResolve event which is raised
when an assembly is not found.

AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(AssemblyResolver);
public static Assembly AssemblyResolver(object sender,
System.ResolveEventArgs e)
{
MessageBox.Show(e.Name);
return null;
}

=====================
Clay Burch
Syncfusion, Inc.
Apr 4 '07 #3
Hi Clay,

thanks for your hint, but it does not work here.

I added the following code to my "program.cs" but the message box never
shows....
Is there something I am doing wrong?

Regards
Rainer

static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;
....
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object
sender, ResolveEventArgs args)
{
MessageBox.Show(String.Format("Assembly {0} is missing", args.Name));
return null;
}
"ClayB" <cl***@syncfusion.comschrieb im Newsbeitrag
news:11**********************@n59g2000hsh.googlegr oups.com...
You can subscribe to the static AssemblyResolve event which is raised
when an assembly is not found.

AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(AssemblyResolver);
public static Assembly AssemblyResolver(object sender,
System.ResolveEventArgs e)
{
MessageBox.Show(e.Name);
return null;
}

=====================
Clay Burch
Syncfusion, Inc.

Apr 4 '07 #4
Hi Peter,

thanks for your hints.

I read the article, and tried the differen illustarated ways, but somehow I
get no MessageBoxes to show on the different ways.
Same like answert to Clay's hint.

Is there "some setting" I have to make to get these things working?

Regards
Rainer Queck

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschrieb im
Newsbeitrag news:16**********************************@microsof t.com...
You can add an unhandled exception handling code block that logs this
information appropriately. Here is some background info:
http://www.eggheadcafe.com/articles/20051205.asp
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Rainer Queck" wrote:
>Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the
app
could tell me which assemblies are missing instead of not starting at
all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck

Apr 4 '07 #5
Rainer,

While Peter and Clay are giving you good suggestions, I would like to
suggest that you take a higher-level view on the whole issue. A question
that you should be asking yourself is if you have a large number of dlls
that you need to distribute, why aren't you using an installer? Obviously,
this is not a matter of a lone exe, but something a little more complex.

Why not just have an installer which will guarantee that the assemblies
be there? Better yet, why not use a ClickOnce setup which will make sure
that all the assemblies in your program are there?

The best code you will write is the code you never have to write, and I
see you coding a number of things you don't have to when there are tools out
there which will do what you want (installation package tools and
ClickOnce).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the
app could tell me which assemblies are missing instead of not starting at
all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck

Apr 4 '07 #6
Hi Nicholas,

I fully see the point, that a Installer would solve my current problem, but
my application goes into a "company installation" for a productive system,
where a Installer can not be used. Therefore I have to provide my project as
a set of folders and files.

Regards
Rainer

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comschrieb
im Newsbeitrag news:O1**************@TK2MSFTNGP06.phx.gbl...
Rainer,

While Peter and Clay are giving you good suggestions, I would like to
suggest that you take a higher-level view on the whole issue. A question
that you should be asking yourself is if you have a large number of dlls
that you need to distribute, why aren't you using an installer?
Obviously, this is not a matter of a lone exe, but something a little more
complex.

Why not just have an installer which will guarantee that the assemblies
be there? Better yet, why not use a ClickOnce setup which will make sure
that all the assemblies in your program are there?

The best code you will write is the code you never have to write, and I
see you coding a number of things you don't have to when there are tools
out there which will do what you want (installation package tools and
ClickOnce).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the
app could tell me which assemblies are missing instead of not starting at
all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck



Apr 4 '07 #7
Rainer,

I would still question the approach. This is the whole point of merge
files. You can create the merge file which will install your
components/exe, and then it can be included in a larger install project
(assuming you are using Windows Installer technology, or pretty much any
other installer technology out there which will leverage the Windows
Installer file formats).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:Ox**************@TK2MSFTNGP03.phx.gbl...
Hi Nicholas,

I fully see the point, that a Installer would solve my current problem,
but my application goes into a "company installation" for a productive
system, where a Installer can not be used. Therefore I have to provide my
project as a set of folders and files.

Regards
Rainer

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comschrieb
im Newsbeitrag news:O1**************@TK2MSFTNGP06.phx.gbl...
>Rainer,

While Peter and Clay are giving you good suggestions, I would like to
suggest that you take a higher-level view on the whole issue. A question
that you should be asking yourself is if you have a large number of dlls
that you need to distribute, why aren't you using an installer?
Obviously, this is not a matter of a lone exe, but something a little
more complex.

Why not just have an installer which will guarantee that the
assemblies be there? Better yet, why not use a ClickOnce setup which
will make sure that all the assemblies in your program are there?

The best code you will write is the code you never have to write, and
I see you coding a number of things you don't have to when there are
tools out there which will do what you want (installation package tools
and ClickOnce).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the
app could tell me which assemblies are missing instead of not starting
at all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck




Apr 4 '07 #8
Rainer,
Nick is absolutely right. Even in the situation where your company cannot
use an MSI installer or merge module, you can still create an installer for
your project that will ensure that all dependencies are present, perform an
install locally, and then provide your company with the resultant folder and
files.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Rainer Queck" wrote:
Hi Nicholas,

I fully see the point, that a Installer would solve my current problem, but
my application goes into a "company installation" for a productive system,
where a Installer can not be used. Therefore I have to provide my project as
a set of folders and files.

Regards
Rainer

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comschrieb
im Newsbeitrag news:O1**************@TK2MSFTNGP06.phx.gbl...
Rainer,

While Peter and Clay are giving you good suggestions, I would like to
suggest that you take a higher-level view on the whole issue. A question
that you should be asking yourself is if you have a large number of dlls
that you need to distribute, why aren't you using an installer?
Obviously, this is not a matter of a lone exe, but something a little more
complex.

Why not just have an installer which will guarantee that the assemblies
be there? Better yet, why not use a ClickOnce setup which will make sure
that all the assemblies in your program are there?

The best code you will write is the code you never have to write, and I
see you coding a number of things you don't have to when there are tools
out there which will do what you want (installation package tools and
ClickOnce).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hello NG,

I realized, that my application won't start, if a referenced assembly is
missing.
Basically this is understandable, but since I destribute my applictaion
without a setup, it can happen that I forget one or the other .dll.

Since my app depends on a whole bunch of .dll it would be great, if the
app could tell me which assemblies are missing instead of not starting at
all.

Is there a way to achieve this desired behaviour?

Regards
Rainer Queck


Apr 4 '07 #9
Hi Rainer,

AppDomain.AssemblyResolve will be fired when the resolution of an assembly
fails, that is when your application is missing any assembly. Note: .Net is
using delay assembly loading style, so if your main Exe is linking with
some class library assembly but did not use it yet, the .Net loader will
not try to resolve and load it yet. Below is a sample to demonstrate this:

//class library assembly
namespace ClassLibrary1
{
public class Class1
{
public static int Add(int a, int b)
{
return a + b;
}
}
}

//I created a .Net Winform project
//and use this class library assembly
//in the Button.Click event
private void button1_Click(object sender, EventArgs e)
{
ClassLibrary1.Class1.Add(3, 4);
}

[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}

static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object
sender, ResolveEventArgs args)
{
MessageBox.Show(String.Format("Assembly {0} is missing", args.Name));
return null;
}

After I deleted the ClassLibrary1.dll in the Exe folder, I double-click the
exe to launch the application. Everything works well, the
CurrentDomain_AssemblyResolve is not fired. Then, when I click the button
in the form, the CurrentDomain_AssemblyResolve is fired and the CLR is
asking you for *help* to find the missing assembly.

You may give this a test to see if the behavior is consistent.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 5 '07 #10
Hi Peter,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschrieb im
Newsbeitrag news:BD**********************************@microsof t.com...
Rainer,
Nick is absolutely right. Even in the situation where your company cannot
use an MSI installer or merge module, you can still create an installer
for
your project that will ensure that all dependencies are present, perform
an
install locally, and then provide your company with the resultant folder
and
files.
Actualy this is exactly what I am doing at the moment. The only unnice point
is, that in my controlpanel / software I have a Installed sofware wich I
don't really have installed. This is no problem, it just bothers me for some
unexplainable reason ;-)

Rainer
Apr 5 '07 #11
Hi Jeffrey,

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comschrieb im Newsbeitrag
news:cW**************@TK2MSFTNGHUB02.phx.gbl...
Hi Rainer,

AppDomain.AssemblyResolve will be fired when the resolution of an assembly
fails, that is when your application is missing any assembly. Note: .Net
is
using delay assembly loading style, so if your main Exe is linking with
some class library assembly but did not use it yet, the .Net loader will
not try to resolve and load it yet.
actually this is the situation I have, still I don't get the event.

static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;
// Start Diagnose
ReportSettings reporterSettings = new ReportSettings();
FileDiagnose.Instance.DiagDir =
Helpers.PathWithBackSlash(reporterSettings.DiagDir , true);
....
}

FileDiagnose and Helpers are classes, locate in seperate dll, which for
testing I deleted.
Still the event is not fired.

Regards
Rainer
Apr 5 '07 #12
Try doing the install from within your solution by right-clicking on the
Setup project and choosing "Install". You can then copy the target folder and
contents somewhere else. Then right- click again and choose "uninstall". Now
you have your "stuff" and the entry in Control Panel Add/Remove will be gone.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Rainer Queck" wrote:
Hi Peter,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschrieb im
Newsbeitrag news:BD**********************************@microsof t.com...
Rainer,
Nick is absolutely right. Even in the situation where your company cannot
use an MSI installer or merge module, you can still create an installer
for
your project that will ensure that all dependencies are present, perform
an
install locally, and then provide your company with the resultant folder
and
files.
Actualy this is exactly what I am doing at the moment. The only unnice point
is, that in my controlpanel / software I have a Installed sofware wich I
don't really have installed. This is no problem, it just bothers me for some
unexplainable reason ;-)

Rainer
Apr 5 '07 #13
Hi Peter,

"Peter Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comschrieb im
Newsbeitrag news:25**********************************@microsof t.com...
Try doing the install from within your solution by right-clicking on the
Setup project and choosing "Install". You can then copy the target folder
and
contents somewhere else. Then right- click again and choose "uninstall".
Now
you have your "stuff" and the entry in Control Panel Add/Remove will be
gone.
Thanks for this hint!
That is the way I will do it from now on.

Regards
Rainer
Apr 5 '07 #14
Hi Rainer,

Thanks for your feedback.

This looks a bit strange. Have you tried this in a little sample project?
This test will help to identify if this problem is this project specific.
If this problem can be reproduced in a little sample project, please feel
free to send to me at je***@online.microsoft.com(remove "online.").
Furthermore, if you need my working sample project, please feel free to
tell me, thanks.

If you want to get Peter Bromberg's unhandled exception filter solution
work, you may also demonstrates the problem in the sample project, I will
help to give it a troubleshoot. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 6 '07 #15
Rainer,

I think the problem you are having is that you are trying to use the reference in the same spot you are trying to trap the error. It fires the event as soon as it starts to load Main (because the missing reference is used there). As a test, put the code calling the dll in another function/sub/whateveryoucallthem in C#, and then call that from main. Or, rename Main as something else and create a new Main to handle these errors.

For example (forgive my C# syntax, I don't code much in it):

static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;
// Start Diagnose
oldmain();
}

static void oldMain()
{
// Start Diagnose
ReportSettings reporterSettings = new ReportSettings();
FileDiagnose.Instance.DiagDir =
Helpers.PathWithBackSlash(reporterSettings.DiagDir , true);
.....
}

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Apr 9 '07 #16
Hi Derek,

Sorry, that I did not respond so long time, but I had to switch to a
different project, and forgot about this thread. Now, back to this project,
I memorized my problem, and checked the NG, finding your Hint. It looks like
you are absolutely right! With the way you described, the event gets fired.

Thanks for your help!
Rainer

<Derekschrieb im Newsbeitrag news:20******************@davenport.edu...
I think the problem you are having is that you are trying to use the
reference in the same spot you are trying to trap the error. It fires the
event as soon as it starts to load Main (because the missing reference is
used there). As a test, put the code calling the dll in another
function/sub/whateveryoucallthem in C#, and then call that from main. Or,
rename Main as something else and create a new Main to handle these
errors.

For example (forgive my C# syntax, I don't code much in it):

static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += new
ResolveEventHandler(CurrentDomain_AssemblyResolve) ;
// Start Diagnose
oldmain();
}

static void oldMain()
{
// Start Diagnose
ReportSettings reporterSettings = new ReportSettings();
FileDiagnose.Instance.DiagDir =
Helpers.PathWithBackSlash(reporterSettings.DiagDir , true);
....
}

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com

May 3 '07 #17
Hello Jeffrey,

Sorry for not responding to your offer that long time, but I had to switch
to a different project and there fore did not monitor my thread for a while.
Now beeing back, I found the time to continue work on my problem again.

Derek (see his answer to the thread on 9th April) found the reason for my
problem. With is workaround, the event gets fired.

Thanks for your offer, but I up to now was not able to reproduce the problem
in a little demo project.
Anyhow, I have my workaround :-)

Regards
Rainer Queck
May 3 '07 #18
Hi Rainer,

Glad to see Derek's reply can help you. If you need further help, please
feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
May 7 '07 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Serge calderara | last post: by
7 posts views Thread by Joshua Sprague | last post: by
12 posts views Thread by ORC | last post: by
6 posts views Thread by Charles Neitzel | last post: by
5 posts views Thread by Josef Brunner | last post: by
17 posts views Thread by =?Utf-8?B?RGF2ZQ==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.