Fallen at first hurdle using C# Example in OCC6.2

About 1 hours experience in OCC. Just installed it. I'm interested in the C# link to OCC. I'm using C# Express. After When I tried to run IE in the samples/standard/C# folder I get the following error:
"FileLoadException Was unhandled"
"{A procedure imported by 'shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.":"shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"}

This happens when at
"Form2 newForm = new Form2();" line of code.

What is wrong, and why isn't the sample set up to work correctly. Is this some kind of initiation rite?

Gerhard Hofmann's picture

Hello Ernest,
I dont know much about the C# example of OpenCascade, but there is a .NET warpper for many OpenCascade classes:

http://www.opencascade.org/org/community/projects/?project_id=218

best regards
Gerhard

Mikael Aronsson's picture

I don't know if it has improved today but at least in the past you could not even compile the sample code or the libraries without modifing the project files, there where lot's of incorrect settings in them, most of the time in the debug versions.

Pawel's picture

Hi Ernest,

- is shell.dll in the EXE-directory of the application? If not just copy the output files of all projects into one directory.
- as far as I know in VS Express you cannot mix different languages in one solution (it was so before but might have changed). In that case you would have to compile the projects separately and copy corresponding files into the same directory.

I use VS professional. I guess, I used the provided sample from OCC5.2 and it worked fine. OK there are some bugs but at least I was able to start the application.

Pawel

Jonathan Hill's picture

Hi Ernest,

I’ve updated the MakeBottle sample and you can download it from:- (watch out for the case sensitive path)

http://www.myxyz.co.uk/Downloads/Development/

Let me know if it works for you.

Jonathan

Gareth's picture

I've had a very similar problem. I get the FileLoadException for shell. The odd thing is that with a try catch around the load, somehow the shell does manage to load the second time. However, there is another problem that on some machines that I have installed the release of the application it will crash again. One factor seems to be that I have tried it on a machine that did not have Visual Studio and it did not work, but then when I install Visual Studio the application will work. I was thinking that this might be just that the Visual C++ Runtime library needs to be installed, but haven't had much luck fixing it. I added the Visual C++ Runtime as a prerequisite to the project and tried installing the redistributable C++ runtime library, but still no luck.

I tried doing dependency walker on the application and shell, but it did not find anything that was not being referenced.

I also tried using the Modules feature in Visual Studio to see which dlls are actually used when the shell is loaded and I added these dlls to the application install directory, but this did not help either. I wasn't sure whether I needed to set the dlls to register and/or set them as system (msvcp80.dll, etc.), but I tried some of these things and was not able to fix the problem.

Any ideas of anything to try? It seems like the underlying issue is that the "Form2 newForm = new Form2();" line does not work, but I guess that something installed with visual studio has some sort of debugging feature that catches it and fixes the reference somehow??? I'm not very comfortable with DLLs, so there may be something trivial that I am not doing that could solve the problem. Thanks for any advice.

Test user's picture

Have someone found a solution to this problem? (w/ Form2 newForm = new Form2();?)
Im using VS 2008 and I get the same error message..

A procedure imported by 'shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.":"shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"

I also try to use the Wrapper to Gerhard Hofmann, but when I try to run the MakeBottle I get an error when executing this line
Geom.TrimmedCurve aArcOfCircle =(new GC.MakeArcOfCircle(ref aPnt2, etc

Error: unable to load DLL OCasToDotNet.dll The specified module could not be found. HRESULT 0x8007007F..

I have referenced this in the PATH variable and under VC++ Directories, but with no luck :(

Test user's picture

I have placed the OCasToDotNet.dll in the bin folder of my project

Test user's picture

After running Dependency Walker on OCasToDotNet.dll, I got the message that im missing some files;
TKOCCLICENSE.DLL
TKXDESAT.DLL
TKXDEXT.DLL
This is not in the 6.3 version of OCC but maybe in some older version?

Test user's picture

Finally I found a solution to this error:

A procedure imported by 'shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' could not be loaded.":"shell, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"

For some reason, it works by commenting out this part of code in the OCC.cpp file

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

But I still have a problem to use the wrapper to Gerhard Hofmann in my VS2008 Solution.. :(

Adrian's picture

I have the same problem with the Wrapper.
I´m also using VS 2008 and the error message is the same "Unable to load DLL OCasToDotNet.dll".
I try to put it the system32 folder and in C:\OpenCASCADE6.3.0\ros\win32\bin, but it don´t work. :-(
Can anyone help me, please?

Adrian

siyamalan's picture

I also have the same problem. Can anyone help me??????????????????????????????????????????????

Dmitry Khabi's picture

I HAD the same problem:
application could not find OCC's dll. The solution:
copy dll in the directory with .exe.

Beim release copy ../win32/bin/
bei Debug copy ../win32/bind

additional copy this directory from ./src/:
SHMessage
StdResource
XmlOcafResource
XSMessage
XSTEPResource

In system variablen you don#t need to set the OCC' variables...

HB's picture

I have copied the OCasToDotNet.dll in the ..\bin\Debug directory of my application.
But i get still the error that the DLL couldn't be find.

Could anyone help me?

PS: I'am using vb.net...

Kenny Busine's picture

Gareth,
I have run into a similar problem. Were you successful solving this problem? Please let me know.

Kenneth

Kevin Malachowski's picture

Have you figured out the solution to the problem of not getting OCasToDotNet.dll to load?

Durgesh's picture

Hello,

I have recently tried running this sample with OCCT6.6. Getting the same error. What's the solution?

-durgesh

Francisco Oblea's picture

Same here... I was able to compile the example code but when I click on the File->New menu item the application crashes. I'm using VS 2012 ultimate edition.

I've attached two screenshots showing the exception and the directory contents.

I appreciate the help.