473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Assembly.LoadFrom throws PathTooLongException unexpectedly.

Hi All,

I call Assembly.LoadFrom("C:\\MyDir\\MyAssembly.dll")- it works fine.

However when I call the following, it fails:

Assembly.LoadFrom("C:\\MyDir\\..\\MyDir\\..\\MyDir \\..\\MyDir\\..\\MyDir\\..\\MyDir\\
...\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\M yDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\ ..\\
MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\ \..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\
MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\ \..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\
MyDir\\..\\MyDir\\MyAssembly.dll")

Can someone tell me how can I get rid of it. Is there a way I can
compact the path before I pass it on to LoadFrom(string path).

Thanks,
Shrish

Feb 16 '06 #1
6 1815
Wow! Where did you get that string from?

I couldn't find anything in the framework that could help optimize this file
name, so I wrote one by myself

Here it is...

static string OptimizeFilePath(string filePath)
{
string[] parts =
filePath.Split(System.IO.Path.DirectorySeparatorCh ar,
System.IO.Path.DirectorySeparatorChar);
Stack stack = new Stack();
foreach (string folder in parts)
{
if (folder == "" || folder == ".")
continue;
if (folder == "..")
stack.Pop();
else
stack.Push(folder);
}

StringBuilder optimizedPath = new StringBuilder();
foreach (string folder in stack)
{
optimizedPath.Insert(0, folder);
optimizedPath.Insert(0,
System.IO.Path.DirectorySeparatorChar);
}
optimizedPath.Remove(0, 1);

return optimizedPath.ToString();
}
--
HTH
Stoitcho Goutsev (100)

<sh********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi All,

I call Assembly.LoadFrom("C:\\MyDir\\MyAssembly.dll")- it works fine.

However when I call the following, it fails:

Assembly.LoadFrom("C:\\MyDir\\..\\MyDir\\..\\MyDir \\..\\MyDir\\..\\MyDir\\..\\MyDir\\
..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\My Dir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\. .\\
MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\ \..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\
MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\ \..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\MyDir\\..\\
MyDir\\..\\MyDir\\MyAssembly.dll")

Can someone tell me how can I get rid of it. Is there a way I can
compact the path before I pass it on to LoadFrom(string path).

Thanks,
Shrish

Feb 16 '06 #2
Thank you very much. I am getting such long paths from some
automatically generated configuration, and therefore having the
problem.

Thanks,
Shrish

Feb 20 '06 #3
Make sure the autogenerated path has a maximum length of 260 characters

<sh********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thank you very much. I am getting such long paths from some
automatically generated configuration, and therefore having the
problem.

Thanks,
Shrish

Feb 21 '06 #4
Actually I'm not sure about that. I read somewhere that MAX_PATH counts the
length of the path in C/C++ chars where the char type is 1 byte. For .NET
one char is 2 bytes so it should be devided by 2 - 130 chars.

As I said I read this in some posting in the ng, never tried, never checked
and it could be simply not true.
--

Stoitcho Goutsev (100)
"David Levine" <Sn*************************@wi.rr.com> wrote in message
news:uI**************@TK2MSFTNGP10.phx.gbl...
Make sure the autogenerated path has a maximum length of 260 characters

<sh********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thank you very much. I am getting such long paths from some
automatically generated configuration, and therefore having the
problem.

Thanks,
Shrish


Feb 21 '06 #5
Actually I'm not sure about that. I read somewhere that MAX_PATH counts the
length of the path in C/C++ chars where the char type is 1 byte. For .NET
one char is 2 bytes so it should be devided by 2 - 130 chars.


No MAX_PATH defines the number of characters, not bytes. So it's 260
in both worlds.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 21 '06 #6
Ok. It make sense. As I said I read it and I wanted to throw it here just to
see what the others have to say about it.

It didn't sound right to me in the first place.

However MAX_PATH is a constant in the SDK header files. It has nothing to do
with the reality. In NTFS the names could be big times longer than 260
characters. I don't know why this limit. I mean I know but it doesn't make
sense in .NET except that it uses the uderlying API.
--

Stoitcho Goutsev (100)

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
Actually I'm not sure about that. I read somewhere that MAX_PATH counts
the
length of the path in C/C++ chars where the char type is 1 byte. For .NET
one char is 2 bytes so it should be devided by 2 - 130 chars.


No MAX_PATH defines the number of characters, not bytes. So it's 260
in both worlds.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Feb 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brent | last post by:
I maintain a Sql Server database application whose forms are compiled in a .dll and kept in a remote web folder. The main .exe looks to the web folder to see if this .dll exists. If so, then it...
4
by: Arnaud Debaene | last post by:
Hello group. I have an app which can load "plugins" assemblies that are described in the registry (each registry entry gives the full path to the plugin ..dll file). The plugins may be anywhere...
0
by: surya | last post by:
Hi, I am using Assembly.LoadFrom within a web service to load assemblies from a web site. This web site is in the same machine where I am running the web service. The...
2
by: Greg Bacchus | last post by:
Hi, Does anyone know how to get an offline reference to an assembly that has been downloaded using Assembly.LoadFrom. E.g. Application downloads the assembly while it in online... next time it...
3
by: Boni | last post by:
Dear Sirs, If I dynamically load assembly into the memory by Load(byte) how long do I have to preserve the array valid? Can it be destructed just after the load call? Thanks in advance, Boni
6
by: Steve | last post by:
I'm playing with late binding and trying a very simple test to load an assembly In my "Host" application I have this code: <code> string modulePath =...
4
by: =?Utf-8?B?SmFu?= | last post by:
I have a .NET 2.0 application divided in two assemblies; the exe and a dll. The application generates a plugin-dll which is then loaded in a separate AppDomain (along with a second instance of my...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
0
by: mjheitland | last post by:
When I pass my directories recursively on a directory structure with paths 260 chars I get the following exception (see line marked with ***), although I am using only ShortPathNames through...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.