When the path of the Excel file is relative. This will not work when moving the compiled code to a different location. The path will still be the absolute path of the original coding location.
Repro steps
Please provide the steps required to reproduce the problem
Create a type with the type provider on a D disk
Try to run the compiled code on a C disk
Expected behavior
If the path for the type is the same relative to the working directory, it should be found.
Actual behavior
The error you can observe is:
System.TypeInitializationException: The type initializer for 'MyTypeProvider' threw an exception.
---> System.TypeInitializationException: The type initializer for '<StartupCode$BlahBlah>.$Blah' threw an exception.
---> System.Exception: Could not open file 'D:\Development\MyExcel.xlsx'. DirectoryNotFoundException
The path that will be shown in the error message is the exact absolute path that was used when compiling the code.
Known workarounds
Using __SOURCE_DIRECTORY__ to create an absolute path gives the same result.
Effectively, this typeprovider can only moved to a location with the same exact absolute path! Meaning I would have to reconfigure a production machine with a D disk just to run this code??
Description
When the path of the Excel file is relative. This will not work when moving the compiled code to a different location. The path will still be the absolute path of the original coding location.
Repro steps
Please provide the steps required to reproduce the problem
Create a type with the type provider on a D disk
Try to run the compiled code on a C disk
Expected behavior
If the path for the type is the same relative to the working directory, it should be found.
Actual behavior
The error you can observe is:
The path that will be shown in the error message is the exact absolute path that was used when compiling the code.
Known workarounds
Using __SOURCE_DIRECTORY__ to create an absolute path gives the same result.
Effectively, this typeprovider can only moved to a location with the same exact absolute path! Meaning I would have to reconfigure a production machine with a D disk just to run this code??
Related information
N/A