|
316 | 316 | }, |
317 | 317 | { |
318 | 318 | "cell_type": "code", |
319 | | - "execution_count": 5, |
| 319 | + "execution_count": null, |
320 | 320 | "id": "d51dfbec", |
321 | 321 | "metadata": { |
322 | 322 | "execution": { |
|
332 | 332 | "output_type": "stream", |
333 | 333 | "text": [ |
334 | 334 | "Python list: [10.5, 20.3, 15.7, 18.9, 22.1]\n", |
335 | | - ".NET array length: 5\n", |
| 335 | + ".NET array: [10.5, 20.3, 15.7, 18.9, 22.1]\n", |
336 | 336 | "Converted back: [10.5, 20.3, 15.7, 18.9, 22.1]\n" |
337 | 337 | ] |
338 | 338 | } |
|
343 | 343 | "dotnet_array = Array[Double](python_data)\n", |
344 | 344 | "\n", |
345 | 345 | "print(f\"Python list: {python_data}\")\n", |
346 | | - "print(f\".NET array length: {dotnet_array.Length}\")\n", |
| 346 | + "# Accessing .NET array elements since Python doesn't know how to print a .NET array directly\n", |
| 347 | + "print(f\".NET array: {[dotnet_array[i] for i in range(dotnet_array.Length)]}\")\n", |
347 | 348 | "\n", |
348 | 349 | "# .NET array back to Python list\n", |
349 | 350 | "back_to_python = [dotnet_array[i] for i in range(dotnet_array.Length)]\n", |
|
460 | 461 | "\n", |
461 | 462 | "### 1. Runtime Not Loaded Error\n", |
462 | 463 | "Make sure you load the runtime BEFORE importing clr.\n", |
| 464 | + "\n", |
463 | 465 | "```python\n", |
464 | 466 | "# X WRONG - will fail\n", |
465 | 467 | "import clr\n", |
|
471 | 473 | "pythonnet.load(\"coreclr\")\n", |
472 | 474 | "import clr\n", |
473 | 475 | "```\n", |
| 476 | + "\n", |
474 | 477 | "### 2. DLL Not Found\n", |
475 | 478 | "Verify the path in `dll_path` is correct and points to a dll that exists. If no dll exists, be sure that you have built the Numerics solution.\n", |
476 | 479 | "\n", |
477 | 480 | "### 3. Loading DLL More Than Once\n", |
478 | | - "When running multiple files at once, if they all load Numerics with ```clr.AddReference(str(dll_path))``` it may fail with an error that Numerics has already been loaded. If this happens, add the statement below to check the assemblies and only load Numerics if it is not already loaded.\n", |
| 481 | + "When running multiple files at once, if they all load Numerics with ```clr.AddReference(str(dll_path))``` it may fail with an error that Numerics has already been loaded. If this happens, add the statement below to check the assemblies and only load Numerics if it is not already loaded. The code below doesn't output anything, but you'll know it worked if it runs without the failure error of loading multiple DLLS. This error shouldn't happened within these notebooks because they all have seperate kernels. It would happen if you were trying to run multiple Python files all at once where each one loads the same DLL. In each of these files you would replace how you were orginally loading the DLL with the chunk below.\n", |
| 482 | + "\n", |
479 | 483 | "```python\n", |
480 | 484 | "# Needed to access the assemblies\n", |
481 | 485 | "from System import AppDomain\n", |
|
489 | 493 | "\n", |
490 | 494 | "### 4. Array Type Mismatch\n", |
491 | 495 | "Check that you're using .NET arrays where required.\n", |
| 496 | + "\n", |
492 | 497 | "```python\n", |
493 | 498 | "# X WRONG - Python list\n", |
494 | 499 | "data = [1, 2, 3]\n", |
|
0 commit comments