|
dilkonika wrote: Why you don't just try to answer to my question I did. You did not mention the AppDomain in your original question. The approach would have been correct for most scenario's, and you could simply show your messagebox. As a warning, I'm not going to post 20 answers in this thread.
I just implemented it, using MSDN[^].
Not very useful. You can only recover if you have the full assembly. If it was there, then it should have already been found. You could only recover if you had all assemblies "twice" on the system, loading them from another location. ..and your users could have deleted them there too, so you just moved your problem to another location, while also doubling the space required.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
There is no real solution to the problem.
The problem is not how your code can recover. It's that fact that if an admin screws up the app THEY are responsible for fixing it, not you.
|
|
|
|
|
I understand that. but I don't want that my application in a such scenario to hang and to be difficult to close it. and of course I want a good messaging behavior to inform the user about what is happening.
|
|
|
|
|
dilkonika wrote: but I don't want that my application in a such scenario to hang and to be
difficult to close it. and of course I want a good messaging behavior to inform
the user about what is happening. That is done using a loader, as explained. I've used the principle before, for an app that needed certification and one of the requirements was to ensure that the files were "as expected". It should recognize "any tampering". Easy with a loader and some hashing.
dilkonika wrote: About the response , I read somewhere about If you're only interested in a single kind of solution, please add it to the starting-post. If possible, with a hyperlink! Now, since you're not going to change your mind even if I say you cannot guarantee that your backups are not equally corrupted, here's your personalized example;
- Create a NEW solution, add a console-project
- Add a class-library and call it "ClassLibrary1".
Edit the class in the classlibrary to look like below;
namespace ClassLibrary1
{
public static class Class1
{
public static string Property1 { get { return "Hello From Class1"; } }
}
} Go to the console-app, and change the Program.cs to below;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += currentAppDomain_AssemblyResolve;
externalTest();
Console.ReadLine();
}
static System.Reflection.Assembly currentAppDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Console.WriteLine("Assembly Resolve {0}", args.Name);
return AppDomain.CurrentDomain.Load(File.ReadAllBytes(@"D:\Projects\ConsoleApplication8\ClassLibrary1\bin\Debug\Copy of ClassLibrary1.dll"));
}
static void externalTest()
{
Console.WriteLine(ClassLibrary1.Class1.Property1);
}
}
}
- Change the path in the above code to your own local folder.
- Put a reference from the Console-app to ClassLibrary1.
- Build.
- Make a copy of the file "ClassLibrary1.dll", rename it to "Copy of ClassLibrary1.dll" (but keep it in that folder, otherwise you'd need to rebuild to update the folder-location in the code)
- Remove the file "ClassLibrary1.dll" from the debug-folders from BOTH projects.
- Right-click on the project, choose "Unload"
- Hit F5 key. It'll say the static linked file ain't there. Ignore it and run the last build, there's no updated code anyway.
- You'll be taken into the debugger and can see how resolving works.
DO read MSDN on the topic, as it contains some things that you will NEED. One particular warning I'd like to point out;
The event handler can return a different version of the assembly than the version that was requested.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Am working on a project, and I create this screen saver, I use streamer to display the file from note pad, and I want to use a timer so d text can randomizze, but I don't know hw to do it, the one I did is not displaying anything on the form.. I need help please..
|
|
|
|
|
|
Hi guys,
I'm trying to find a way to get the beat from an audio input (physical input on the sound card, not playing a file).
I would like something as basic as having something like a picturebox blinking to the rhythm of the music, do a show/hide or color change black/red, or any other change following the beat. From this I can find my way to do what I need.
I was thinking this could be easy but it seems to be harder than I thought
Thank you for your help.
Vince.
|
|
|
|
|
MBV-Media wrote: I was thinking this could be easy but it seems to be harder than I thought Live audio-access is rather terribly hard, and requires DirectX.
There's an example using C# here on CodeProject; VolumeMeter (Managed DirectX)[^]. Didn't find any VB-specific example though.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for the info.
I'll have a look at this example and see if I can do something with it... My C# knowledge is quite basic so I will be hard
Thank you anyway...
|
|
|
|
|
I have a vb.net 2013 project.
I have a form with a lot's of controls. Everything was working perfectly.
But at some point , I don't know what I have done , but the Form.Shown event doesn't fire anymore. The form is open correctly and everything works , except that Event.
I delete and recreated again this event , but doesn't work.
what may be the cause and what I should do to fix this ?
Thank you !
|
|
|
|
|
Do you mean it doesn't fire ever? Or only the first time the form is shown and then not fired after that
|
|
|
|
|
I mean doesn't fire ever.
|
|
|
|
|
Does your Shown event handler definitely have Handles MyBase.Shown after it?
|
|
|
|
|
Of course.
Was working before.
I think I found that the cause of the problem is this line of code in Load event :
Application.AddMessageFilter(filter1)
where filter1 is a IMessageFilter.
This filter prevent users clicking on a specific form's area when a condition is true. When I remove this line of code , the shown event is fired.
But what has to do this with a form shown ???!!! And why on other forms ( where I have also exactly this line of code ) everything is working perfectly ?
|
|
|
|
|
Post the code for your IMessageFilter implementation.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Imports System.Windows.Forms
Public Delegate Sub InsideDelegate(ByRef value As Boolean)
Public Class MyMessageFilter
Implements IMessageFilter
Public Event Inside As InsideDelegate
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Private Const WM_PAINT As Integer = &HF
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
If m.Msg = WM_PAINT Then
Return False
End If
Return OnInside()
End Function
Private Function OnInside() As Boolean
Dim _inside As Boolean = True
If InsideEvent IsNot Nothing Then
InsideEvent(_inside)
End If
Return _inside
End Function
End Class
|
|
|
|
|
So either InsideEvent is Nothing , or it's setting the parameter to True , and your IMessageFilter is cancelling every message except WM_PAINT .
You've declared constants for WM_LBUTTONDOWN and WM_LBUTTONUP ; did you intend to test for and cancel those specific messages?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
yes , I was thinking to test something before.
|
|
|
|
|
|
Yes - don't cancel every message sent to your form.
Most Windows Forms events are raised in response to window messages. If you cancel all messages being sent to the form, then you shouldn't be surprised when things stop working as expected.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry , but the filter became active only when a condition is true.
This condition became true only if the user press a button. But the user can't press a button when the form is not shown. so before the form is shown , the filter has no effect.
|
|
|
|
|
When you add the filter in the form's Load event, you prevent any further messages from being sent to the form. (As I said before, either InsideEvent is Nothing , or it's setting the parameter to True .)
That prevents the form from receiving the message telling it that it has been activated, which prevents it from raising the Shown event.
Adding a filter which prevents any window messages from being sent to your form is a very bad idea. You should not be surprised when it breaks things in interesting ways!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Private Sub filter_Inside1(ByRef value As Boolean)
value = condition1
End Sub
Dim condition1 as Boolean=false
On form's load event :
AddHandler filter1.Inside, AddressOf filter_Inside1
Application.AddMessageFilter(filter1)
As you can see at the beginning the filter is not active because the value=false.
And I repeat , that I have this scenario in all my forms , but only this form has the problem.
|
|
|
|
|
Then there's something else going on that you haven't shown us.
It's still a very bad idea to cancel all window messages for a form. Your filter should only be cancelling the specific messages that you want to block.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If it was something else , why the problem is resolved when I remove the line of code that add the filter to application ?
And just to clarify , I doesn't cancel all messages to the entire form. The condition that enable/disable the filter become true only if some other conditions are true and if the user click with mouse in some specific area.
|
|
|
|