473,785 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assembly.LoadFr om throws PathTooLongExce ption unexpectedly.

Hi All,

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

However when I call the following, it fails:

Assembly.LoadFr om("C:\\MyDir\\ ..\\MyDir\\..\\ MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\
...\\MyDir\\..\ \MyDir\\..\\MyD ir\\..\\MyDir\\ ..\\MyDir\\..\\ MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\
MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\M yDir\\..\\MyDir \\..\\MyDir\\.. \\MyDir\\..\\My Dir\\..\\
MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\M yDir\\..\\MyDir \\..\\MyDir\\.. \\MyDir\\..\\My Dir\\..\\
MyDir\\..\\MyDi r\\MyAssembly.d ll")

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 1838
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 OptimizeFilePat h(string filePath)
{
string[] parts =
filePath.Split( System.IO.Path. DirectorySepara torChar,
System.IO.Path. DirectorySepara torChar);
Stack stack = new Stack();
foreach (string folder in parts)
{
if (folder == "" || folder == ".")
continue;
if (folder == "..")
stack.Pop();
else
stack.Push(fold er);
}

StringBuilder optimizedPath = new StringBuilder() ;
foreach (string folder in stack)
{
optimizedPath.I nsert(0, folder);
optimizedPath.I nsert(0,
System.IO.Path. DirectorySepara torChar);
}
optimizedPath.R emove(0, 1);

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

<sh********@gma il.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi All,

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

However when I call the following, it fails:

Assembly.LoadFr om("C:\\MyDir\\ ..\\MyDir\\..\\ MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\
..\\MyDir\\..\\ MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\M yDir\\..\\MyDir \\..\\MyDir\\.. \\MyDir\\..\\
MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\M yDir\\..\\MyDir \\..\\MyDir\\.. \\MyDir\\..\\My Dir\\..\\
MyDir\\..\\MyDi r\\..\\MyDir\\. .\\MyDir\\..\\M yDir\\..\\MyDir \\..\\MyDir\\.. \\MyDir\\..\\My Dir\\..\\
MyDir\\..\\MyDi r\\MyAssembly.d ll")

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********@gma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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************ *************@w i.rr.com> wrote in message
news:uI******** ******@TK2MSFTN GP10.phx.gbl...
Make sure the autogenerated path has a maximum length of 260 characters

<sh********@gma il.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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.o rg> wrote in message
news:es******** ******@TK2MSFTN GP10.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
1906
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 compares the ..dll with the cache copy. If the cache copy is older then it downloads a new copy. If the .dll is not present, it throws an error. In my main .exe, I need to early bind my "Main" form from my FormsLibrary.dll to get data into it. If...
4
2884
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 on the disk. Each plugin defines a class which implements an interface known to the app. The main app loads the plugin with Assembly.LoadFrom and then uses Assembly.GetTypes() and Type.FindInterface to find the concrete types in the plugin that...
0
1644
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 Assembly.LoadFrom(httpsite) method throws a file not found exception. I used the same code within a windows based application on the same machine and it worked, so if the windows based application can load the assembly why can't the web service find the same? I have been...
2
2165
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 is run it is offline and needs to still use that same assembly. Assembly.LoadFrom throws an exception. Cheers, Greg
3
1678
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
44489
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 = @"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\TestModule\bin\Debug\TestModule"; Assembly a = Assembly.Load(modulePath); </code>
4
4475
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 application dll). It's been working for months and now the it's not working from my application exe anymore but still working from NUnit when testing the dll. What could have changed in my exe? Some configuration thing in my VS2005 project?
7
2367
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 "Custom Attributes" by type. The output below identifies that I can catch the "DefaultMemberAttribute", but I can not catch my own "DirectoryVersionAttribute". Cany anyone throw any light on this as it is driving mad Thanks in Advance, - Paul....
0
2121
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 Win32API function:: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. My short path names are < 255 characters, but...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.