474,042 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FileNotFoundExc eption question

Hello,

Let me explain my situation. There is an application in C++ (that I didn't
write) that needs to call a C# DLL. One option, I believe, would be to
compile the app with the clr switch. Rather than do that first the other
developer wondered if I could create an intermediate managed code DLL that
would call my C# code.

So, I created a C++ DLL that exports a function and compiled it with the clr
switch. It calls my C# code. To test I created a C++ console application that
uses LoadLibrary to load the C++ managed code DLL. I originally had the C++
and the C# DLLs in the same directory and the executable in a different
directory. With that set up I always get a FileNotFoundExc eption error. It
says it can't find the C# assembly. When I move the executable to the same
directory as the two DLLs it works fine.

Does anyone have any ideas as to why it would behave that way? Thanks for
any help, I really appreciate it.

Thanks,
Nick
Nov 17 '05 #1
3 2434
Hi Nick,

Your problem has to do with the way the CLR probes for assemblies. Assuming
that you don't have a <codeBase> element in your application's configuration
file, the CLR probes for the assembly (your C# dll) in the following order:

1. The Global Assembly Cache.

2. The application base path, which is the root location where the
application is being executed. This is your executable's path. Keep this in
mind, more on this in a second.

3. The application base path appened with any private paths specified.

This is overly simplified, the rules are actually a lot more complex and
have to do with configuration files, static and dynamic loading, culture
info, etc. but I think you can see the problem already. You perform a
LoadLibrary to load the C++ dll, which references the C# dll. Therefore, the
CLR has to load the C# dll. In your case, again assuming no extern config
files / culture info / etc. it will search the GAC, not find it, then search
the application base directory, and not find it. It will then terminate the
probe and throw a FileNotFoundExc eption. In the case where the dll's are in
the same directory as the exe, it can find it because the dll is located in
the application base directory.

For more information, you can see the following link, which explains things
in more detail:

http://msdn.microsoft.com/library/de...assemblies.asp

Hope that helps!
--
Magius
"Nick" wrote:
Hello,

Let me explain my situation. There is an application in C++ (that I didn't
write) that needs to call a C# DLL. One option, I believe, would be to
compile the app with the clr switch. Rather than do that first the other
developer wondered if I could create an intermediate managed code DLL that
would call my C# code.

So, I created a C++ DLL that exports a function and compiled it with the clr
switch. It calls my C# code. To test I created a C++ console application that
uses LoadLibrary to load the C++ managed code DLL. I originally had the C++
and the C# DLLs in the same directory and the executable in a different
directory. With that set up I always get a FileNotFoundExc eption error. It
says it can't find the C# assembly. When I move the executable to the same
directory as the two DLLs it works fine.

Does anyone have any ideas as to why it would behave that way? Thanks for
any help, I really appreciate it.

Thanks,
Nick

Nov 17 '05 #2
Hi Magius,

Thanks for the help. I haven't got it working yet, but I just started
looking at it again. At least now I have a clue as to what I'm doing. Thanks
again.

Regards,
Nick

"Magius" wrote:
Hi Nick,

Your problem has to do with the way the CLR probes for assemblies. Assuming
that you don't have a <codeBase> element in your application's configuration
file, the CLR probes for the assembly (your C# dll) in the following order:

1. The Global Assembly Cache.

2. The application base path, which is the root location where the
application is being executed. This is your executable's path. Keep this in
mind, more on this in a second.

3. The application base path appened with any private paths specified.

This is overly simplified, the rules are actually a lot more complex and
have to do with configuration files, static and dynamic loading, culture
info, etc. but I think you can see the problem already. You perform a
LoadLibrary to load the C++ dll, which references the C# dll. Therefore, the
CLR has to load the C# dll. In your case, again assuming no extern config
files / culture info / etc. it will search the GAC, not find it, then search
the application base directory, and not find it. It will then terminate the
probe and throw a FileNotFoundExc eption. In the case where the dll's are in
the same directory as the exe, it can find it because the dll is located in
the application base directory.

For more information, you can see the following link, which explains things
in more detail:

http://msdn.microsoft.com/library/de...assemblies.asp

Hope that helps!
--
Magius
"Nick" wrote:
Hello,

Let me explain my situation. There is an application in C++ (that I didn't
write) that needs to call a C# DLL. One option, I believe, would be to
compile the app with the clr switch. Rather than do that first the other
developer wondered if I could create an intermediate managed code DLL that
would call my C# code.

So, I created a C++ DLL that exports a function and compiled it with the clr
switch. It calls my C# code. To test I created a C++ console application that
uses LoadLibrary to load the C++ managed code DLL. I originally had the C++
and the C# DLLs in the same directory and the executable in a different
directory. With that set up I always get a FileNotFoundExc eption error. It
says it can't find the C# assembly. When I move the executable to the same
directory as the two DLLs it works fine.

Does anyone have any ideas as to why it would behave that way? Thanks for
any help, I really appreciate it.

Thanks,
Nick

Nov 17 '05 #3
Hi Nick,

I am glad Magius' help can help you. In addition to this, below is the
official document of how .Net Runtime locates the assembly:
"How the Runtime Locates Assemblies"
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconhowruntime locatesassembli es.asp

Hope it helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4

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

Similar topics

1
6726
by: ulf | last post by:
Hello, After I got a FileNotFoundException in my real life CSharp code, I nailed it down to the following line: System.EnterpriseServices.ResourcePool rp = new System.EnterpriseServices.ResourcePool(null); The exception I get for this line is System.IO.FileNotFoundException: The specified module could not be found.
1
2953
by: Brian | last post by:
I've looked through the previous posts on this one and have verified permissions and location of my Dlls, but I am still getting an exception when I try to Load an assembly. The directory where my Dlls are located give the ASPNET user full control, and all Dlls used by the Assembly in question are in the local folder with the rest of the web application Dlls. Could someone take a look at my error and shed some light on this?
6
1673
by: Prodip Saha | last post by:
I am trying to load a shared component like DataAccess from GAC and not been able to successfully get it working for my asp.net application. The dll is loading from the GAC with correct version and I can verify it from Output window of VS.Net IDE. I can change the policy and it works because I can see the oldversion is redirected to newVersion. The problem is- unless I copy the dll in the bin directory of the application I get...
5
2277
by: MattC | last post by:
Hi, I am getting the following error: System.IO.FileNotFoundException: C:\Dreamtxt\WebSites\mysite\www\feedback.aspx at System.Web.UI.TemplateParser.GetParserCacheItem() at System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String virtualPath, String inputFile, HttpContext context) at System.Web.UI.TemplateControlParser.GetCompiledInstance(String virtualPath,
0
2547
by: jason | last post by:
Hello. Newbie question for sure. I've got this simple web service (.asmx) function that works fine when called remotly from asp.net client web page. The dll compiled output from the wsdl produced vb code is under webroot/bin/nnn.dll on the client.
3
9103
by: James | last post by:
Hi guys Do you ever get the exception in Managed C++? How can I know which file or dll is missed?
5
38385
by: SGRing | last post by:
I have a c# application that I'm migrating from 2003 to 2005, and I moved it to another machine. It built ok. But, when trying to run I get System.IO.FileNotFoundException was unhandled Message="The specified module could not be found. (Exception from HRESULT: 0x8007007E)" when it tries to call a property in the file that it's in. But, there is no file information, and it never seems to get to the first line of the property in question....
0
1432
by: Peter Vestergaard | last post by:
Hi, I am running VS .Net 2005. I have an application in which one of the classes are having a member that is an instance of a class defined in a managed C++ dll. As soon as I try to create an instance of the local class I get a FileNotFoundException not telling much more than the file cannot be found. I have made the below code that reproduces this behaviour. What I don't understand is that the debugger is reporting that the...
2
3121
by: bbindae | last post by:
I am trying to check whether XmlTextReader reads the xml file successfully or not. MSDN says that XmlTextReader raise the FileNotFoundException when it cannot find the file to read. Here is the source code I wrote. string fileName = "thisfileneverexist.xml"; XmlTextReader xmlReader = null;
0
10536
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10335
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12130
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...
0
11137
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8687
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
7861
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
6647
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5404
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
3
3963
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.