Can not Load .dll file

Can not Load .dll file

a.kouchakzadeh
Advocate Advocate
7,069 Views
10 Replies
Message 1 of 11

Can not Load .dll file

a.kouchakzadeh
Advocate
Advocate

Hello world.

I need help in loading a dll file created in .net

it loads perfectly fine in my computer but when I send it to others, they get this error message:

 

Command: NETLOAD
Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\hesam\Downloads\2021\12-Dec\RibbonSample.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\hesam\Downloads\2021\12-Dec\RibbonSample.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()

 

 

I even suggested others trying to load my dll to install objectARX from Autodesk but still not working.

I also gave them the whole folder so if they application needs anything from that folder it can access it, but no luck with that.

how ever it does load from my computer.

 

Edit: Happy new year

0 Likes
Accepted solutions (1)
7,070 Views
10 Replies
Replies (10)
Message 2 of 11

a.kouchakzadeh
Advocate
Advocate

I found the solution.

I just had to right click on the file, in properties/general, I had to check mark the trust file.

but how can I make it a trustable file for others without making them freak them out.

Message 3 of 11

norman.yuan
Mentor
Mentor
Accepted solution

Where did you get the dll file? If you downloaded from somewhere from the internet, then this is a Windows OS security feature: if an executable file (exe/dll, zipped or not) is downloaded/transferred to the computer from the Internet, Windows automatically flags it as unsafe, and locks it up.

 

If you created the dll by yourself (with VS),  place it on a network drive and try to load it there, then you need to configure .NET framework to allow the DLL to be loaded from a drive outside the computer as the Miscrosoft's link indicated.

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 11

mgorecki
Collaborator
Collaborator

Hi Norman,

I am getting the same error.  The strange part is that for years we've been running the .DLL's from the network with no problem.  Recently we all went to new laptops and they're running Windows 11.

I've checked the link, but I'm a bit ignorant on where to find, or add the "loadFromRemoteSources"

 

They also have a Note which reads:  In the .NET Framework 4.5, assemblies on local network shares are run as full trust by default; you do not have to enable the <loadFromRemoteSources> element.

My Visual Studio by default is set to 4.6.1, so I would think this wouldn't be an issue.

 

Thanks for any info.

0 Likes
Message 5 of 11

norman.yuan
Mentor
Mentor

"loadFromRemoteSources" is to be added into acad.exe.config, if you have to use it.

 

Now that the MS document says "In the .NET Framework 4.5 and later versions, assemblies on local network shares run in full trust by default; you do not have to enable the <loadFromRemoteSources> element.", then you have to decide how/why you get the same error. Or is the error really the same? Have you tried to manually NETLOAD the same DLL both from local drive, and from networkshare? I had experience that the CAD plugin DLL was sent to users through large corporate network across half world, then Windows somehow think the DLL is downloaded from the Internet and flagged it as unsafe. So, the so called Local Network can be tricky to be recognized as real "Local".

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 11

mgorecki
Collaborator
Collaborator

Hi Norman,

Thank you for such a quick reply.

This is the error I get:

Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'file:///L:\AutoCAD\VB_Net\FlipChip_POD_Creator_2018-DB.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///L:\AutoCAD\VB_Net\FlipChip_POD_Creator_2018-DB.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

I copied the .dll from the network and saved it locally.  If I start AutoCad and load the local one, it runs just fine.  I get the error when I load the one from the network.

I have a feeling the security people did something.

 

Best regards,

Mark

 

 

0 Likes
Message 7 of 11

mgorecki
Collaborator
Collaborator

Norman, as always you are awesome!!!!

I added the commands to the acad.exe.config and it works great.

 

Thanks you very much!!

 

Best regards

0 Likes
Message 8 of 11

subash.nalla
Enthusiast
Enthusiast

Hi please see the attached image and correct me if am wrong for the issue.

0 Likes
Message 9 of 11

Yehoshua18
Enthusiast
Enthusiast

How do you go about unblocking a DLL sourced from a network folder if that option is not available in the DLL properties once it's been moved to a local folder?

 

Thanks!

0 Likes
Message 10 of 11

gleeuwdrent
Advocate
Advocate

I have created my own DLL loader which programmatically unblocks the dll:

object persistZoneId = Activator.CreateInstance(Type.GetTypeFromCLSID(Guid.Parse("0968e258-16c7-4dba-aa86-462dd61e31a3")));
IZoneIdentifier zoneIdentifier = (IZoneIdentifier)persistZoneId;
IPersistFile persisteFile = (IPersistFile)persistZoneId;
zoneIdentifier.SetId(URLZONE.URLZONE_TRUSTED);
persisteFile.Save(filename, false);
0 Likes
Message 11 of 11

songmaverick
Contributor
Contributor

Thank you very much!!!

It is important to trust the file!!!

0 Likes