0

Solution: I had to click "Unblock" in the file properties dialog in Windows Explorer.

I made an app in c# because i thought it will work on all windows versions. Today i was at my fathers place and downloaded my precompiled app from github. It was running but totally not as expected! Highlighted rows in a gridview wasnt visible, scollbars on a tabcontrol wasnt working and some other more or less small bugs. I had no time to download visual studio to recompile it but is this usual behavior? My father is running on windows 7 and i saw .NET framework 4.5 was installed - i compiled my app using v4.0 so i thought there should be no compatibility issues. I also created a Windows10 virtual machine at home after that and recognized it was the same behavior. I know highlighted rows or scrollbars are not that important but i also have a plugin system to load and reflect additional libraries and thats a basic feature of my app. And the assembly loader will NOT work either - just on the machine i have compiled on.

Should i compile it on multiple versions to support any "unknown" user and its operationg system? I saw that microsoft say i can determine the users version using https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed but i can do it after my app is installed so should i create some downloader to download the correct version after installation or how is this meant?

Edit i uploaded a video on youtube to show how it should work and how it accuaally works.. https://www.youtube.com/watch?v=DTQa8WlECa8

Edit I got an error message stating (translated from native german) "It was tried to load an assembly from a network address" but i dont understand this message, i never do so.. I load assemblies using

    private void m_btnRegisterModule_Click(object objectSender, EventArgs eventArgs)
    {
        OpenFileDialog openFileDialog = new OpenFileDialog();
        openFileDialog.Multiselect = true;
        openFileDialog.Title = "Register Stack";
        openFileDialog.Filter = "Assemblies (*.exe, *.dll)|*.exe;*.dll|All Files (*.*)|*.*";
        if (openFileDialog.ShowDialog(this) == DialogResult.Cancel) return;
        Assembly assembly = null;
        foreach (String file in openFileDialog.FileNames)
        {
            try
            {
                assembly = System.Reflection.Assembly.LoadFile(file);
            } catch (Exception) { return; }
            Type[] arrayTypes = assembly.GetExportedTypes();
            foreach (Type type in arrayTypes)
            {
                if (!typeof(ScriptStack.Runtime.Stack).IsAssignableFrom(type)) continue;
                ConstructorInfo constructorInfo = null;
                try
                {
                    constructorInfo = type.GetConstructor(new Type[0]);
                }
                catch (Exception) { continue; }
                try
                {
                    object objectHostModule = constructorInfo.Invoke(new object[0]);
                    ScriptStack.Runtime.Stack hostModule = (ScriptStack.Runtime.Stack)objectHostModule;
                    m_scriptManager.RegisterHostStack(hostModule);
                }
                catch (Exception) { continue; }
            }
        }
        UpdateModuleControl();
        pluginFilter.Select();
    }

I found .net local assembly load failed with CAS policy and try to load it.. otherwise. lets see how. For now i created a messagebox to see the exact exception.

Edit Solution: I had to click "Unblock" in the file properties dialog in Windows Explorer.

banner
  • 69
  • 1
  • 8
  • 1
    Would it be possible to share some code - how you are loading assemblies and is it not loading all assemblies or just assemblies compiled on your machine? Assemblies usually cannot be loaded for reflection if their dependencies are not found or loaded (some exceptions are there). – mbshambharkar Feb 13 '20 at 05:26
  • Did you retrieve the entire bin folder and run and not just the exe? – Allanckw Feb 13 '20 at 05:36
  • @Alander what do you mean "entire bin folder"? I **ship** whats needed exe and dll, of course not the pdb files. – banner Feb 13 '20 at 05:49
  • @Alander maybe you will take a look at the video i made – banner Feb 13 '20 at 05:55
  • @mbshambharkar i updated my question it really seems to be the loading.. it states i tried to load an assembly from a network address..but i dont! – banner Feb 13 '20 at 06:02
  • @banner..if you look at the loadComponents method it is trying to load assemblies by Assembly.LoadFile(dll). This is where dependencies comes in and it is possible the plugin you are using may be trying to load assembly from network itself or ScriptStack is doing itself. Possible solution is to identify the dependencies and place in bin folder . – mbshambharkar Feb 13 '20 at 06:13
  • This is MY source code, there are no dependencies! Now i got the error message that the filepath is not supported?! File paths are the same regardless which windows version am i right? The host application loads assemblies, plugins doesnt - they are assemblies without dependencies except System.*. If you want and have time i could send you the source code but its quite large - all in all about ~10000 lines – banner Feb 13 '20 at 06:36
  • I could also just send you just the neccessary stuff but i think the links shows all of them. By "loading from network" - do you mean like NuGet or that i have coded something to do so? – banner Feb 13 '20 at 06:42
  • Lol, I just needed to click "Unblock" in the file properties dialog in Windows Explorer.. – banner Feb 13 '20 at 07:17
  • If you go the solution, please add it as an answer. – Sin Feb 13 '20 at 07:21

1 Answers1

0

Clicking "Unblock" in the file properties dialog in Windows Explorer solved my issue in some way. By "in some way" i mean i cant expect everybody to know this so someone will just think its not working crap and drop the app.. i guess

banner
  • 69
  • 1
  • 8
  • 1
    check whether an assembly is blocked https://stackoverflow.com/questions/6374673/ or support loading blocked assemblies https://through-the-interface.typepad.com/through_the_interface/2011/07/loading-blocked-and-network-hosted-assemblies-with-net-4.html – devio Feb 13 '20 at 08:18